Open specific form from cmd button

  • Thread starter Thread starter Steve
  • Start date Start date
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!
 
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
 
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!
 
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.
 
Back
Top