First Record of the Form

Haytham

Registered User.
Local time
Today, 20:57
Joined
Jun 27, 2001
Messages
162
Hi All...
I have two command buttons on my main form, CmdNext and CmdPrevious.
When I open the form to display all the records, I want the CmdPrevious button to be disabled or hidden. I can do this disable or hide button, but the problem how to recognize that this is first record..
I tried :
If DFirst ("*","NameofQuery") Then
DoCmd.CmdPrevious.Enable = False
Else
DoCmd.CmdPrevious.Enable = False
End If

I have a problem in the DFirst, it's not working ..
Will any body help me where is my mistake please
 
Simply my question is:
When open the form,
If the record in this form is the first record how to disable CmdPrevious Button please
 
Hello Haytham,

I think this may be what your looking for. I use this on one of my forms that has command buttons for next and previous. You can put this code in the forms On Current event and I think it will do what you want. You will need to change the names of the command buttons to the name of your buttons.

This code comes from Beginning Access 97 VBA by Wrox.

Dim recClone As Recordset

Set recClone = Me.RecordsetClone()

If Me.NewRecord Then
Me.cmdNext.Enabled = False
Me.cmdBack.Enabled = False
Else
recClone.Bookmark = Me.Bookmark
recClone.MovePrevious
Me.cmdBack.Enabled = Not (recClone.BOF)
If recClone.BOF Then
Me.cmdBack.Visible = False
Else
Me.cmdBack.Visible = True
End If
recClone.MoveNext
recClone.MoveNext
Me.cmdNext.Enabled = Not (recClone.EOF)
If recClone.EOF Then
Me.cmdNext.Visible = False
Else
Me.cmdNext.Visible = True
End If
recClone.MovePrevious
End If

recClone.Close

HTH
Shane
 
Dear BadOkie,
You are great. That what I was looking for exactly. It works perfectly.
I tried to understand the code but in vain..
I think I have to read more about the new codes you wrote to me.
It's a great win to know many things new.
Again thank you
 

Users who are viewing this thread

Back
Top Bottom