Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / October 2005

Tip: Looking for answers? Try searching our database.

Custom Nav Buttons - Putting code in Module

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SteveR - 18 Oct 2005 16:13 GMT
I have several forms on which I would like to use custom nav buttons.  I have
successfully set this up on one form but it seems like I should be able to
put the code in a module and call the procedure when the form opens (the
form's On Current event) and when the First, Previous... buttons are pressed
(On Click Event)

Here is my On Current code:
Private Sub Form_Current()
   Dim rsClone As Recordset
   Set rsClone = Me.RecordsetClone
   If Me.NewRecord = True Then
       Me!cmdAdd.Enabled = False
       Me!cmdNext.Enabled = False
       Me!cmdPrevious.Enabled = True
       Me!cmdFirst.Enabled = True
       Me!cmdLast.Enabled = True
   ElseIf rsClone.Bookmarkable = True Then
       Me!cmdAdd.Enabled = True
       rsClone.Bookmark = Me.Bookmark
       rsClone.MovePrevious
       cmdFirst.Enabled = Not (rsClone.BOF)
       cmdPrevious.Enabled = Not (rsClone.BOF)
       rsClone.MoveNext
       rsClone.MoveNext
       cmdNext.Enabled = Not (rsClone.EOF)
       cmdLast.Enabled = Not (rsClone.EOF)
       rsClone.MovePrevious
   End If
   rsClone.Close
End Sub

Here is the On Click event code for the First button:
Private Sub cmdFirst_Click()
DoCmd.GoToRecord , , acFirst
End Sub

I created a new module called "Nav" and changed "Private" to Public and then
tried to call the procedure but there is a problem with using "Me."  Looks
like I need to use another technique and I've never called a procedure so I
could use a suggestion there as well.

Thanks for any help you can offer.
Douglas J Steele - 18 Oct 2005 16:37 GMT
Presumably you've got something like

  Sub Nav()

as the declaration for your new routine, and you're calling it as:

  Call Nav

Change the declaration to

  Sub Nav(WhatForm As Form)

then go into the routine and change every reference to Me to WhatForm.

Also, change how you call it to

  Call Nav(Me)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I have several forms on which I would like to use custom nav buttons.  I have
> successfully set this up on one form but it seems like I should be able to
[quoted text clipped - 38 lines]
>
> Thanks for any help you can offer.
SteveR - 18 Oct 2005 17:23 GMT
I must admit that I was somewhat dubious but I plugged it in and it works
well for not only the rolodex form but another form.  I understand that
Call(Me) will bring over the name of the current form but typing in the
frmRolodex in the code doesn't make sense to me.  Like I said it works great
even on a form not called frmRolodex but if you can point me to where I can
learn why I will develop my skills.  Here is the code in the NavButtons
Module:  By the way, I have learned a lot from your website in the past.  
Thanks for your generosity.

Public Sub Nav(frmRolodex As Form)
   Dim rsClone As Recordset
   Set rsClone = frmRolodex.RecordsetClone
   If frmRolodex.NewRecord = True Then
       frmRolodex!cmdAdd.Enabled = False
       frmRolodex!cmdNext.Enabled = False
       frmRolodex!cmdPrevious.Enabled = True
       frmRolodex!cmdFirst.Enabled = True
       frmRolodex!cmdLast.Enabled = True
   ElseIf rsClone.Bookmarkable = True Then
       frmRolodex!cmdAdd.Enabled = True
       rsClone.Bookmark = frmRolodex.Bookmark
       rsClone.MovePrevious
       frmRolodex!cmdFirst.Enabled = Not (rsClone.BOF)
       frmRolodex!cmdPrevious.Enabled = Not (rsClone.BOF)
       rsClone.MoveNext
       rsClone.MoveNext
       frmRolodex!cmdNext.Enabled = Not (rsClone.EOF)
       frmRolodex!cmdLast.Enabled = Not (rsClone.EOF)
       rsClone.MovePrevious
   End If
   rsClone.Close
End Sub

Public Sub addr()
DoCmd.GoToRecord , , acNewRec
End Sub

Public Sub FirstR()
DoCmd.GoToRecord , , acFirst
End Sub

Public Sub LastR()
DoCmd.GoToRecord , , acLast
End Sub

Public Sub NextR()
DoCmd.GoToRecord , , acNext
End Sub

Public Sub PreviousR()
DoCmd.GoToRecord , , acPrevious
End Sub

> Presumably you've got something like
>
[quoted text clipped - 60 lines]
> >
> > Thanks for any help you can offer.
Douglas J Steele - 18 Oct 2005 17:45 GMT
It's basically a coincidence that it worked!

While you may have a form named frmRolodex, that's not what frmRolodex
refers to in the Nav routine: it's a variable that represents whatever form
is passed to the routine.

I didn't mean for you to replace WhatForm in my sample. It's not critical
that you change what you have, other than to remove the chance for confusion
when you (or someone else) looks at it in the future!

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I must admit that I was somewhat dubious but I plugged it in and it works
> well for not only the rolodex form but another form.  I understand that
[quoted text clipped - 113 lines]
> > >
> > > Thanks for any help you can offer.
SteveR - 18 Oct 2005 19:16 GMT
Thanks Doug,  I also make beer and wine so I'll be checking your site.  My
brother is a master at making beer.

> It's basically a coincidence that it worked!
>
[quoted text clipped - 131 lines]
> > > >
> > > > Thanks for any help you can offer.
Stephen Lebans - 18 Oct 2005 20:58 GMT
Have a look here:
http://www.lebans.com/recnavbuttons.htm
    RecordNavigationButtons is an MDB containing code to replace the
standard Navigation Buttons. The custom buttons exactly emulate the standard
navigation bar including the autorepeat property

Signature

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

>I must admit that I was somewhat dubious but I plugged it in and it works
> well for not only the rolodex form but another form.  I understand that
[quoted text clipped - 120 lines]
>> >
>> > Thanks for any help you can offer.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.