Custom Nav Buttons - Putting code in Module

G

Guest

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.
 
D

Douglas J Steele

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)
 
G

Guest

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
 
D

Douglas J Steele

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!
 
G

Guest

Thanks Doug, I also make beer and wine so I'll be checking your site. My
brother is a master at making beer.
 
S

Stephen Lebans

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


--

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top