Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Posts
    41

    Unanswered: Enter Parameter message - subform /combo boxes

    Hey folks,

    I have 3 combo boxes on a form along, and based on what the user selects in the boxes, I want the subform to update automatically. I thought my code would work and it do for the 1st drop down but when I select the 2nd or 3rd box I get the Enter Parameter error message. Any suggestions would be greatly appriciated.

    Thanks

    Private Sub RunFilter()

    Dim strFilter As String
    Dim bFilter As Boolean

    bFilter = False
    strFilter = ""


    If Nz(Me.cbowbs, "<All>") > "<All>" Then 'WBS
    If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
    strFilter = strFilter & "WBS = '" & Me.cbowbs & "'"
    bFilter = True
    End If


    If Nz(Me.cbodiscipline, "<All>") > "<All>" Then 'Discipline
    If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
    strFilter = strFilter & "Discipline = '" & Me.cbodiscipline & "'"
    bFilter = True
    End If


    If Nz(Me.cbocontract, "<All>") > "<All>" Then 'Contract
    If Len(Nz(strFilter)) > 0 Then strFilter = strFilter & " And "
    strFilter = strFilter & "Contract = '" & Me.cbocontract & "'"
    bFilter = True
    End If


    If bFilter Then
    Me.Estimate_subform.Form.OrderBy = ""
    Me.Estimate_subform.Form.Filter = strFilter
    >>> Me.Estimate_subform.Form.FilterOn = True 'The debugger takes me to this line
    Else
    Me.Estimate_subform.Form.FilterOn = False
    End If



    End Sub
    Attached Files Attached Files
    Last edited by justlearning200; 01-27-10 at 16:03. Reason: Found Answer

  2. #2
    Join Date
    Oct 2004
    Location
    Oxfordshire, UK
    Posts
    89
    Your filter field parameters need to be the names of fields in the RecordSource of the form to be filtered NOT the names of the filter parameter combo boxes. Here's the code with correct field names:

    Private Sub RunFilter()
    Dim strFilter As String
    'WBS
    If Not Nz(cbowbs, "<All>") = "<All>" Then
    strFilter = strFilter & "WBS = '" & cbowbs & "'"
    End If

    'Discipline
    If Nz(cbodiscipline, "<All>") > "<All>" Then
    If Not strFilter = "" Then strFilter = strFilter & " And "
    strFilter = strFilter & "[VINL Discipline] = '" & cbodiscipline & "'"
    End If

    'Contract
    If Nz(cbocontract, "<All>") > "<All>" Then
    If Not strFilter = "" Then strFilter = strFilter & " And "
    strFilter = strFilter & "ContractNum = '" & cbocontract & "'"
    End If

    'Apply/remove filter.
    With Estimate_subform.Form
    If strFilter = "" Then
    .FilterOn = False
    Else
    .OrderBy = ""
    .Filter = strFilter
    .FilterOn = True
    End If
    End With
    End Sub

Posting Permissions

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