SubForm Double Click event (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
Is is possible to call this event and run the code there from a module ?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:41
Joined
May 21, 2018
Messages
8,525

theDBguy

I’m here to help
Staff member
Local time
Today, 14:41
Joined
Oct 29, 2018
Messages
21,454
I'd say give it try... Or, did you try it already but ran into a problem?
 

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
Great! I've got
Code:
call Form_mysubform.Prefix_DblClick
but getting error Argument not optional
Should I expect something else ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:41
Joined
Oct 29, 2018
Messages
21,454
Great! I've got
Code:
call Form_mysubform.Prefix_DblClick
but getting error Argument not optional
Should I expect something else ?
Hi. Anytime you call a routine with a non-optional argument, you will have to provide a value for the argument.
 

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
Thanks, found I had to add (vbcancel),
However now I need to select the record in that Form. I know the value of the 'Prefix' field.
Is there any VBA command to do this ? That is I know there must be but I can't think what.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:41
Joined
Oct 29, 2018
Messages
21,454
Thanks, found I had to add (vbcancel),
However now I need to select the record in that Form. I know the value of the 'Prefix' field.
Is there any VBA command to do this ? That is I know there must be but I can't think what.
You may have to modify the routine to get the value from a variable. Otherwise, make the current prefix is the one you want first.
 

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
I have the value already. Plus I found a way to do it, but I don't think it's the right or best way.
Code:
Sub GotoRecord(ByVal strPrefix As String)

    Dim rst As DAO.Recordset
    Dim strff As String
    
    Set rst =Form_mysubform.Form.RecordsetClone
    strff = "Prefix = '" & strPrefix & "'"
    
    rst.FindFirst strff
    If Not rst.NoMatch Then
             Form_mysubform.Form.Bookmark = rst.Bookmark
    End If
    
    rst.Close
    Set rst = Nothing

End Sub
Seems way too complicated. Any thoughts ? Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:41
Joined
Oct 29, 2018
Messages
21,454
Hi. Glad to hear you got it sorted out. As usual, there are more than one way to get things done in Access. I can't say if this is too complicated without knowing what the original intent was. For instance, what did the original dblclick event code do?
 

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
It gets a whole pile of data from that record and outputs it to Notepad. Gives a useful quick overview.
By complicated I meant using a recordset clone and bookmark just to goto a record. I imagined something much simpler
like DoCmd.GotoRecord(Prefix=123) might exist. Or maybe that's wishful thinking!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:41
Joined
Oct 29, 2018
Messages
21,454
Oh, I think I see what you mean. There are several ways to go to a record. I think the bookmark method is a reliable one, even if it may be a bit complicated.
 

Micron

AWF VIP
Local time
Today, 17:41
Joined
Oct 20, 2018
Messages
3,478
There is DoCmd.FindRecord, but I think what you have would be more reliable and isn't all that complicated. You can get unexpected results using a 'Find First' sort of approach which is basically what FindRecord is.
 

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
Aren't I using .FindFirst anyway ? Thanks though, I'll stick with what there.. looks liket here's no one-liner (which was probably what I was hoping for). It maybe isn't that complicated but looks like way too much code. It just has to be in that cell to run it's d-click event. (LOL yes it's not a cell but I'm not sure what Access calls it!)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:41
Joined
Oct 29, 2018
Messages
21,454
...looks liket here's no one-liner (which was probably what I was hoping for).
Actually, I think there is (or was it a two -liner?), but I think you're better off with what you got.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:41
Joined
May 21, 2018
Messages
8,525
Gives a useful quick overview.
By complicated I meant using a recordset clone and bookmark just to goto a record. I imagined something much simpler
like DoCmd.GotoRecord(Prefix=123) might exist.
The recordsetclone method is a leftover from before the recordset property of a form was accessible.

Using a recordset
me.recordset.FindFirst "Prefix = 123"
 

Micron

AWF VIP
Local time
Today, 17:41
Joined
Oct 20, 2018
Messages
3,478
Aren't I using .FindFirst anyway
Yes, I mis-spoke. I had in mind finding "First" or finding "Last" which usually trips people up because the names First and Last are misleading.
 

kirkm

Registered User.
Local time
Tomorrow, 09:41
Joined
Oct 30, 2008
Messages
1,257
Roger that Micron. MajP I've successfully changed my Sub GotoRecord to what you suggested and its working nicely. TY.
But I'm not sure what you were telling me about leftover property. And the comments saying what I had was okay or best.
Is there some issue I might run into with me.recordset.FindFirst "Prefix = 123". I like it.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:41
Joined
May 21, 2018
Messages
8,525
But I'm not sure what you were telling me about leftover property. And the comments saying what I had was okay or best.
Is there some issue I might run into with me.recordset.FindFirst "Prefix = 123". I like it.
You mentioned the long code using the recordsetclone and not the shorter recordset method that I posted. I believe the recordset clone and bookmark method that you see on the internet is a leftover from the days when you could not get the actual recordset. You had to do it the long way.
However, if you do not want to physically move the form display then use the clone. If you move in the recordset it moves the record in the form.

Using gotorecord or findfirst are different approaches, but not sure if anyone can say one is better than another. Gotorecord is pure access and findfirst is DAO. Doubt either is going away sometime soon.
 

Users who are viewing this thread

Top Bottom