Command button to close and open form

R

Radhika

I need to create a command button that closes form 1 and opens form 2. form 1
consists of a from and a subform. When i click on the command button, I want
the entire form with its subfrom to close and another completely different
form to open. I tried doing this using a macro in the 'On Click' event of the
command button. The macro is as follows 1. Close subfrom 1. 2. Close form 1.
3.Open form 2. However, when i click on the command button in datasheet veiw,
nothing opens of closes. What can i be doing wrong?
 
W

Wayne-I-M

I am a little confused by this. You can't have a datasheet form with a
subform.

If you have a mainform and a sub form you only need to closed the main form
(the sub will close at the same time)

Use something like this
Private Sub ButtonName_Click()
DoCmd.Close acForm, "Form1"
DoCmd.OpenForm "Form2", acNormal, "", "", , acNormal
End Sub
 
P

Pat Hartman

You don't need to close the subform separately. Rather than using macros,
let the button wizard create the VBA procedure to do this. It will
generate the code to close the current form. Open the code to edit it and
on the line above the close for the current form, add the open of the second
form.

DoCmd.OpenForm "yourformname"

Or - you can let the wizard build the code to open the second form and then
add the code to close the first form.

If you need to open the second form to a particular record, the wizard can
do that for you if you choose the correct option.
 

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