Setting navigation buttons on/off

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

I am opening a form in code and I want to open the form with or without
navigation buttons depending on a condition. How do I do this? I have in
frmForm1:

DoCmd.Openform "frmForm2"
If a then
set buttons on
Else
set buttons off
End if

how do I reference the navigation buttons on frmForm2 from frmForm1?

Robert
 
The best way I know how to do this is to build your own navigation buttons.
I'll have a sample form which I'll put it up on the accessmvp website. Look
for Navigation.zip
 
Hi Robert,

In the code in your frmForm1 form, open the frmForm2 button with and without
supplying an optional OpenArg statement. For example:

If a = True then
DoCmd.Openform "frmForm2" '<---No OpenArg argument included
Else
DoCmd.Openform "frmForm2", OpenArgs:="Hello World"
End If

Add the following Form_Open event procedure to frmForm2:

Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ProcError

If Not IsNull(Me.OpenArgs) Then
Me.NavigationButtons = False
Me.RecordSelectors = False
Else
Me.NavigationButtons = True
Me.RecordSelectors = True
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in Form_Open event procedure..."
Resume ExitProc
End Sub


I have a working example that you can download, if you'd like. In this case,
frmForm1 would be the Query By Form that is the startup form,
"2frmQueryByFormExample", and frmForm2 would be my "frmMovieTitles" form. If
you open frmMovieTitles by itself, you will see the record selector and the
navigation buttons. However, if you open this same form by double-clicking a
record in the QBF form, you will not see the record selector or navigation
buttons. Here is a link to the download:

http://home.comcast.net/~tutorme2/samples/Chap08QBF.zip


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
Back
Top