Double Click event to open to specific record (1 Viewer)

T. McConnell

Registered User.
Local time
Today, 17:57
Joined
Jun 21, 2019
Messages
63
Ok, I am having a hard time getting this to work. I have seen numerous posts all over the Internet stating to use the below code. However when I place this code onto the Double click event, it opens to a blank record, but if I double click it again while the one form is still open, it will then display the correct record. Almost like I have to quad click it, which doesn't make no sense. Any suggestions?

Private Sub JobID_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmAdminOrders", , , "[JobID] = " & Me.JobID
End Sub

I have tried different variations of this code as well, but still no luck. As far as I can see the relationship links are setup correctly to use JobID as the link PK.

Thank you for any suggestions and help.
 

JHB

Have been here a while
Local time
Today, 23:57
Joined
Jun 17, 2012
Messages
7,732
In which form do you've the code when you click it first time and also the second time?
If you can't get it post your database with some sample data, zip it!
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:57
Joined
Sep 21, 2011
Messages
14,238
It will do that if the record with JobID does not exist.?

I worked around that issue by passing in the ID as OpenArgs as well

DoCmd.OpenForm "frmSubmitterClient", , , "ClientID = " & Me.ClientID, , acDialog, Me.ClientID

In the called form
Code:
Private Sub Form_Current()
If Me.NewRecord Then
    Me.ClientID = Me.OpenArgs
End If
End Sub

HTH
 

T. McConnell

Registered User.
Local time
Today, 17:57
Joined
Jun 21, 2019
Messages
63
Thank you all for the help, shortly after posting this (which was way too early in the AM lol) I was able to get it to work. Below is what I was able to get to work using some code from other sources as well. Maybe it may help someone down the road also.

Private Sub JobID_Click() '<-- I decided to go with a single click instead of a double click method, but it worked on the double click as well.
Dim rs As Object
Dim OpenAlert As Long

'Set variable to the current record
OpenAlert = Me.JobID 'Change JobID to your field
'open the new form
DoCmd.OpenForm "frmAdminOrders"

'Go to the selected record
Set rs = Forms!frmAdminOrders.RecordsetClone
rs.FindFirst "JobID = " & OpenAlert

'Optional lines shown below can be included if there's a chance the record won't exist in the form being opened
If rs.NoMatch Then 'optional - if no match, go to a new record
DoCmd.GoToRecord acForm, "frmAdminOrders", acNewRec 'optional
Else 'optional
Forms!frmAdminOrders.Bookmark = rs.Bookmark
End If 'optional
Set rs = Nothing
End Sub

Thanks again!
 
Last edited:

Users who are viewing this thread

Top Bottom