Close this form, and run this command

SueBK

Registered User.
Local time
Tomorrow, 05:53
Joined
Apr 2, 2009
Messages
197
I have a form with a command button. When the button is clicked I want it to close the form; and then run the code below. The code below works fine; does just what I want it to. But I can't work out how/where to put the docmd.close code. Every where I've tried has either not run the rest of the code; closed the form I'm going to; or just plain crashed.

Code:
Private Sub Cmd08_Click()
On Error GoTo Err_Cmd08_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "StartForm02"
If IsNull(Me![Combo03]) Then
MsgBox "Please choose a report from the drop down list."
Else
stLinkCriteria = "[RptID]=" & Me![Combo03]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me![Combo03]
End If
Me.Combo03 = Null
 
Exit_Cmd08_Click:
Exit Sub
Err_Cmd08_Click:
MsgBox Err.Description
Resume Exit_Cmd08_Click
 
I think you will need to put the DoCmd.Close command at the end of your code, but you will need to explicitly refer it to the form you wish to close, other wise it will just close the form you've just opened.

Code:
DoCmd.Close acForm, "FRM_Name"
 
Private Sub Cmd08_Click()
On Error GoTo Err_Cmd08_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "StartForm02"
stLinkCriteria = "[RptID]=" & Me![Combo03]

If IsNull(Me![Combo03]) Then
MsgBox "Please choose a report from the drop down list."

Else

DoCmd.OpenForm stDocName, , , stLinkCriteria

End If


Me.Combo03 = Null

Exit_Cmd08_Click:
Exit Sub
Err_Cmd08_Click:
MsgBox Err.Description
Resume Exit_Cmd08_Click



Try that............
 
If you want to close the form that the code is on you do not have to give it the actual name but you can use:

DoCmd.Close acForm, Me.Name, acSaveNo

The Me.Name part is generic code which you can keep exactly as written to close the form that the code is on. Me refers to the class object that is currently running the code.

You should close after running the code, so put that line (exactly as written) at the end of your code and it should work fine.
 

Users who are viewing this thread

Back
Top Bottom