Access: The Switchboard Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

'------------------------------------------------------------
' OpenMovieFrm_Click
'
'------------------------------------------------------------

Private Sub OpenMovieFrm_Click()
On Error GoTo OpenMovieFrm_Click_Err

DoCmd.Close
DoCmd.OpenForm "Movies", acNormal, "", "", , acNormal


OpenMovieFrm_Click_Exit:
Exit Sub

OpenMovieFrm_Click_Err:
MsgBox Error$
Resume OpenMovieFrm_Click_Exit

End Sub

Database Tools ->Visual Basic

Editing the Code

Your command buttons opened every form you commanded. However, it left all of the forms open. Is there a way to close the Switchboard when you go to the MovieTitles form? Yes.

 

Look for the DoCmd in our Event Procedure. Place your cursor in front of the DoCmd and hit the enter key on your keyboard to create a new blank line.

 

Now type: DoCmd.Close

 

That’s it. You did not have to dimension another stDocName for the Switchboard form because the DoCmd.Close applies to the form you are programming.

 

Save your code and test your form.

 

Memo to self: You want to close the form you were in before opening the next form!