Access 2007 - Searching with a form

Hi experts,

I'm trying to create a search form that has several drop-down boxes which I'd like to serve as the criteria for a query. Once the user clicks "search" on the form, the query opens up with the records that match those criteria. My problem is that if the criteria section of the query says something like Forms![My search form].cbo1, if cbo1 isn't filled in on the form, the query will return nothing. Your thoughts?

Thanks...
JC_LivesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:

create a sub like this in the form's module, something like this

Sub ApplyFilter()
  Dim strFilter As String

    If Len(Me.[ComboBoard] & vbNullString) > 0 Then
        strFilter = "SumBoard=" & Me.[ComboBoard] & ""
    End If

    If Len(Me.[ComboFinance] & vbNullString) > 0 Then
        If Len(strFilter) > 0 Then
            strFilter = strFilter & " AND "
        End If
        strFilter = strFilter & "SumFinance=" & Me.[ComboFinance] & ""
    End If
   
    If Len(Me.[ComboHR] & vbNullString) > 0 Then
        If Len(strFilter) > 0 Then
            strFilter = strFilter & " AND "
        End If
        strFilter = strFilter & "SumHR=" & Me.[ComboHR] & ""
    End If

    If Len(Me.[ComboRandD] & vbNullString) > 0 Then
        If Len(strFilter) > 0 Then
            strFilter = strFilter & " AND "
        End If
        strFilter = strFilter & "SumRD=" & Me.[ComboRandD] & ""
    End If

    If Len(Me.[ComboRegulatory] & vbNullString) > 0 Then
        If Len(strFilter) > 0 Then
            strFilter = strFilter & " AND "
        End If
        strFilter = strFilter & "SumReg=" & Me.[ComboRegulatory] & ""
    End If

    If Len(Me.[ComboSales] & vbNullString) > 0 Then
        If Len(strFilter) > 0 Then
            strFilter = strFilter & " AND "
        End If
        strFilter = strFilter & "SumSales=" & Me.[ComboSales] & ""
    End If


Me.filter= strFilter
me.filteron=true
End sub

Open in new window



call the sub in the afterUpdate event of the combo boxes, like this

private sub ComboBoard_afterupdate()
applyFilter

end sub


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JC_LivesAuthor Commented:
THanks!!!
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
Sure, Try this criteria:

Like Forms![My search form].cbo1 & "*"

Open in new window

0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
Sorry about the late post.  When I viewed the post I did not see an replies.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.