Filtering by a variable

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?
 
T

Tommy D.

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.
 
M

Mari

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.
 

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

Top