Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering a Subform

Status
Not open for further replies.

kopy

Technical User
May 30, 2002
141
US
I'm trying to filter a subform. The main form is frmDataEntry, the subform is frmDataEntry2, and the criteria for the filter is a combo box cboNP on a form frmMainSwitchboard. My current code is as follows:
===========================================================
Dim stDocName, strSQL As String
Dim stLinkCriteria As String

stDocName = "frmDataEntry"
DoCmd.OpenForm stDocName, , , stLinkCriteria
strSQL = "Select * from tblPlan where"
strSQL = strSQL & " [NP]=" & Forms![frmMainSwitchboard]![cboNP]
Me.[frmDataEntry2].Form.RecordSource = strSQL
===========================================================
Any help will be greatly appreciated, Kopy
 
The "Me." in your code is probably referencing frmMainSwitchboard or whatever form contains the code. You would need to use something like:
Code:
Dim stDocName, strSQL As String
    Dim stLinkCriteria As String

    stDocName = "frmDataEntry"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    strSQL = "Select * from tblPlan where"
    strSQL = strSQL & " [NP]=" & Forms![frmMainSwitchboard]![cboNP]
    Forms![frmDataEntry].[frmDataEntry2].Form.RecordSource = strSQL
I'm not sure it this will work or not. It might depend on where the code is running. I don't generally like modifying properties of one form from another. I would prefer setting the RecordSource of the subform from code in the subform's parent.

Duane
Hook'D on Access
MS Access MVP
 
I'm now getting an error 2465 that Access can't find the field referred to int he expression.
 
Thanks for the help. I finally solved the p[roblem by writing a query that used the contents of the combo box as selection critera. I thenk filtered the main form by the query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top