opening and closing forms with 1 button

simeon_rose

Registered User.
Local time
Today, 23:45
Joined
Nov 4, 2000
Messages
34
i posted a topic on how to open one form whilst closing another not long ago. i received an answer saying:

Put this code on the OnClick event of the Command Button...

DoCmd.OpenForm "Nameofformyouwanttoopen"
DoCmd.Close, acForm, "Nameofformyouwanttoclose"

The problem is, I'm not sure where to put this code. My guess is that I should add it to the code behind a wizard-created "openform" button. However, not being able to program in VB, i seem to continuously mess up the structure of the entire code everytime I try to ammend the code.

Could someone please give me an explanation of how I can create a button that does what I want in a way that I can understand...I thank you if you can
 
First turn the tool wizard off while you do this. Just click the wand on the Tools tool bar. Then draw your button on your form, right click the button and choose properties. Once you have the properties menu up select the Events tab. Put your insert point in the On Click box and click on the elipse (three dots to the right of the box. It looks like this ...) The Code builder window should come up, once it does, click the code builder. Now put the code you listed above there, close it and test your button.
 
right...thanks. i now know how to build an event, but there seems to be a problem with the code. i keep getting the "runtime error 13" message and a pointer pointing at the second line of code...any solutions? i'd be made up if you could sort this out for me...help...PLEASE!
 
This code (posted below) will open Form1 and close Form2 when the button is clicked. If you want the form to open up in Edit or Add mode just change the acReadOnly to acEdit or acAdd.

Private Sub Command0_Click()

DoCmd.OpenForm "Form1", acNormal, , , acReadOnly, acNormal
DoCmd.Close acForm, "Form2"

End Sub

If you are still having problems maybe you should post your code here.
 
you are my saviour...praise be to you.
no really, i appreciate your help...thanks loads.
 

Users who are viewing this thread

Back
Top Bottom