Close form from command button

G

Guest

Access 2002 with Win 2000
Have a form, named party, with a command button and an onclick event to take
a person back to the switchboard form with this code:
Private Sub cmdswitch_Click()
On Error GoTo Err_Command1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Main SwitchBoard"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub

Clicking the command button does open the switchboard but I also would like
the Party Form to close when this happens. Can someone assist on how to do
this? Thanks
 
F

fredg

Access 2002 with Win 2000
Have a form, named party, with a command button and an onclick event to take
a person back to the switchboard form with this code:
Private Sub cmdswitch_Click()
On Error GoTo Err_Command1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Main SwitchBoard"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub

Clicking the command button does open the switchboard but I also would like
the Party Form to close when this happens. Can someone assist on how to do
this? Thanks

You have a lot of code written by the Access wizard that just isn't
needed, and a bit of useful error handling information that is not
included.

Try it this way:

Private Sub cmdswitch_Click()
On Error GoTo Err_Command1_Click

DoCmd.OpenForm "Main SwitchBoard"
DoCmd.Close acForm, Me.Name

Exit_This_Sub:
Exit Sub

Err_Command1_Click:
MsgBox "Error #: " & Err.Number & " " & Err.Description
Resume Exit_This_Sub
End Sub
 
M

Marshall Barton

Slow said:
Access 2002 with Win 2000
Have a form, named party, with a command button and an onclick event to take
a person back to the switchboard form with this code:
Private Sub cmdswitch_Click()
On Error GoTo Err_Command1_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Main SwitchBoard"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub

Clicking the command button does open the switchboard but I also would like
the Party Form to close when this happens. Can someone assist on how to do
this?

Add this line after the DoCmd.OpenForm ... line

DoCmd.Close acForm, Me.Name, acSaveNo
 
G

Guest

Can you explain further???

fredg said:
You have a lot of code written by the Access wizard that just isn't
needed, and a bit of useful error handling information that is not
included.

Try it this way:

Private Sub cmdswitch_Click()
On Error GoTo Err_Command1_Click

DoCmd.OpenForm "Main SwitchBoard"
DoCmd.Close acForm, Me.Name

Exit_This_Sub:
Exit Sub

Err_Command1_Click:
MsgBox "Error #: " & Err.Number & " " & Err.Description
Resume Exit_This_Sub
End Sub
 

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