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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding Microsoft Access Database Forms 1

Status
Not open for further replies.

CoolFactor

Technical User
Dec 14, 2006
110
US
I want to hide the main form whenever I click on command button on my form and then restore the main form when the user closes the form opened by the command button.

I have the following code on the On Click Event of my command button of my main form:

Private Sub Command148_Click()
Me.Visible = False
DoCmd.OpenForm "frm_Candidate Contributions Data Entry", OpenArgs:=Me.Name
End Sub

On the "frm_Candidate Contributions Data Entry," form I have the following code in the On Unload Event of the form:

Private Sub Form_Unload(Cancel As Integer)
Forms(Me.OpenArgs).Visible = True
End Sub
 
I forgot to mention that my problem is coming in where when I try to open the frm_Candidate Contributions Data Entry form in the design view I get the following error:

Run time error 13

type mismatch
 
I would either just trap for and ignore the error or possibly move the code to the On Close event or both.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I'm still getting the same error when I compile. If move the code over to the On Close event, I still get the same error.
 
I tried your code and it worked for me. Where does the compile stop with an error? Have you stepped through to ensure that OpenArgs contains something usable?

As an aside, there are advantages in closing the form and opening it, unless you need data from the hidden form.
 
It is indicating that the error is coming from here:

Forms(Me.OpenArgs).Visible = True

Also did you try to open you form in the design because that is where I am getting the error
 
You have lost me, are you saying that when you open frm_Candidate Contributions Data Entry in design view you get a compile error or are you saying that you are using code to open the form in design view? If it is the latter, your code above does not show this.
 
If you open the form from the database window then there will be no openargs. The closing of the form will then cause an error. Try something like:
Code:
Private Sub Form_Unload(Cancel As Integer)
    If Len(Me.OpenArgs & "") > 0 Then
        Forms(Me.OpenArgs).Visible = True
    End If
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Duane,

You totally nailed with that code fix. I was saying that when I open frm_Candidate Contributions Data Entry in design view I get a compile error. That last post was the fix.

Thanks so much.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top