Display link on last record of Recordset.EOF

Hello ee!

I'm listing visits in order, the latest one is the last record of my list. How do i display a link referencing to the last record of the recordset? I can get the link to show in all of the records, but i only want it to show for the last one. Any ideas thanks in advance!

This is basically as far as i have gotten.

do while recordset.EOF
     Response.Write <table
     etc etc........
     Recordset.movenext
loop
If recordset.eof then
response.write("display/print")
End
IntercareSupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
The code you need is posted below. If you do not use the correct cursor type to retrieve the query, then you RecordCount will always return -1 and the "IF" clause will get executed.
Refer to this for more info on RecordCount:
http://w3schools.com/ado/prop_rs_recordcount.asp


Dim limit
limit = recordset.RecordCount - 1 
IF limit < 0 Then
	Response.Write("limit is below zero. Invalid cursorType maybe?")
Else
 
	For i=0 to limit
	     Response.Write <table
     	etc etc........
     	Recordset.movenext
	Limit
 
	If NOT recordset.eof then
		response.write("display/print")
	End
End If

Open in new window

0
IntercareSupportAuthor Commented:
I'm not returning any records back. I think you forgot to put an ending on the loop, so put the next after limit. Is that right?
0
hieloCommented:
>> I think you forgot to put an ending on the loop
Yes, I did forget. Take a look at the code below. Provide the correct fieldName
Dim limit
limit = recordset.RecordCount - 1 
IF limit < 0 Then
	Response.Write("limit is below zero. Invalid cursorType maybe?")
Else
 
	For i=0 to limit
		Response.Write ( recordset.fields("fieldName").value )
     		Recordset.movenext
	Next
 
	If NOT recordset.eof then
		Response.Write ( recordset.fields("fieldName").value )
	End
End If

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

IntercareSupportAuthor Commented:
hmmm, still nothing when i response write Recordset.RecordCount -1 i get a negavtive number
0
hieloCommented:
On my first post I included a link that clearly tells you which cursor you must use to get the actual RecordCount. If you use the incorrect cursor type, then recordset.RecordCount will always return -1

Basically your recordset query statement line should look similar to:
recordset.open sqlString, connectionObj, 1, 3

You are actually interested in the last two arguments (1,3)
0
IntercareSupportAuthor Commented:
i have multiple recordsets running. I have one displaying some information from another table and i have dropdown boxes
0
hieloCommented:
The recordset you need to "worry" about is the one for which you want to determine the RecordCount
0
IntercareSupportAuthor Commented:
I've changed my cursortype & locktype with the Recordset.Open portion and still nothing. Is there something I'm missing?
0
hieloCommented:
If you got the recorset via:
recordset = conn.Execute( sql )

then that's the problem. You must create a Recordset object explicitly to use the Recordcount
Set recordset = Server.CreateObject("ADODB.Recordset")
recordset.open sql, conn, 1, 3

If you still have problems, post your code.
0
IntercareSupportAuthor Commented:
Hielo can you take a look at the file another pair of eyes helps
test.txt
0
hieloCommented:
Not ignoring, nor did I forget you. Just busy. Any way, I can see what you are doing wroing, but I don't understand the logic of what you are trying to do. So let me explain what is wrong and hopefully you will be able to fix it.

On the attached file:
Line 38: Creates Recordset Object => OK
Line  80: Opens recordset object as discussed =>OK (assuming that Connection object actually exists, most likely in connect.asp). At this point there is "something" pointing to the first record on this recordset object.
Lines 95 through 106:  On this loop, the recordset pointer is continually moved until there are no more records left. Hence, beyond line 106, the recordset pointer is not pointing to any records.

Line 197: This is the reason why things are not working for you:
set Recordset = Recordset.NextRecordset
At this point, the Recordset pointer is NOT pointing to any recordset at all. Previously you said:
"still nothing when i response write Recordset.RecordCount -1 i get a negavtive number". Now I am curious as what was the negative number being printed. I would expect Recordset.NextRecordset to evalutate to Null or Nothing.

Line 198: strLimit = Recordset.RecordCount - 1
Due to the issues already outlined, it should be obvious that Recordset is not longer the original recordset you had.

Now,"things/tools" available  that you may use to fix your problems depending on what you are trying to do on line 197.
If you are trying to move to the first record on the original recordset, you can use:
Recordset.MoveFirst
instead

If you are trying to move to the last record on the original recordset, you can use:
Recordset.MovePrevious
Instead, since you are already beyond the last record. Not sure but perhaps even Recorset.MoveLast might work.

Hope this help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IntercareSupportAuthor Commented:
change the loop logic to go with Recordset.MovePrevious. Works perfectly now. Thanks for clarifying it. I needed it spelled out =).
0
IntercareSupportAuthor Commented:
quality answer. Wasn't quick, but still got back to me and answered. Wasn't a problem at all. Experts are busy now a days.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.