Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenArgs looses hidden form name

Status
Not open for further replies.

tamus121

Technical User
Mar 19, 2007
38
GB
I'm passing the form name with code in a command button so I can move and return to the same form (Main menu)
Code:
    stDocName = "NoticeBN2"
    Me.Visible = False
    DoCmd.OpenForm stDocName, OpenArgs:=Me.Name
When NotiiceBN2 is closed I have in the form_unload event
Code:
    If Len(Me.OpenArgs & "") > 0 Then
        Forms(Me.OpenArgs).Visible = True
    End If
If I enable command buttons on the form (NoticeBN2) to give the user the option to print reports I dont get my main menu back.
Code:
        Command15.Enabled = True
I can't find out why. If I remove the code to enable the command buttons I return to the main menu as planned when cancelling form NoticeBN2 otherwise I don't. Any help or pointers would be appreciated
tamus
 
When you talk about a 'main menu', are you referring to a form?

Max Hugen
Australia
 
Hi Max, yes I am. I'm using OpenArgs to hide the main menu form and all works except this one (NoticeBN2) unless I open it with the command buttons already enabled.
When the user makes their selection via combo boxes the appropriate command button is enabled allowing them to print a word document.
tamus
 
Do you know how to debug the code, by setting a Break point? I'd check the value of the OpenArgs when the form opens to ensure it has the menu form's name, and also before and after enabling the buttons, and in the Unload event.

Max Hugen
Australia
 
Max to be honest I don't. It always works if I always cancel (close) the from NoticeBN2 immediately after opening.
I'll have to read up and try what you say. thanks
tamus
 
If it works when you first open the form, then the OpenArgs is certainly being passed to the form.

Sometimes, if there is an error in the code and Access breaks, the contents of some variables will be lost. I'm not sure if it applies to the OpenArg, but is does sound like it.

Are you getting any errors when you do things in the form?

To debug:

1. Open NoticeBN2 from the menu.

2. Press <Ctl+G> to open the Debug window, and type ?Me.OpenArgs and <Enter>. It should return the openargs value.

3. Now do something in your form that you'd usually do, and each time you do anything, check the OpenArgs in the debug window. This may help to work out if/when the OpenArgs value is being reset.

Max Hugen
Australia
 
I can only get the message "variable not yet created in this context". I am beginning to think that it might be better to close and open the form main menu rather than use visible.
tamus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top