Command button to open and close forms

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

Im making a database that has a main page off if it you can go to two
different forms.

I made a command button on the page to open a new form, but i also want to
to close the current form so you dont get 15 different windows open. Here is
the open cmd

Private Sub cmdEnter_Click()
On Error GoTo Err_cmdEnter_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNew"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdEnter_Click:
Exit Sub

Err_cmdEnter_Click:
MsgBox Err.Description
Resume Exit_cmdEnter_Click
End Sub


What do I need to make it close the form as well?

thanks
 
Andrew said:
Im making a database that has a main page off if it you can go to two
different forms.

I made a command button on the page to open a new form, but i also
want to to close the current form so you dont get 15 different
windows open. Here is the open cmd

Private Sub cmdEnter_Click()
On Error GoTo Err_cmdEnter_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNew"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdEnter_Click:
Exit Sub

Err_cmdEnter_Click:
MsgBox Err.Description
Resume Exit_cmdEnter_Click
End Sub


What do I need to make it close the form as well?

thanks

After opening the new form, add this line:

DoCmd.Close acForm, Me.Name
 
Andrew said:
Do I put that in the open event of the new form?

does the me.name mean ME. MYFORMNAME?

No, put it in the event procedure for cmdEnter. The modified proc would
look like this:

'----- start of revised event procedure -----
Private Sub cmdEnter_Click()
On Error GoTo Err_cmdEnter_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmNew"
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, Me.Name

Exit_cmdEnter_Click:
Exit Sub

Err_cmdEnter_Click:
MsgBox Err.Description
Resume Exit_cmdEnter_Click
End Sub
'----- end of revised event procedure -----
 
Back
Top