Go To Main Form Record from selected subform record

Go To Main Form Record from selected subform record

Post by UmljaCB » Wed, 29 Dec 2004 08:35:03


I put a datasheet subform in my mainform that works great.
The main form is a list of workers. When a worker is selected, all the
other workers for the same company and with the same craft appear in a list
in the subform.
Is there a way by selecting a different worker in the list, that the main
form record can go to his record ? I saw how to do that by linking a second
subform but the main form already shows the information. Thanks
 
 
 

Go To Main Form Record from selected subform record

Post by tina » Wed, 29 Dec 2004 10:43:11

i assume your mainform RecordSource includes a primary key field that
identifies each "worker" record; i'll call it WorkerID. and that the same
primary key value is available in the subform record, too (as a foreign key
field); i'll call it WorkerIDfk. i also assume that the key value is a
number, not text. if so, try something along these lines (air code)

Dim lngID As Long
lngID = Me!WorkerIDfk

Me.Parent!WorkerID.SetFocus
DoCmd.FindRecord lngID

substitute the correct control names in place of WorkerIDfk and WorkerID.
then put the code in the subform's module, wherever you want to trigger the
search.

hth




list
second

 
 
 

Go To Main Form Record from selected subform record

Post by Dirk Goldg » Wed, 29 Dec 2004 10:51:52


Suppose you use the Click event of the form displayed in the subform for
this. Note that this event will fire when the user clicks on the record
selector to the left of each detail record, but not AFAIK at any other
time. You could pick some other event, or use multiple events, but I'll
give an example based on the the subform's Click event and the
assumption that there is a field named EmployeeID that is the unique key
for the table on which the main form and subform are based.

'----- start of example code -----
Private Sub Form_Click()

If IsNull(Me.EmployeeID) Then Exit Sub

If Me.Dirty Then Me.Dirty = False

Me.Parent.Recordset.FindFirst "EmployeeID=" & Me.EmployeeID

End Sub
'----- end of example code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
 
 

Go To Main Form Record from selected subform record

Post by UmljaCB » Thu, 30 Dec 2004 03:11:04

Thank you both for your help. Amazing simplicity in your solutions. I
modified the name of the ID field and it works brilliantly