Justin
Justin

Reputation: 4539

Access 2007 - Docmd.OpenForm not opening form, OpenArgs?

So I am trying to use a button click to open the next form (in my form flow), and pass the ID to the next form using openArgs:

docmd.openform "NextForm",,,,,, MainID
docmd.close acform, "CurrentForm", acSaveYes

the second form will not open....i have never run into this problem with a docmd.openform in a sub before. however, this is my first experience using OpenArgs....usually I would pass a value to a hidden text box, but I am trying something different.

The routine runs without error, and the currentform closes just as it should. It's like access is convinced the second form is in fact open, but its not showing up. Also if I even try to show the database objects window, and just click open the form from there.....nothing

please help! thanks Justin

Upvotes: 0

Views: 9804

Answers (2)

HarveyFrench
HarveyFrench

Reputation: 4568

You can open forms and control them Without using Open Args

You do this by opening another form as if it were a class

Create a module called GlobalVars which includes this line:

Public Form_MyFormNameToOpen as Form_MyFormNameToOpen

(The form you open will remain open until this variable "dies", so make it global to keep it alive)

MyFormNameToOpen is the name of the form you want to open and has Form_ in front of it in some of my example code. This tells access to get a "form class" ie one of the forms you created.

Then in code that you want to open a form use:

' Opens the form using it as it were a class
Set GlobalVars.Form_MyFormNameToOpen = New Form_MyFormNameToOpen

' The modify the form you have just opened however you want to.
With Form_MyFormNameToOpen
    .Visible = True

    ' This relies ont he control names never changing
    .Controls("ProviderID") = 10
    .Controls("ProviderFileID") = 11


    ' it's better to use properties created on the called form
    ' eg
    .MyLetProviderID = 10
    .MyProviderFileID = 11
End With

I hope this helps.

I find using open args a real pain except for the most basic of things. Using forms like this make life much easier.

(perhaps you can use a similar technique for subforms etc...)

Upvotes: 0

HansUp
HansUp

Reputation: 97101

It's like access is convinced the second form is in fact open, but its not showing up.

If you get no error message when the form apparently fails to open, check whether NextForm is present in the Forms collection. In the Immediate Window, try:

? Forms("NextForm").Name

What happens? The Forms collection includes the forms which are open. If you get an error message that NextForm isn't found, then NextForm is not open. But, if that command returns the name NextForm, the form is open but you can't see it.

That can happen in at least 2 ways:

  1. form has been opened hidden
  2. form has been opened at a screen position outside your visible display area

If the form really does not open, and you're not getting an error message, make sure you don't have SetWarnings and Echo turned off.

If those suggestions don't lead you to the cure, show us what NextForm is attempting to do with OpenArgs. Can you get NextForm to open if you temporarily disable its OpenArgs handling code?

Update: A couple more questions ...

Can you open NextForm in design view?

What happens if you try the following command in the Immediate Window? Error message?

DoCmd.OpenForm "NextForm",,,,,acWindowNormal

Upvotes: 4

Related Questions