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!

Closing one form after another opens 1

Status
Not open for further replies.

merlynsdad

Programmer
Nov 18, 2010
175
US
From my opening screen, I'm inserting a password feature for the Administrator on one of the buttons. I want the frmMain to close when frmAdmin opens. Here's the code:
Code:
Private Sub btnAdmin_Enter()

Dim strPW As String
Dim strInput As Variant

strPW = "password"
strInput = InputBox("Enter Administrator password")
If strInput = strPW Then
    DoCmd.OpenForm "frmAdmin"
    DoCmd.Close acForm, "frmMain"
Else
    Exit Sub
End If

End Sub
I'm getting an error saying this action can't be carried out wihle processing a form. What did I do wrong?

If the square peg won't fit in the round hole, sand off the corners.
 
then reverse the events ... maybe :)

close the current form then open the next

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 

Put the
Code:
DoCmd.Close acForm, "frmMain"
in the Form_Open Event of frmAdmin.

Or, if you are going to return to frmMain when you close frmAdmin, just make frmMain invisible when you enter frmAdmin, and visible when you leave.
Code:
Forms("frmMain").Visible = False
 
OK, I put the DoCmd.Close acForm, "frmMain"
in the form open event of frmAdmin, and got the same error. Reversing them doesn't work either.

If the square peg won't fit in the round hole, sand off the corners.
 
Actually, now it's working. Don't know why it didn't before. Thanks.

If the square peg won't fit in the round hole, sand off the corners.
 
Private Sub btnAdmin_Enter() should be an on click event

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
You're right; it was that way when I inherited the db. They wrote it with macros instead of VBA, then had Access convert the macros to VBA. What a mess! I'm dumping the macros and rewriting it in VBA. Thanks.

If the square peg won't fit in the round hole, sand off the corners.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top