find record in subform

G

Guest

Hello All,
The code below is on the ON CLICK event in form "sfrm_qry_Pickup_Details".

Goal is to open form "frm Donors" and goto a specific tab, and in it's
subform "sfrm_Pickup_Pending", goto the matching record using the common
field of DonationsID.



110 DoCmd.OpenForm "frm Donors"
115 Forms![frm Donors].TabCtl200.Pages(4).SetFocus
116 Forms![frm Donors].sfrm_Pickup_Pending.SetFocus
' Find the record that matches the control.
117 Set rs = Me.Recordset.Clone
118 rs.FindFirst "[DonationsID] = " & Me![DonationsID]
119 If Not rs.EOF Then Me.Bookmark = rs.Bookmark


I do not receive an error, it just goes to the first record in the recordset.

Any assistance you can provide would be greatly appreciated.
 
A

Allen Browne

Your code opens the form, but attempts to find the record in a clone of the
recordset of the form the code belongs to (not the target form.)

The code below assumes that the record will be found in the subform. If the
subform control has anything in its LinkMasterFields/LinkChildFields
property, it will be necessary to find the correct record in the main form.
Otherwise the record won't be in the subform, so won't be found.

Dim rs As DAO.Recordset
DoCmd.OpenForm "frm Donors"
Forms![frm Donors]!TabCtl200 = 4
With Forms![frm Donors].sfrm_Pickup_Pending.Form
Set rs = .RecordsetClone
rs.FindFirst "[DonationsID] = " & Me![DonationsID]
If rs.NoMatch Then
MsgBox "Not found."
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing
 
G

Guest

Allen,
Absolutely perfect, thank you.

Allen Browne said:
Your code opens the form, but attempts to find the record in a clone of the
recordset of the form the code belongs to (not the target form.)

The code below assumes that the record will be found in the subform. If the
subform control has anything in its LinkMasterFields/LinkChildFields
property, it will be necessary to find the correct record in the main form.
Otherwise the record won't be in the subform, so won't be found.

Dim rs As DAO.Recordset
DoCmd.OpenForm "frm Donors"
Forms![frm Donors]!TabCtl200 = 4
With Forms![frm Donors].sfrm_Pickup_Pending.Form
Set rs = .RecordsetClone
rs.FindFirst "[DonationsID] = " & Me![DonationsID]
If rs.NoMatch Then
MsgBox "Not found."
Else
.Bookmark = rs.Bookmark
End If
End With
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

David said:
Hello All,
The code below is on the ON CLICK event in form "sfrm_qry_Pickup_Details".

Goal is to open form "frm Donors" and goto a specific tab, and in it's
subform "sfrm_Pickup_Pending", goto the matching record using the common
field of DonationsID.



110 DoCmd.OpenForm "frm Donors"
115 Forms![frm Donors].TabCtl200.Pages(4).SetFocus
116 Forms![frm Donors].sfrm_Pickup_Pending.SetFocus
' Find the record that matches the control.
117 Set rs = Me.Recordset.Clone
118 rs.FindFirst "[DonationsID] = " & Me![DonationsID]
119 If Not rs.EOF Then Me.Bookmark = rs.Bookmark


I do not receive an error, it just goes to the first record in the
recordset.

Any assistance you can provide would be greatly appreciated.
 

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