Like Statements

  • Thread starter Thread starter Downie
  • Start date Start date
D

Downie

Can you tell me the difference between these 2 Like statements?

If ((rst3!msglog_text) Like "'%Abnormal%'") Then

((dbo_jobmst.jobmst_name) Like " & """" & "*" & rst2!Job_Name & "*" &
"""" & ")
 
The first is VBA, and actually won't do anything. (% isn't a valid wildcard
with VBA)

Assuming that the second one is SQL, but it's intended to take that current
value in rst2!Job_Name and look for all records in dbo_jobmst.jobmst_name
that have that current value in Job_Name anywhere in the string.
 
In Access, the * is a wildcard character. That means it represents any
number of characters. So in Access, if you wanted to run a query for
all names that start with Smi and end with an n, your Like statement
would be Like "Smi*n". Your results would give you names like
Smithson, Smitton, but not Smith. The % is also a wildcard character,
but not when used in Access. If you take your statement,
rst3!msglog_text Like "'%Abnormal%'", the only time the code in your If
statement will be executed is when rst3!msglog_text = '%Abnormal%'. In
Access, the % is treated like an ordinary character. You would use the
% as a wildcard if you were, for example, running a pass through query
to a SQL Server.

By the way, the statement after your IF...Then does not make sense.
You would not use Like in that fashion.

Hope that helps!
 
Back
Top