Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Irritating Navigation Button Problem! 1

Status
Not open for further replies.

AndWy

Programmer
Mar 13, 2001
13
0
0
GB
Can anyone help with some code that I can store in a module for use by all forms in my database that require Move First & Move Last navigation buttons. Basically when the user clicks on the Move First or Move Last button when they are already at the first or last record I want to be able to display my own message (Access doesn't currently display anything). The code has to recognise which form the user is on as there may be more than one form with these buttons open at any given time.
 
AndWy:

Are you are using command buttons for navigation rather than the navigation buttons provided? If so, put this code in your On_Current event of your form:


Private Sub Form_Current()

If IsNull(ReviewerID) Then 'Skips this code when a new record has been added.
Exit Sub 'Processing of this code when a new record has been
End If 'added causes an error.

'Code to enable/disable navigation buttons to prevent error messages
'if the user tries to move beyond the bounds of the recordset

Dim recClone As Recordset
'
Set recClone = Me.RecordsetClone
recClone.Bookmark = Me.Bookmark

recClone.MovePrevious
cmdFirst.Enabled = Not (recClone.BOF)
cmdPrev.Enabled = Not (recClone.BOF)
recClone.MoveNext

recClone.MoveNext
cmdLast.Enabled = Not (recClone.EOF)
cmdNext.Enabled = Not (recClone.EOF)
recClone.MovePrevious

recClone.Close

End Sub

The cmdXXXX are navigation button I create with the Command Button Wizard. This has worked pretty well for me.

Hope it helps.
Larry De Laruelle
larry1de@yahoo.com

 
Cheers Larry, works a treat!.... one more thing if I may.

I want to store this code in a module and call it from any open form that has the focus, is there a quick method of finding out which open form has the focus?

I've done it in the past by storing the form's name in a public variable triggered by the on open event of the form but this starts to get messy when more than one form is opened and I'd be grateful if you know of a better way.
 
AndWy:

There should be, but that's a bit beyond my current skill level.

Perhaps one of the wizards on this site can give us both the answer. What I have been doing is making sure I name the navigation buttons consistently and then just cut and paste that bit of code in the On_Current event of each form where I want to use it.

I'm glad it helped but I can't claim credit. That is one of the first things I learned from a beginning VBA for access book. Happy to pass it on.
 
AndWy:

That last post is mine. I came in the back door and used my email name instead of my logon name.

Been a long week.
Larry De Laruelle
larry1de@yahoo.com

 
Cheers for your help anyway Larry, hopefully one of the site's 'Wizards' will take up your challenge!
 
Just in case anyone reads this thread to the end and if you are still interested in the solution, I found the answer myself....

Public frmCurrentForm as Form
Set frmCurrentForm=Me.ActiveForm

It's only easy if you know it (as Chris Tarrant might say!)
 
oops I mean :
set frmcurrentform=screen.activeform
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top