473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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

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
2 9500
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: eternalD3 | last post by:
Hi, I have a problem to get this working on Opera 7.x+. This does not need to work on older Opera browsers There are problems on rendering the sub-level navigation. It aligns right on Firefox...
1
by: Les Juby | last post by:
Some time back we assembled an Explore-type menu system (tree of folders) for a client site which has grown to be a pivotal function of the site in that deep navigation into the South African...
6
by: MX1 | last post by:
Hi, I've created a series of navigation buttons to be used as a standard across many forms in an Access DB. Does anyone know an easy way to cut and paste these navigation buttons into each new...
2
by: Liam | last post by:
ok I have built a simple form which has next and previous button on it. Now what i want to happen is when I get to the last button in the set of records the button which it is at, i.e. if and the...
2
by: PC Datasheet | last post by:
I have an AccessXP(A2000 mode) customer who says on one form the navigation buttons do nothing when he clicks on any of the 5 but the navigation buttons work on other forms. In my copy of the...
1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
3
by: Jack Russell | last post by:
I want to add navigation buttons to a tabcontrol (somewhat like excel) How do I get the "tabs" to offset to the right so that I can draw the buttons on the left? TIA -- Remove norubbish to...
3
by: KimberlyM | last post by:
This has been driving me crazy. I hope someone can help. The site displays perfectly in FF but all div's do not show in IE. Please help me find the problem! Thanks! Here is my css. ...
3
by: Gary | last post by:
Afternoon Is it possible to display test alongside the Navigation Buttons in an MS Access form? I have a complex form containing a number of subforms where the Navigation Buttons are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.