Navigating records in the main form through a button in a subform

nharrison

Registered User.
Local time
Today, 08:16
Joined
Jun 11, 2009
Messages
55
So my main form is a marketing contacts viewing form, and in this I have a subform which has a list of all contacts in the database (its a small one).

The subform is a continuous form formatted like a datasheet, so I can view essential data for multiple contacts at a time, while still allowing for button functionality and the like.

So next to each record, there is a button, which when clicked, I would like to search through the main form and open the record to view more detailed info.

I've tried this code but it's not working like it should:

Code:
Private Sub ContactView_Click()
On Error GoTo Err_cmdDetails_Click

DoCmd.SearchForRecord acForm, Forms![Marketing Targets], acFirst, "[Contact ID]=" & Forms![Marketing Targets]![MarketingTargetsMulti]![Contact ID]

Exit_cmdDetails_Click:
Exit Sub

Err_cmdDetails_Click:
MsgBox Err.Description
Resume Exit_cmdDetails_Click
End Sub

Attached is a screenshot of what the continuous subform is formatted like, so you understand my issue. Thanks
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    93.6 KB · Views: 239
Drop the quote marks and concatenation. This is a Where clause like in a query rather than a string comparison.
Also you need to test the field in the main form's Record Source against a field in the Current Record of the Record Source of the subform.
Without the .Form property, Access is looking for the value of a control on the subform.

[Contact ID]= Forms![Marketing Targets]![MarketingTargetsMulti].Form![Contact ID]
 
Still no luck using that string, with or w/o quotes :(
 
The problem may be that the name [Contact ID] is ambiguous. Try changing the name of the field in the Record Source of either the form or subform (and the matching name in the where clause) to prevent any confusion.

Note this does not mean changing the bound control name on the form. The clause refers to the Record Source field, not the name of the control displaying it.

Probably not the issue but I thought to mention that a common problem with referring to a subform is when the subform control which contains the subform's form object (the control's Source Object property) has a different name from the subform object itself.

[MarketingTargetsMulti] must be the name of the subform control on the main form, not the name of the subform's form object.
 

Users who are viewing this thread

Back
Top Bottom