Select record on second subform

L

Lauren H

Hello,
I have two subforms on my main form on different page tabs. When I select a
record (by clicking on it) on the subform on the first page, I would like it
to select the same record (put the arrow next to the record in the datasheet
subform view) on the second page. Is it possible to insert code to do this
into the 'on click' area?

Thanks!
 
S

strive4peace

Hi Lauren,

you can use the form Current event for the first subform to find the
same record on the second subform

'~~~~~~~~~~~~
' if you are on a new record, don't do anything
if me.newrecord then exit sub

with me.parent.subform2_controlname.form
'find the first value that matches
.RecordsetClone.FindFirst "pk_fieldname = " & me.pk_controlname

'if a matching record was found, then move to it
If Not .RecordsetClone.NoMatch Then
.Bookmark = .RecordsetClone.Bookmark
End If
end with
'~~~~~~~~~~~~

WHERE
- subform2_controlname is the Name property of the second subform control
- pk_fieldname is the field name of the primary key in the RecordSource
of the second subform
- pk_controlname is the Name property of the control on the first
subform that corresponds to pk_fieldname

am assuming that the primary key is numeric (if text or a date, you will
need to delimit)

if you need more specific code, please provide more information about
your forms and data, thanks


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
:) have an awesome day :)
*
 
Joined
Mar 9, 2013
Messages
1
Reaction score
0
Crystal,
This totally rocked my world and took my form to the next level. Thank you so much! :bow:
 

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