close a form as you open a new form

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I have a form frmAllDealer that displays all my dealer i then have a
view button that open frmDealer up and displays all the info

i use the standard wizard code to open up the form
where about in the form and what code do i type so that it closes
frmAllDealer after frmDealer has opened


Thanks

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmDealer"

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

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub
 
Hi, Simon.
i use the standard wizard code to open up the form
where about in the form and what code do i type so that it closes
frmAllDealer after frmDealer has opened

Try:

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmDealer"

stLinkCriteria = "[AccountNumber]=" & Me![AccountNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name ' Close this form.

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


Simon said:
I have a form frmAllDealer that displays all my dealer i then have a
view button that open frmDealer up and displays all the info

i use the standard wizard code to open up the form
where about in the form and what code do i type so that it closes
frmAllDealer after frmDealer has opened


Thanks

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmDealer"

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

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub
 
This should do it. Note: I added a check to save the current record, in case
it was dirty (ie. being edited). This way, the AccountNumber should be
current if it was changed (if it is not an autonumber). Also, using code to
close a form can result in a loss of edits if a required field has not been
filled in.

Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

Dim stDocName As String
Dim stLinkCriteria As String

If Me.Dirty = True Then
Me.Dirty = False
End If

stDocName = "frmDealer"
stLinkCriteria = "[AccountNumber]=" & Me![AccountNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria

DoCmd.Close acForm, Me.Name '<-------********************

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub


To make your code a bit more readable, I suggest that you rename the command
button Command11 to something like cmdOpenDealersForm.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________
 
Back
Top