Form close help please

Tark221

Registered User.
Local time
Today, 07:17
Joined
Oct 12, 2012
Messages
74
I hope I havent posted this twice but

I basically have a main form with a list of buttons when one button is clicked
it opens a new form, how do i make it when the new form appears the main form
closes.

Thanks
 
You can add DoCmd.Close with the appropriate arguments.
 
Thanks for the quick reply, I'm fairly new to VBA

this is the code I'm using which opens the new form but doesn't close the old form

Private Sub CommandButton1_Click()
UserForm2.Show
DoCmd.Close
End Sub
 
Ah yeh forgot about that, what would those arguments be?

Sorry just really new to this
 
It's the object type, then name of report, and an opitional save. Highlight DoCmd.Close and hit F1 for help it will tell you the agruments required.
 
still cant get it too work, any example code would be helpful?
 
DoCmd.Close acForm, "frmColorReports"

This is a line from my code it closes a form named frmColorReports
 
omg this form is like terminator
still no close lol

Private Sub CommandButton1_Click()
UserForm2.Show
DoCmd.Close UserForm1, "frmUserForm1"
End Sub

This look ok ?

Appreciate all the help btw :)
 
Private Sub CommandButton1_Click()
On Error GoTo CommandButton1_Click_Err

DoCmd.OpenForm "YourFormNumberTwo", acNormal, "", "", , acNormal
DoCmd.Close acForm, "YourFormNumberOne"


CommandButton1_Click_Exit:
Exit Sub

CommandButton1_Click_Err:
MsgBox Error$
Resume CommandButton1_Click_Exit

End Sub

The mistake you did in Samantha is You used frmUserForm1 whereas you should only use UserForm1, probably.

Anyway, now use above code with replacing YourFormNumberOne and Two carefully with your form names.
 
Is the other form being opened in dialog/popup/modal? That can prevent code from continuing.
 
Thanks for the replies people

Using this code:

Private Sub CommandButton1_Click()

On Error GoTo CommandButton1_Click_Err

DoCmd.OpenForm "UserForm2", acNormal, "", "", , acNormal
DoCmd.Close acForm, "UserForm1"


CommandButton1_Click_Exit:
Exit Sub

CommandButton1_Click_Err:
MsgBox Error$
Resume CommandButton1_Click_Exit

End Sub

When I click the button it now says object required, any ideas?

Thanks
 
better if you post a sample to see why & how it is happening.
 
still cant get this to work, when I click a buttong it opens the new form on the top, but the old form doesn't close really annoying, you would think there would be a simple bit of code.
 
Solved ****

Private Sub CommandButton1_Click()
Unload MainMenu
AddAb.Show
End Sub

Seems to easy lol but yeh it works, i tried unload me ages ago didnt work then i decided to change the order of the code.

Thank you for everyones help very grateful
 
Can you post a copy of your DB in Access 2003 mdb format
 
I'm going to make a guess that it's not in Access.
 

Users who are viewing this thread

Back
Top Bottom