Wrox Programmer Forums
|
BOOK: Access 2003 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2003 VBA Programmer's Reference by Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein; ISBN: 9780764559037
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2003 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2005, 11:44 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wizard generated navigation buttons

Hi to all, I have a question about the "Control Wizards" generated record navigation buttons on a form. The form is generated from a table and I don't want to use the default record navigation buttons. I used the "Control Wizards" enable on the tool bar when I make a button so I can make my own buttons to navigate through the records.

My problem is that the buttons that go to the "Next" or "Previous" record gives an error message, "You can't go to the specified record.", when when I go to the EOF or BOF. Here's the code generated by the wizard for the button.

Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click

    DoCmd.GoToRecord , , acNext

Exit_cmdNext_Click:
    Exit Sub

Err_cmdNext_Click:
    MsgBox Err.Description
    Resume Exit_cmdNext_Click

End Sub

What I want to do is check for EOF or BOF and disable the button or if I could tell want the record count is I could keep track of that to not go past EOF or BOF. I'm still looking but I have not found any reference to this in the book.

Any help would be greatly appreciated.
Regards Mike G.

 
Old January 10th, 2005, 06:54 PM
Authorized User
 
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike,

The Wizards are reknowned for generating some fairly stodgey code. I'd be inclined to rewrite them:

Private Sub cmdMoveNext_Click()
    Me.cmdMovePrevious.Enabled = True

    If Not Me.NewRecord Then
        DoCmd.GoToRecord , , acNext
        If Me.NewRecord Then
            DoCmd.GoToRecord , , acPrevious

            Me.cmdMovePrevious.SetFocus
            Me.cmdMoveNext.Enabled = False
        End If
    End If
End Sub

Private Sub cmdMovePrevious_Click()
    On Error Resume Next

    Me.cmdMoveNext.Enabled = True

    If Not Me.RecordsetClone.BOF Then
        DoCmd.GoToRecord , , acPrevious

        If Err <> 0 Then
            Me.cmdMoveNext.SetFocus
            Me.cmdMovePrevious.Enabled = False
        End If
    End If
End Sub

In any case, for general questions about Access, refer to the following page for information about logging onto the Microsoft newsgroups, where you can get help 24/7.

http://www.pacificdb.com.au/MVP/newsgroup.htm

Graham R Seach
Microsoft Access MVP
 
Old January 11th, 2005, 01:26 AM
Registered User
 
Join Date: Dec 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Graham, thank you very much for your quick reply, the info is exactly what I was looking for.

Thanks again, Mike G.

 
Old January 11th, 2005, 02:33 AM
Authorized User
 
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike,

I just realised - in cmdMovePrevious_Click(), you can omit the "If Not Me.RecordsetClone.BOF Then" line (and its associated "End If", because they're redundant.



Graham R Seach
Microsoft Access MVP





Similar Threads
Thread Thread Starter Forum Replies Last Post
Navigation Wizard Control everest ASP.NET 2.0 Professional 0 January 17th, 2007 06:22 PM
intelligent navigation buttons NeoCat Access 13 September 17th, 2005 07:43 PM
Navigation buttons terry s Dreamweaver (all versions) 3 August 3rd, 2004 04:03 PM
Intelligent Navigation Buttons twsinc Access VBA 1 October 7th, 2003 09:07 AM
Animated Buttons Inside Navigation Bars? Ben Horne Dreamweaver (all versions) 0 October 5th, 2003 09:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.