Close form from command button

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top