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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable a command button when it reach the end of record 1

Status
Not open for further replies.

cctrinh

MIS
Feb 2, 2001
25
US
Hi,

I try to disable a command button when I get to the end of the record. The following is the code that I wrote. I declared the variable locally. Any help will be thankful.

Cal

Dim rst As Recordset
Dim dbs As Database
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblISstaff")
rst.MoveNext
If (rst.EOF) Then
Me.next.Enabled = False
End If
 
This works, courtesy of Access 97 VBA programming.

Private Sub Form_Current()
Dim rst As Recordset

Set rst = Me.RecordsetClone()

rst.Bookmark = Me.Bookmark

rst.movenext
If (rst.EOF) Then
Me.next.Enabled = False
Else
Me.next.Enabled = True
End If
End Sub

you may also need to check to see if there are any records first by doing:

if rst.recordcount= 0

'do something

else

'do the code above

end if
 
It Really works,

thank you very much. Your tip is very helpful.
Just have a question. Why do you use the recordsetclone?

appreciate your assistance.
 
It is meerly an alternative to using openrecordset(). The recordsetclone is a read only recordset that is copy of whatever recordset is behind your form.

Other bonus features are:
You also require less text to declare this recordset.
You do not need to change the recordset declaration if the table name that your form points to changes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top