Filtering by a variable

  • Thread starter Thread starter Mari
  • Start date Start date
M

Mari

This is my code:

Dim sLetter As String
Me.OrderBy = "MainCompany ASC"
sLetter = "B"
Me.Filter = "MainCompany >= 'sLetter'"
Me.FilterOn = True

What I'm trying to do is use the same filter and change it just by passing a
variable. However, if I put the variable in single quotes, I get an error.
If I take out the quotes, it filters literally. What am I doing wrong?
 
Try this:
Me.Filter = "MainCompany >= '" & sLetter & "'"
The tick marks show that it is text and the "&" shows
that it is a variable not literal.
Hope it works.
 
PERFECT! Thank you!!

Tommy D. said:
Try this:
Me.Filter = "MainCompany >= '" & sLetter & "'"
The tick marks show that it is text and the "&" shows
that it is a variable not literal.
Hope it works.
 
Back
Top