Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intelligent Navigation Buttons

Status
Not open for further replies.
Aug 26, 2002
33
US
HELP!!! I am trying desparately to make my command buttons "intelligent" to where you can't go past the last record or before the first record (so that the whole program doesn't blow up).
This particular form that I want the buttons on is a results form, meaning that the table was filtered by the user. So I took that SQL string used to filter it and passed it into a recordset, hoping to use the recordset to enable and disable the different buttons when necessary. I get no errors when running the code, but nothing happens with the buttons as far as enabling and disabling goes. Here is my code:

Private Sub Form_Current()

Dim strSQL2 As String

strSQL2 = Me!txtTemp

Dim rs2 As Recordset
Dim db2 As Database

Set db2 = CurrentDb
Set rs2 = CurrentDb.OpenRecordset(strSQL2, dbOpenSnapshot)

If rs2.RecordCount = 0 Then
MsgBox "There are no records."
Exit Sub
End If

If rs2.RecordCount <> 0 Then
rs2.MoveFirst
rs2.MoveLast

If rs2.RecordCount = 0 Then
MsgBox &quot;There are no records.&quot;
Exit Sub

If Me.CurrentRecord = 1 Then
cmdPrevious.Enabled = False
cmdFirst.Enabled = False
Else
cmdPrevious.Enabled = True
cmdFirst.Enabled = True
End If

If Me.CurrentRecord = rs2.RecordCount Then
cmdNext.Enabled = False
cmdLast.Enabled = False
Else
cmdNext.Enabled = True
cmdLast.Enabled = True
End If

Else
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
End If

End Sub

Any suggestions???

Also, I thought that I had seen a post on this very topic before, but couldn't ever find it again, so if this exact question has been answered, please point me to that thread.
Thanks!
 
Try .BOF and .EOF instead of recordcount.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
I don't know if this will help but, What I do is :

for the &quot;next&quot; button I use the total number of records, if you are the last record the buttons visibility is set to false.

for the previous button i set the visibility to false if you are the first record.


That way you don't even have to bother with messages.

There is also an active X control that looks just like the navigation bar.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top