Dbl click code

B

bmersereau

I have the following Dbl click code in a form. Right now it opens the form
just fine to the first record however I would like it to open the form to a
new record. I cannot figure out what to add to the code for that to happen.
Can anyone help?

Private Sub NameID_DblClick(Cancel As Integer)
On Error GoTo Err_NameID_DblClick
Dim lngNameID As Long

If IsNull(Me![NameID]) Then
Me![NameID].Text = ""
Else
lngNameID = Me![NameID]
Me![NameID] = Null
End If
DoCmd.OpenForm "frmNames", , , , , acDialog, "GotoNew"
Me![NameID].Requery
If lngNameID <> 0 Then Me![NameID] = lngNameID

Exit_NameID_DblClick:
Exit Sub

Err_NameID_DblClick:
MsgBox Err.Description
Resume Exit_NameID_DblClick
End Sub
 
F

fredg

I have the following Dbl click code in a form. Right now it opens the form
just fine to the first record however I would like it to open the form to a
new record. I cannot figure out what to add to the code for that to happen.
Can anyone help?

Private Sub NameID_DblClick(Cancel As Integer)
On Error GoTo Err_NameID_DblClick
Dim lngNameID As Long

If IsNull(Me![NameID]) Then
Me![NameID].Text = ""
Else
lngNameID = Me![NameID]
Me![NameID] = Null
End If
DoCmd.OpenForm "frmNames", , , , , acDialog, "GotoNew"
Me![NameID].Requery
If lngNameID <> 0 Then Me![NameID] = lngNameID

Exit_NameID_DblClick:
Exit Sub

Err_NameID_DblClick:
MsgBox Err.Description
Resume Exit_NameID_DblClick
End Sub

Regarding: > DoCmd.OpenForm "frmNames", , , , , acDialog, "GotoNew" <
The "GoToNew" in this line is the OpenArgs argument which is passed to
the newly opened form.
To then use the OpenArgs argument, you must have some code in the
newly opened form to read it and then take some action.

Code the Load event of the form "frmNames":

If Me.OpenArgs = "GoToNew" Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If
 

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

Top