Command button to make form visible

G

Guest

In ACCESS 2002 I used the following code to make form1
visible when you click the command button on form2, and
then to make form2 visible when you click on form1. I
got an error message stating that "type-declaration
character does not match declared data type."
specifically relating to "Forms!"

following is the coding:

Private Sub cmdOpen1_Click() --on main form
Me.Visible = False
DoCmd.OpenForm "Form2"
End Sub
----------------
'in second form:
Private Sub Form_Unload(Cancel as Integer)
Forms!Form1.Visible = True
End Sub

---------------------------
'in main form
Private Sub cmdOpen_Click()
Me.Vislble = False
DoCmd.OpenForm "Form2", OpenArgs:=Me.Name
End Sub

--------------
'in second form

Private Sub Form_Unload(Cancel as Integer)
Forms(Me.OpenArgs).Visible = True <---the trouble "Forms"

End Sub

Why? How to correct??? Is this an error in the program?
I tried putting a "Dim Form1, Form2 as Object" Didn't
help.
 
D

Dan Artuso

Hi,
It seems you have 2 different ways to open Form2.
In one you pass "Form1" in OpenArgs but in the other you don't pass anything.
Now in the Unload event for Form2 you seem to always be checking OpenArgs.
It seems to me this will cause problems, no?

When you get the error, what is the value of OpenArgs?
Have you checked?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top