DblClick event doesn't go to new record

K

KRosier

Hi folks! Using Access2000
I have the following bit of code in the DblClick event of the combo box
cmb_team_no. It opens the proper form but always goes to the first
record, not to a new (blank) record. Can anyone point out my error?
Thanks!

Kathy

Private Sub cmb_team_no_DblClick(Cancel As Integer)

On Error GoTo Err_cmb_team_no_DblClick
Dim lngcmb_team_no As Long

If IsNull(Me![cmb_team_no]) Then
Me![cmb_team_no].Text = ""
Else
lngcmb_team_no = Me![cmb_team_no]
Me![cmb_team_no] = Null
End If

DoCmd.OpenForm "frm_team", , , , , acDialog, "GotoNew"
Me![cmb_team_no].Requery
If lngcmb_team_no <> 0 Then Me![cmb_team_no] = lngcmb_team_no

Exit_cmb_team_no_DblClick:
Exit Sub

Err_cmb_team_no_DblClick:
MsgBox Err.Description
Resume Exit_cmb_team_no_DblClick
End Sub
 
K

Ken Snell \(MVP\)

Not sure how the OpenArgs string value "GotoNew" is being handled in the
form that is being opened, but you can use an argument in the DoCmd.OpenForm
method to tell the form to just show a new record (and no records that
already exist):

DoCmd.OpenForm "frm_team", , , , acFormAdd, acDialog, "GotoNew"


However, if you want to show existing records as well as start on a new
record, then you can use the OpenArgs value and have code in the newly
opened form move the form to a new record. You can do this in the Load event
of the newly opened form:

Private Sub Form_Load()
If Me.OpenArgs = "GotoNew" Then Me.Recordset.AddNew
End Sub
 
K

KRosier

Ah, thank you for pointing me in the right direction. I had forgotten
to set up the form I was opening properly...one of the dangers of
copying code.

Thanks for the help!

Kathy
 

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