Pre-load Forms (1 Viewer)

yippie_ky_yay

Registered User.
Local time
Today, 09:17
Joined
Jul 30, 2002
Messages
338
Hello all,

I have a small problem with pre-loaded forms. In my switchboard form, I pre-load another form using the following code:
DoCmd.OpenForm "myForm", , , , , acHidden

This would work perfectly except for one thing - all of my forms have either "DoCmd.Maximize" or "DoCmd.Restore" in their Activate events depending on how I need them. Because the Activate code gets executed, the form remains behind my Startup Form.

Is there another way I could pre-load my forms or is there a way to load a form and tell it to ignore its code? The reason why I like to size the form in its activate event is because most forms can be accessed in a variety of ways therefore, a "Forms!myForm!txtField.SetFocus - DoCmd.Restore" solution would be a huge task.

Thanks in advance,
-Sean
 

dcx693

Registered User.
Local time
Today, 09:17
Joined
Apr 30, 2003
Messages
3,265
Is there another way I could pre-load my forms or is there a way to load a form and tell it to ignore its code?
You can place some code in the form's open event, and pass an OpenArg to it form the calling form. Test the value of the OpenArg to see if the form should maximize or restore itself.
 

yippie_ky_yay

Registered User.
Local time
Today, 09:17
Joined
Jul 30, 2002
Messages
338
Thanks for the reply dcx, but I am still having problems trying to implement your suggestion (mostly because I've never used the "OpenArgs" before and my help file doesn't have much on it).

I don't think I understand how it works really. Could you tell me how close I am please? In the target form, I have:
Code:
Private Sub Form_Activate()
If Not Form.OpenArgs = "noshow" Then
    DoCmd.Maximize
End If
End Sub
And in my switchboard I have:
Code:
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmDataEntry", , , , , acHidden, "noshow"
End Sub
This blocks the activate code from running for sure - but (because I always hide or make visible my forms) I can't change the OpenArgs property for when I try to open the form using a button!

Thanks again!
-Sean
 

dcx693

Registered User.
Local time
Today, 09:17
Joined
Apr 30, 2003
Messages
3,265
Change:
Code:
Private Sub Form_Activate()
If Not Form.OpenArgs = "noshow" Then
    DoCmd.Maximize
End If
End Sub
to:
Code:
Private Sub Form_Activate()
If Not Me.OpenArgs = "noshow" Then
    DoCmd.Maximize
End If
End Sub
 

Matty

...the Myth Buster
Local time
Today, 08:17
Joined
Jun 29, 2001
Messages
396
I've done something similiar in the database I'm working on. I've pre-loaded most of my forms, and rather than using DoCmd.OpenForm, I just set the form's Visible property to True. But before that line of code, I set the target form's Tag property to a certain string. In your case, if I wanted to show your target form from a button click, it'd look like this behind the button:

Code:
Forms("frmDataEntry").Tag="noshow"
Forms("frmDataEntry").Visible=True

And rather than closing the target form when you're done with it, you'd set the form's visible property to False.

Hopefully that helps a bit.
 

yippie_ky_yay

Registered User.
Local time
Today, 09:17
Joined
Jul 30, 2002
Messages
338
Thank you both for your help on this!

I ended up going with Matty's suggestion because the Tag property was easier for me to use. Once the OpenArgs property is set, you cannot (or at least I couldn't) change it, so I would have to close the form completely and reopen it.

Thanks again!

-Sean
 

Users who are viewing this thread

Top Bottom