Search Button Code Help Please

  • Thread starter Thread starter missamay
  • Start date Start date
M

missamay

Hi, I am creating a search function based on a selection made from a
combo box. I have a combo box cmbSearchState and a command buttons
cmdSearchState and cmdClearState.

So far I'm using some code from Allen Browne that he posted previously
which works well (Thanks Allen!).

For the Search button

Private Sub cmbStateSearch_Click()
Dim strFilter As String
If IsNull(Me.cmbSearchState) Then
MsgBox "What state abrevation?"
Else
If Me.Dirty Then 'Save before filter
Me.Dirty = False
End If
strFilter = "[State1] = """ & Me.cmbSearchState & """"
Me.Filter = strFilter
Me.FilterOn = True
End If
End Sub

And for the Clear button (cmdClearState)

Private Sub cmbClearState_Click()
If Me.Dirty Then 'Save before remove filter
Me.Dirty = False
End If
Me.FilterOn = False

However, I want the code to search several fields including [State2],
[State3], and [State4], but I don't know how to change the code to get
it work. I tried using an OR Statement between the fields, but that did
not work. I also tried adding other IF/THEN Statements to include the
other fields, but that did not work either. Any help would be
appreciated.

Thanks,
Melissa
 
I would think that Or statements should work in the Filter property.
Something like this:

strFilter = "[State1] = """ & Me.cmbSearchState & """ OR [State2] = """ &
Me.cmbSearchState & """ OR [State3] = """ & Me.cmbSearchState & """"

Does this not work?

Barry
 
I would think that Or statements should work in the Filter property.
Something like this:

strFilter = "[State1] = """ & Me.cmbSearchState & """ OR [State2] = """ &
Me.cmbSearchState & """ OR [State3] = """ & Me.cmbSearchState & """"

Does this not work?

Barry
 
I would think that Or statements should work in the Filter property.
Something like this:

strFilter = "[State1] = """ & Me.cmbSearchState & """ OR [State2] = """ &
Me.cmbSearchState & """ OR [State3] = """ & Me.cmbSearchState & """"

Does this not work?

Barry
 
HI Barry,

Thank you so much. The code worked. I think I must have missed a ""
somewhere. It's nice to know I was on the right track though.
Thank again. You made my afternoon.

M

Barry said:
I would think that Or statements should work in the Filter property.
Something like this:

strFilter = "[State1] = """ & Me.cmbSearchState & """ OR [State2] = """ &
Me.cmbSearchState & """ OR [State3] = """ & Me.cmbSearchState & """"

Does this not work?

Barry

missamay said:
Hi, I am creating a search function based on a selection made from a
combo box. I have a combo box cmbSearchState and a command buttons
cmdSearchState and cmdClearState.

So far I'm using some code from Allen Browne that he posted previously
which works well (Thanks Allen!).

For the Search button

Private Sub cmbStateSearch_Click()
Dim strFilter As String
If IsNull(Me.cmbSearchState) Then
MsgBox "What state abrevation?"
Else
If Me.Dirty Then 'Save before filter
Me.Dirty = False
End If
strFilter = "[State1] = """ & Me.cmbSearchState & """"
Me.Filter = strFilter
Me.FilterOn = True
End If
End Sub

And for the Clear button (cmdClearState)

Private Sub cmbClearState_Click()
If Me.Dirty Then 'Save before remove filter
Me.Dirty = False
End If
Me.FilterOn = False

However, I want the code to search several fields including [State2],
[State3], and [State4], but I don't know how to change the code to get
it work. I tried using an OR Statement between the fields, but that did
not work. I also tried adding other IF/THEN Statements to include the
other fields, but that did not work either. Any help would be
appreciated.

Thanks,
Melissa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top