Filter

  • Thread starter Thread starter AJOLSON
  • Start date Start date
A

AJOLSON

I am using the code below to filter a form from an combo box. However all I
am getting is all records filtered out or null return.
Lets assume the combo box has a value of "C". This code is working down to
StrTemp = combo8.text. but when applied in the next line
Docmd.applyfilter,"Field1 = StrTemp" I get a null result when I would expect
a "C" Result.

Any help would be appreciated

Here is my code:
Private Sub Command6_Click()
Dim StrTemp As String
Combo8.SetFocus
StrTemp = Combo8.Text
DoCmd.ApplyFilter , "Field1 = StrTemp"

Stop
End Sub
 
Ryan Thanks,
StrTemp is = to the Content of Combo8 (changed to Me.combo8)
But when it goes to the next line of code
DoCmd.ApplyFilter , "Field1 = StrTemp"
StrTemp = null and seems to loose its value from Me.Combo8
I even change the code to read this
DoCmd.ApplyFilter , "Field1 = Me.Combo8" but still get no records returned.
 
Ok after a little trouble shooting what I can see is that in this code
DoCmd.ApplyFilter , "Field1 = StrTemp"
the StrTemp keeps its value of the combo box Does not pass it to Field1 to
filter on.
Field one in that code remains Null.
That seems to be the issue.
 
Try using the standard old filter:
Me.filter = "[your field name] = """ & me.combo8 & """"
Me.filteron = true
 
Hurray Success!!! Thanks Golfinray!!!

Ok one last thing I can’t find any code for a command button that would
clear the filter. Does anyone know of one and if so please pass it on.

Again thanks all
Andy

Golfinray said:
Try using the standard old filter:
Me.filter = "[your field name] = """ & me.combo8 & """"
Me.filteron = true

AJOLSON said:
Ryan Thanks,
StrTemp is = to the Content of Combo8 (changed to Me.combo8)
But when it goes to the next line of code
DoCmd.ApplyFilter , "Field1 = StrTemp"
StrTemp = null and seems to loose its value from Me.Combo8
I even change the code to read this
DoCmd.ApplyFilter , "Field1 = Me.Combo8" but still get no records returned.
 
Try this
Private Sub Command6_Click()
Dim StrTemp As String
DoCmd.ApplyFilter , "Field1 = " & StrTemp
..FilterOn = True
End Sub
 
Back
Top