changing the recordsource of a subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can't figure out how to change the recordsource of a subform based on user
input. I construct a SQL based on user input and use that to define the
recordsource for the subform (Forms!subform.RecordSource = sql). That works
fine for the subform by itself, but it doesn't do anything to the records
displayed in the subform that is part of the main form.

Thanks for your help.

Mark
 
The syntax for referencing a subform's recordsource from the main form is:
Forms!FormName!SubformName.Form.Recordsource

Note that FormName and SubformName are stand-ins for your actual form and
subform names; the rest of the words are verbatim.
 
Thanks BruceM, but that doesn't seem to work.

I created a procedure called PopulateMatrix to update the records in the
subform based on a SELECT query passed to it by another procedure. The form
is called frmMatrixUpdate and the subform is called subPayorMatrix. Here is
the code:

Public Sub PopulateMatrix(sql As String)
Forms!frmMatrixUpdate!subPayorMatrix.Form.RecordSource = sql
End Sub

When it runs I get a Run-time error '2465': Access can't find the field
'subPayorMatrix' referred to in your expression.

This code worked great when I used a list control (named lstMatrixData)
instead of a subform, and the code read:

Public Sub PopulateMatrix(sql As String)
Me.lstMatrixData.RowSource = sql
End Sub

But I want to use a subform because with the list box I can't control how
the individual columns are formatted (text alignment).

Thanks.

Mark
 
Back
Top