Code for closing Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an customer form that has a customer number on it. I use a button to open another form with the same customer number and other information on it. My question is where do I put the DoCmd.Close (I am assuming this is the right command) in the button code below to close the 1st form and keep the link and open the second form?

Private Sub OrderFormButton_Click(
On Error GoTo Err_OrderFormButton_Clic

Dim stDocName As Strin
Dim stLinkCriteria As Strin

stDocName = "OrderForm

stLinkCriteria = "[Customer#]=" & Me![Customer#
DoCmd.OpenForm stDocName, , , stLinkCriteri


Exit_ORderFormButton_Click
Exit Su
Err_ORderFormButton_Click
MsgBox Err.Descriptio
Resume Exit_ORderFormButton_Clic

End Sub
 
Put the DoCmd.Close after the DoCmd.OpenForm:

Private Sub OrderFormButton_Click()
On Error GoTo Err_OrderFormButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "OrderForm"

stLinkCriteria = "[Customer#]=" & Me![Customer#]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name

Exit_ORderFormButton_Click:
Exit Sub
Err_ORderFormButton_Click:
MsgBox Err.Description
Resume Exit_ORderFormButton_Click

End Sub

--
Ken Snell
<MS ACCESS MVP>

Vern said:
I have an customer form that has a customer number on it. I use a button
to open another form with the same customer number and other information on
it. My question is where do I put the DoCmd.Close (I am assuming this is
the right command) in the button code below to close the 1st form and keep
the link and open the second form?
Private Sub OrderFormButton_Click()
On Error GoTo Err_OrderFormButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "OrderForm"

stLinkCriteria = "[Customer#]=" & Me![Customer#]
DoCmd.OpenForm stDocName, , , stLinkCriteria


Exit_ORderFormButton_Click:
Exit Sub
Err_ORderFormButton_Click:
MsgBox Err.Description
Resume Exit_ORderFormButton_Click

End Sub
 
Back
Top