Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

LIKE and WILDCARD problems with VBA and variables

Posted on 2004-08-27
11
Medium Priority
?
617 Views
Last Modified: 2008-01-09
I am using Access front end on SQL Server backend. I am trying to get a SQL query in VBA code to execute correctly. I am having problems with the LIKE operand. Here is the query - is my syntax incorrect? The field jbISBN is a varchar field, the variable I am using to match is a string.

DoCmd.RunSQL "update tblJob set jbCurrentlyBilling = 1 from dbo.tblJob  " & _
       " where tblJob.jbBillTag = 1 and tblJob.jbISBN like " * " & '" & strIssueSearch & "' & " * ""

I have tried using different wildcard symbols and preconcatenating the string with the asterix, but am having no luck whatsoever. Any suggestions greatly appreciated as Im going mad trying to get this to work...

Thanks

Steph
0
Comment
Question by:Steffee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 11

Expert Comment

by:ram2098
ID: 11911599
DoCmd.RunSQL "update tblJob set jbCurrentlyBilling = 1 from dbo.tblJob  " & _
       " where tblJob.jbBillTag = 1 and tblJob.jbISBN like " % " & '" & strIssueSearch & "' & " % ""

0
 
LVL 11

Expert Comment

by:ram2098
ID: 11911604
'%' is the wild card symbol that you have to use with like in SQL.
0
 
LVL 4

Expert Comment

by:bragn
ID: 11911644
Hi Steph.

Access uses * and ? for wildcards, but ms-sql and most other sql databases use % and _ (underscore).

Best regards,
bragn.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Steffee
ID: 11911666
if I use % as in ram2098 suggestion I get an invalid character error, so I think I have to use the *, still struggling to get this to work...
0
 
LVL 11

Accepted Solution

by:
ram2098 earned 2000 total points
ID: 11911671
I guess there is small problem with quotes in your query...

DoCmd.RunSQL "update tblJob set jbCurrentlyBilling = 1 from dbo.tblJob  " & _
       " where tblJob.jbBillTag = 1 and tblJob.jbISBN like '%" & strIssueSearch & "%' "
0
 

Author Comment

by:Steffee
ID: 11911693
I am no longer getting invalid character errors but it is not perfornming the update requested i.e. setting jbCurrentlyBilling = 1.
The other where criteria are fulfilled, when I run this as a stored procedure the update occurs (I replace the variable name with the actual text: 06311 for example.Is it because it is a number I am trying to match? - although I am reading it in as a string as sometimes this contains letters as well.

Thanks

Steph
0
 
LVL 4

Expert Comment

by:bragn
ID: 11911712
Steffee

Are you running this on a linked table or as a passthru query?
If this is a linked table in Access, you should use * and ?.  

Best regards,
bragn
0
 
LVL 11

Expert Comment

by:ram2098
ID: 11911797
It doesn't matter..whether it is a character (or) a number....

If it is runnng thru stored procedure means, I guess the value that you are passing from the Access may not be correct ..
0
 
LVL 11

Expert Comment

by:ram2098
ID: 11911823
Could you please verify whether "strIssueSearch" is getting the correct value as you are expecting?
0
 

Author Comment

by:Steffee
ID: 11939714
Thanks for your replies, I am running it on a linked table in Access, and yes the strIssueSearch variable is holding the correct value. The code is not erroring on the sql command it carries on through as if it has worked properly but does not perform the update.

Thanks for your help on this so far.

Steph
0
 

Author Comment

by:Steffee
ID: 11939875
Hi, well after a fresh look at it this morning, code in the on_change() event was counter acting the code in the after update event of my button. So in fact the syntax of ram2098's answer was correct.

Thank you!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question