By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

Problems with VBA navigation buttons (BOF and EOF not working?)

P: n/a
I have been trying to implement navigation buttons for a number of
forms in my application.

Creating the 'Next' 'Previous' buttons has been fine but setting the
enabled properties doesn't work due to problems with the BOF and EOF
properites. They never appear to be set properly.

Here is the offending code:

private sub Form_Current()
With Me.RecordsetClone
Me.CmdPrevious.Enabled = Not (.BOF)
Me.CmdPrevious.Enabled = Not (.EOF)
End With
end sub

command code:

Private Sub CmdNext_Click()
DoCmd.GoToRecord , , acNext
End Sub

Private Sub CmdPrevious_Click()
DoCmd.GoToRecord , , acPrevious
End Sub

I have stripped out the checks in the code that handle for new/no
record.

The the buttons are always enabled (set to true) by this code. When
the user clicks the Previous/Next button when the record position at
the begining/end of the set I get error 2105 which should not happen
if BOF/EOF is working properly.

I have tried other methods to determine whether the form is at the
first/last record using the absoluteposition or the bookmark
properties. No luck there. The code becomes much more complex as well.

Does anybody know something that might help. I must be doing something
fundermentally wrong here to cause this problem.

Thanks.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 20 Sep 2004 19:20:20 -0700, lo*****@iinet.net.au wrote:
I have been trying to implement navigation buttons for a number of
forms in my application.

Creating the 'Next' 'Previous' buttons has been fine but setting the
enabled properties doesn't work due to problems with the BOF and EOF
properites. They never appear to be set properly.

Here is the offending code:

private sub Form_Current()
With Me.RecordsetClone
Me.CmdPrevious.Enabled = Not (.BOF)
Me.CmdPrevious.Enabled = Not (.EOF)
End With
end sub

command code:

Private Sub CmdNext_Click()
DoCmd.GoToRecord , , acNext
End Sub

Private Sub CmdPrevious_Click()
DoCmd.GoToRecord , , acPrevious
End Sub

I have stripped out the checks in the code that handle for new/no
record.

The the buttons are always enabled (set to true) by this code. When
the user clicks the Previous/Next button when the record position at
the begining/end of the set I get error 2105 which should not happen
if BOF/EOF is working properly.

I have tried other methods to determine whether the form is at the
first/last record using the absoluteposition or the bookmark
properties. No luck there. The code becomes much more complex as well.

Does anybody know something that might help. I must be doing something
fundermentally wrong here to cause this problem.

Thanks.


This will turn off the cmdPrevious at the first record, and turn off
the cmdNext at the last record.

Private Sub Form_Current()
CmdPrevious.Enabled = Not Me.CurrentRecord = 1
CmdNext.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <
Me.Recordset.RecordCount
End Sub

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #2

P: n/a
EOF is not true when you are at the last record: only when you attempt to
move past it. Likewise BOF is not true *at* the first record.

Additionally, the RecordsetClone is not automatically set to the same record
as that in the form. (It exists so you can examine other records also.)

There are other ways to do this also, but this code illustrates how to use
RecordsetClone to calculate boolean variables to disable command buttons for
Previous, Next, and New.

Private Sub Form_Current()
Dim rs As DAO.Recordset
Dim bNoPrevious As Boolean
Dim bNoNext As Boolean
Dim bNoNew As Boolean

Set rs = Me.RecordsetClone
If rs.RecordCount = 0 Then ' no records?
bNoPrevious = True
bNoNext = True
Else
If Me.NewRecord Then 'at a new record?
bNoNext = True
bNoNew = True
Else
'See if there is a next record.
rs.Bookmark = Me.Bookmark
rs.MoveNext
bNoNext = rs.EOF

'See if there is a previous record.
rs.Bookmark = Me.Bookmark
rs.MovePrevious
bNoPrevious = rs.BOF
End If
End If

Set rs = Nothing
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<lo*****@iinet.net.au> wrote in message
news:b2**************************@posting.google.c om...
I have been trying to implement navigation buttons for a number of
forms in my application.

Creating the 'Next' 'Previous' buttons has been fine but setting the
enabled properties doesn't work due to problems with the BOF and EOF
properites. They never appear to be set properly.

Here is the offending code:

private sub Form_Current()
With Me.RecordsetClone
Me.CmdPrevious.Enabled = Not (.BOF)
Me.CmdPrevious.Enabled = Not (.EOF)
End With
end sub

command code:

Private Sub CmdNext_Click()
DoCmd.GoToRecord , , acNext
End Sub

Private Sub CmdPrevious_Click()
DoCmd.GoToRecord , , acPrevious
End Sub

I have stripped out the checks in the code that handle for new/no
record.

The the buttons are always enabled (set to true) by this code. When
the user clicks the Previous/Next button when the record position at
the begining/end of the set I get error 2105 which should not happen
if BOF/EOF is working properly.

I have tried other methods to determine whether the form is at the
first/last record using the absoluteposition or the bookmark
properties. No luck there. The code becomes much more complex as well.

Does anybody know something that might help. I must be doing something
fundermentally wrong here to cause this problem.

Thanks.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.