Using LEFT and LIKE in VBA

E

el zorro

I am working on an adp front end connected to SQL Server back end. When a
user clicks a command button on a form, I want a second datasheet-type form
to open, with criteria specified in the VBA code that opens it. The form is
based on an SQL View.

So far, I can open the form specifying a COMPLETE MATCH between a name on
the calling form and a name on the form that is opened:

stLinkCriteria = "[LName]=" & "'" & Me![LN] & "'" then opening the form with
the criteria.

But I want to get all the names that begin with the FIRST 3 letters. I've
tried using LEFT, but no dice. Shouldn't it work? I've tried several
different syntax combinations such as:
stLinkCriteria = "Lname Like'" & Left(Me![LastName], 3) & "*' "
but no dice.

SO I moved on to the next problem: I have another form that I want to read a
language name listed on the calling form, and search a memo field in a second
form (also based on a View) for that language. Again, I can get the results
of an EXACTmatch:

stLinkCriteria = "[Lang]=" & "'" & Me![Language] & "'" then opening the form
with the criteria.

But I can't seem to get a LIKE statement to work. I think I'm dealing with
the same basic problem in both of these. You help would be greatly
appreciated. Thanks!
 
S

Sylvain Lafontaine

On SQL-Server, the wildcard symbols for LIKE are % and _, not * and . There
is also the operator []; check the BOL for more info.
 

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