ProNetGroup
MIS
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 "There are no records."
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!
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 "There are no records."
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!