DoCmd.OpenForm vs. Form_MyForm.Visible

duluter

Registered User.
Local time
Today, 11:59
Joined
Jun 13, 2008
Messages
101
Hello.

I was wondering if anyone could explain the differences/benefits/drawbacks of these two approaches to opening a form:

DoCmd.OpenForm "MyForm", ...

and

Form_MyForm.Visible = True


Duluter
 
The form would already have to be open but hidden for the second technique, so the 2 really do different things.
 
Yes. My bad, as they say.

Thanks,

Duluter
 
So, to open this up again, I'm a little confused.

If the form is not already open, you can't do this:

Form_MyForm.Visible = True

But you can do this:

Form_MyForm.APublicVariableInTheForm = "Something"


It's strange to me that the module for the form is available, but the form itself isn't.


Duluter
 
I'm not sure that's accurate. I don't think you can access a form level variable when the form is closed, and a brief test just now bears that out.
 
Really?

A brief test on my end bears out the opposite.

I have a form that is closed with a public variable in it. I have a subroutine in a module with this code in it:

Form_frmSample.thispublicvariable = "this"
MsgBox (Form_frmSample.thispublicvariable)

And it runs ok.

Controversy! :)


Duluter
 
Can you post the db? I was testing with 2003.
 
Sorry, this may be a dumb question, but if I post the db, will it have identifying information in it? Like my Windows username, etc.? I wouldn't want this info in the wild.

I am using 2007, but my database is saved as a 2003 mdb file. I have one completely empty form. In the module behind the form, I have only one statement, which is this:

Public thisglobalvariable As String

In the other module (not the one attached to the form), I have this:

Sub Tester()

Form_frmSample.thisglobalvariable = "this"
MsgBox (Form_frmSample.thisglobalvariable)

End Sub


When I run the subroutine in the module, the messagebox pops up with the variable's value correctly set to "this", even when the form itself is not open.


Duluter
 
Last edited:
As far as I know, the only identifying info in the database itself is what's in File/Database Properties. That said, I had tested from another form instead of a module, so I tested from a standard module. As you say, it does work from there. However, after you run that test go to Window/Unhide and you'll find that the form has been opened and hidden. Actually, you'd need the 2007 equivalent, which is in Office Button/Access Options/Customization/All Commands/Unhide

So, we're sort of both right. I'm going to see if I can find out why this happens.
 
Oh, super weird. So, this does not work (when in a standard module, run when the form is not already open):

Form_frmSample.Visible = True


But this does:

Form_frmSample.thisvariable = "this"
Form_frmSample.Visible = True


You can't "open" the form by setting its visible property to true, but if you first modify a variable in that form's module, then you can "open" it by setting its visible property to true?

I'm double confused now.


Duluter


[EDIT]

I guess it would be more accurate to say that you can't open a form like this:

Form_frmSample.Visible = True

But you can open a form like this:

Form_frmSample.thisvariable = "this"


Just the act of giving a value to a variable on the form opens that form.

Interesting...
 
I just tested and the visible didn't work by itself, as I expected. As a slight correction, this:

if you first modify a variable in that form's module, then you can "open" it by setting its visible property to true

is not technically accurate. Access opened the form in the background when you set the variable, so setting it's visible property at that point is only doing what you'd expect; making it visible, not opening it. That's probably quibbling semantics, but I want to clarify it.

I'm very surprised setting the variable worked, which I'm looking into further. I didn't know Access would open the form behind the scenes without being explicitly told to. I'll post back if I find out anything. I'm glad you pointed out this little quirk.
 
Sorry, I was typing while you edited, so you already clarified the point.
 

Users who are viewing this thread

Back
Top Bottom