Open specific form from cmd button

S

Steve

I want to add a command button to an existing form to allow entry of
additional data for another table or tables via form. Can I control what
form is opened when they press the command button based on the value of a
field in the already open form? Do I need to do anything special after
opening the second form via command button to return bo the original form?

Thx!
 
R

Ryan

This should work for you

Private Sub YourCommandButtonName_Click()
Dim FormToOpen as String
FormToOpen = Me.TheNameOfTheField

DoCmd.OpenForm "FormToOpen"
DoCmd.Close acForm, "ThisFormsName" (Optional)
End Sub

To Return you would have a button on the other form and you could hard code
the name of the form you came from into that code.

Private Sub YourCommandButtonName_Click()

DoCmd.OpenForm "YourOriginalFormName"
DoCmd.Close acForm, "ThisFormsName" (Optional)
End Sub
 
S

Steve

I'm missing something - if the values in the field that controls what form
should open are A,B,C,D and E for example - would I name the forms A,B,C,D
and E so they match per your example?

Also, I'm not sure where I would place this code - could you please
elaborate?

THX!
 
R

Ryan

You could either name the forms A,B,C and make the display name what you want
it to be or you could make a dropdown list instead of a texbox and have the
names of the forms and the code I gave you would work.
 

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