"relating" records in subform to other than the parent form

G

Guest

I have a main form with a command button on it. The command button has this
code, which opens a form and displays only those records in a related table
that have a matching ID to the main form.

Private Sub Command116_Click()

On Error GoTo Err_Command116_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmReportDocLinks"

stLinkCriteria = "[ID]=" & Me![ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command116_Click:
Exit Sub

Err_Command116_Click:
MsgBox Err.Description
Resume Exit_Command116_Click


End Sub

What I want instead is for the command button (on the main form) to open a
form that has a subform, and for that subform to display only those records
in the related table that have a matching ID to the MAIN form.

Any suggestions?
 
S

Svetlana

DoCmd.OpenForm "frmReportDocLinks"
Forms!frmReportDocLinks!NameOfSubForm.Form.Filter = "ID=" & Me!ID
Forms!frmReportDocLinks!NameOfSubForm.Form.FilterOn= True
 

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