Changing a Open Other Form Command Button

G

Guest

I created a command button, through the automatic functions, that opens and
displays another form. When the second form opens, the original form stays
open.

I'd like to change the command button or add another command so that the
first initial form closes when the second form opens. Is it possible to use a
Macro?

Below is the VB code that was automatically created by Access. I'm very
inexperienced in VB and need very specific help.

Private Sub cmdOCabForm_Click()
On Error GoTo Err_cmdOCabForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

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

Exit_cmdOCabForm_Click:
Exit Sub

Err_cmdOCabForm_Click:
MsgBox Err.Description
Resume Exit_cmdOCabForm_Click

End Sub
 
R

Ruel Cespedes via AccessMonster.com

Insert this line of code: DoCmd.Close acForm, "FormName"

"FormName" is the name of the form that you want to close. It will look like
this:


Private Sub cmdOCabForm_Click()
On Error GoTo Err_cmdOCabForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

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

DoCmd.Close acForm, "FormName"

Exit_cmdOCabForm_Click:
Exit Sub

Err_cmdOCabForm_Click:
MsgBox Err.Description
Resume Exit_cmdOCabForm_Click

End Sub




Ruel
 
G

Guest

Hi Ruel,

I added the following into the code: DoCmd.Close acForm, frm1Parts

I received the message: This action requires an Object Name Argument.

What did I miss?
 
G

Guest

Hi Again Ruel,

I discovered that I forgot to put the quote marks around the form name. Now
its working fine. Thanks for your help.
 

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