Results 1 to 5 of 5
  1. #1
    huongdl1987 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    26

    Multiple combobox to filter subform

    Hi, I'm trying to filter a subform based on 4 comboboxes in the main form, which are:
    City
    State
    Zip Code
    Area

    Basically, i want to search mother's based on these 4 comboboxes, so that the subform would show the filtered mom.

    However, the code that I've been using keeps giving me error. Can you help me take a look at these? I've working on these for like 1 week and it's getting me no where!

    Here is the code that I've been using:
    [/code]

    Private Function MomSearch()
    On Error GoTo Error_MomSearch
    Dim CurrentFilter As String
    Dim FilterClause As String, D As Long

    'Hold whether we use AND or OR in our filter criteria
    D = Me.DirectionGrp.Value

    '1st Combo- UpdatedMotherCity - The Table Field 'UpdatedMotherCity' is of a text datatype
    If Nz(Me.cbxMomCity.Column(0), 0) > 0 Then


    If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
    FilterClause = FilterClause & "[cbxMomCity]='" & Me.cbxMomCity.Value & "'"
    End If

    '2nd Combo- UpdatedMomState - The Table Field 'UpdatedMotherCity' is of a text datatype
    If Nz(Me.cbxMomState.Column(0), 0) > 0 Then
    If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
    FilterClause = FilterClause & "[cbxMomState]='" & Me.cbxMomState.Value & "'"
    End If

    '3rd Combo- UpdatedMomZip - The Table Field 'UpdatedMotherCity' is of a text datatype
    If Nz(Me.cbxMomZip.Column(0), 0) > 0 Then
    If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
    FilterClause = FilterClause & "[cbxMomZip]='" & Me.cbxMomZip.Value & "'"
    End If

    '4th Combo- Area - The Table Field 'Area' is of a text datatype
    If Len(Me.cbxMomArea.Value & "") > 0 Then
    If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
    FilterClause = FilterClause & "[cbxMomArea]='" & Me.cbxMomArea.Value & "'"
    End If

    'Fill this form wide variable so that it can be used for the report
    CurrentFilter = FilterClause: FilterClause = ""

    'Place our created filter criteria into the filter property of subform.
    Forms("MailMerge")("MailMergeQuery").Form.Filter = CurrentFilter
    'Turn OFF the filter
    Forms("MailMerge")("MailMergeQuery").Form.FilterOn = True

    Exit_MomSearch:
    Exit Function
    Error_MomSearch:
    MsgBox "MomSearch function Error" & vbCr & vbCr & _
    Err.Number & " - " & Err.Description, vbExclamation, _
    "Mothers Search Error"
    Resume Exit_MomSearch


    End Function




    [/code]

    AccessQuestion.zipI've also attached the file in this post.
    Please ignore the 3 errors it gives asking for mother's name and address when you first open the file. I have to delete this information to protect the ID of the mothers.

    Thank you,
    Meo

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Please post the error code and message.

    Have you tried stepping thru the code?

  3. #3
    huongdl1987 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    26
    The error is: MomSearch function error 2465- Access can't find the field 'MailMergeQuery' referred to in your expression.

    I don't know how to save as mdb file??

    Meo
    Attached Files Attached Files

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    I think there is a button or dialog hat allows you to save in a previous version or earlier format????

    Check your form names carefully, I think you have mis-identified the Form involved. Or your syntax is incorrect.

    see this for syntax
    http://access.mvps.org/access/forms/frm0031.htm

  5. #5
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Orange is correct
    'Place our created filter criteria into the filter property of subform.
    Forms("MailMerge")("MailMergeQuery2").Form.Filter = CurrentFilter --------------Your subform control name is MailMergeQuery2
    'Turn OFF the filter
    Forms("MailMerge")("MailMergeQuery2").Form.FilterOn = True --------------Your subform control name is MailMergeQuery2

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  2. Replies: 29
    Last Post: 08-16-2011, 05:52 PM
  3. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  4. Replies: 0
    Last Post: 12-16-2009, 01:14 PM
  5. Replies: 7
    Last Post: 05-24-2009, 10:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums