Plz help:simple code amendment to hide a form

S

Sam Kuo

I was given the code below used to restrict user's entry to Form2, and to
close Form1 if correct password is entered. But now instead of close Form1,
I'd like to just hide it (so the user can get back to Form1 at its original
state after closing Form2).
I'm a newbie to Access coding. Could someone please show me how to amend the
code so it does just that? Thanks
--------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
Const strFormPassword As String = "password"

If InputBox("Please enter password") <> strFormPassword Then
MsgBox "Password incorrect. Please try again", vbOKOnly
Cancel = True
Else
DoCmd.Close acForm, "frmNameOfForm1", acSaveNo
End If
End Sub
 
J

Jason

Private Sub Form_Open(Cancel As Integer)
Const strFormPassword As String = "password"

If InputBox("Please enter password") <> strFormPassword Then
MsgBox "Password incorrect. Please try again", vbOKOnly
Cancel = True
Else
frmNameOfForm1.Visible = False
End If
End Sub

This hides the form... when you're ready to make it visible again just set
the property to True
frmNameOfForm1.Visible = True
 
S

Sam Kuo

Thanks, Jason. But it didn't work. An error message goes "User-defined type
not defined" after I click the command button to open Form2.

Could it be because Form2 contains subforms (if it has anything to do with
it)?Other codes in Form2's VB window include:
Private Sub Form_Load()
Private Sub Form_Unload(Cancel As Integer)
 
J

Jason

Sam... toggling a forms visibility generally should not produce this error.
Of course I could be wrong. My question is if it was working properly prior
to changing the code, was any other code changed as well? Generally this
error refers to code that uses libraries that are not referenced. See this
page for an explanatoin:
http://support.microsoft.com/kb/145759/en-us
 

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