Command button to open and close forms

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
 
D

Dirk Goldgar

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
 
A

Andrew

Do I put that in the open event of the new form?

does the me.name mean ME. MYFORMNAME?
 
D

Dirk Goldgar

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 -----
 

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

Similar Threads


Top