Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2008
    Posts
    150

    Answered: NOT WORKING! Filter Datasheet Subform from a Mainform using an unbound Combo Box

    Hi All,

    I have searched the web for an answer and found some really close ones, but none that I could use for my form.

    I have a datasheet subform (subfrmEE) that I would like to filter. I have an unbound combo box (cbo_EEProjNum) above the subform to use as the control for filtering.

    I have the master/child links set. I added the SQL statement to the “After Update” event properties, but nothing is working. Frustrating.

    <Begin Code>
    Me.RecordSource = "SELECT * FROM EEtbl WHERE EEtbl.Project Number = " & cbo_EEProjNum
    <End Code>

  2. Best Answer
    Posted by Sinndho

    "If you want to filter the subform (subfrmEE), you need to address the subform Recordsource property. In the main (parent) form:
    Code:
    Private Sub cbo_EEProjNum_AfterUpdate()
        Me.subfrmEE.Form.RecordSource = "SELECT * FROM EEtbl WHERE EEtbl.Project Number = " & cbo_EEProjNum
    End Sub
    This suppose that the SubForm/SubReport control has the same name as the one of the subform it contains (they can be different). If it's not the same, you need to use the name of the control, not the name of the subform in the code.

    See also: http://access.mvps.org/access/forms/frm0031.htm"


  3. #2
    Join Date
    Mar 2009
    Posts
    5,441
    Provided Answers: 14
    If you want to filter the subform (subfrmEE), you need to address the subform Recordsource property. In the main (parent) form:
    Code:
    Private Sub cbo_EEProjNum_AfterUpdate()
        Me.subfrmEE.Form.RecordSource = "SELECT * FROM EEtbl WHERE EEtbl.Project Number = " & cbo_EEProjNum
    End Sub
    This suppose that the SubForm/SubReport control has the same name as the one of the subform it contains (they can be different). If it's not the same, you need to use the name of the control, not the name of the subform in the code.

    See also: http://access.mvps.org/access/forms/frm0031.htm
    Last edited by Missinglinq; 05-06-15 at 11:26.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •