Goto record on master form based on subform selection

G

Guest

I need a little coding help here.

I have a datasheet subform based on the same table as the master. The
Master form is just a Single Form where edits can be made or new records
created. The sub form is "tbl_Trace subform"... I know quit wincing at my
poor naming convention.

I want the OnClick event in the subform on field [trace_ID] to make the
master form go to that record.

Thanks in advance
 
M

Marshall Barton

Bdavis said:
I have a datasheet subform based on the same table as the master. The
Master form is just a Single Form where edits can be made or new records
created. The sub form is "tbl_Trace subform"... I know quit wincing at my
poor naming convention.

I want the OnClick event in the subform on field [trace_ID] to make the
master form go to that record.


If the table's primary key is included in the subform's
record source table/query, then you can use code like this
in the subform's Current event:

With Me.Parent.RecordsetClone
.FindFirst "Trace_ID = " & Me.Trace_ID
Me.Parent.Bookmark = .Bookmark
End With
 
B

byman2030

I had a similar problem in another thread and found this solution.

It locates the current record number in the subdatasheet view, opens the
parent form in form view, and then tells the parent form to goto the record
that was in the datasheet view.

Private Sub trace_ID_OnClick(Cancel As Integer)
Dim lngrecordnum As Long
lngrecordnum = Me.CurrentRecord

DoCmd.OpenForm "tbl_TraceParentFormName", acNormal
DoCmd.GoToRecord acDataForm, "tblTraceParentFormName", acGoTo,
lngrecordnum
End Sub


Marshall Barton said:
Bdavis said:
I have a datasheet subform based on the same table as the master. The
Master form is just a Single Form where edits can be made or new records
created. The sub form is "tbl_Trace subform"... I know quit wincing at my
poor naming convention.

I want the OnClick event in the subform on field [trace_ID] to make the
master form go to that record.


If the table's primary key is included in the subform's
record source table/query, then you can use code like this
in the subform's Current event:

With Me.Parent.RecordsetClone
.FindFirst "Trace_ID = " & Me.Trace_ID
Me.Parent.Bookmark = .Bookmark
End With
 

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