Open form check?

H

Harmannus

Hallo,

I have 2 forms. One is a main form and another "mainbasedform" that show a
selection of fields based on the main form. To prevent save problems i want
to prevent the main form to be opened if the mainbased form is open.

This main form is accessable through a menu bar. So how can i prevent the
main form to be opened by code if the "mainbasedform" is open?

I tried the below but can't get it to work

If Not IsLoaded("frmMainbased") Then
MsgBox "Form can't be opened!", vbInformation
Cancel = False
Else
DoCmd.OpenForm "frmMain"
End If

Thanx for any tips!

Regards,

Harmannus
 
A

Albert D. Kallal

It really depends on if you menu bar calls some code, or you in fact just
dragged the form to the menu bar (just as a side note, you can have menu
bars call your code you place in a module).

However, you can also use the forms on-open event, as it does have a cancel
option.

So, the code you have looks *almost* good, but two things:


1) you need to place the code in the on-open event

2) you need to set cancel = TRUE to CANCEL the form open.

So, the following should work:

If Not IsLoaded("frmMainbased") Then
MsgBox "Form can't be opened!", vbInformation
Cancel = True
End if


The above code goes in your main form that you want to prevent form loading.
The above code goes in the on-open event.

Further, I do assume you have the code IsLoaded, and have that in a standard
code module also..right?
 
H

Harmannus

Thanx Albert!

I draged the form from the customize menu to the menu bar! Code works just
fine now!

Thanx!


Greetz and happy christmas! No white christmas for us this year ;-( Just
rainy days uptill now...


Harmannus
 

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