Button is visible if a certain form is open

G

Guest

I am trying to write some vb code that will only make a button visible if a
certain form is open.

The code i thought would work is as follows

Private Sub Form_Open(Cancel As Integer)
If IsOpen("frmOrders") Then
Command47.Visible = True
Else
Command47.Visible = False
End If
End Sub

my hope was that command47 button would only be visible if frmOrders is open.
However when i open the form that holds the code an error message comes up
saying there is a compile error and IsOpen is selected in VB of the above
code.

Can anyone please help
 
T

tina

looks like IsOpen() is a user-defined function. do you have the function
stored in either the form's module, or a standard module, in your database?
if not, try using this code instead:

Public Function IsLoaded(ByVal strFormName As String) As Boolean

' Returns True if the specified form is open.
Dim frm As AccessObject
Set frm = CurrentProject.AllForms(strFormName)
IsLoaded = frm.IsLoaded

End Function

paste the above function into a standard module. then change the code that
run's in the form's Open event, to

Command47.Visible = IsLoaded("frmOrders")

personally, i would run the code from the form's Load event instead of the
Open event, but probably it won't really matter. also, note that it's a good
idea to compile your code when you edit it, so that you catch some errors
immediately; in the VBE window, click Debug | Compile from the menu bar.

hth
 

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