473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

VBA SQL - difficulty with delimiters and WHERE clause

I'm using Office 2003 on Xp sp2.

Please notice that this VBA code works and produces
a record set which contains the desired data if the WHERE
clause is omitted. When, however, the code is run as presented
below, the recordset remains empty. There definitely is the
correct data eg. "Cat" in the Table1.Table1_Name field of
the testData.mdb database. Am I doing something wrong with
the delimiters around 'C*' in the SQL?


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command5_Click()
  2.  
  3. Dim rs0  As New ADODB.Recordset
  4. Dim AccessConnect As String
  5.  
  6. ' the connection string
  7. AccessConnect = _
  8. "Driver={Microsoft Access Driver (*.mdb)};" & _
  9. "Dbq=testData.mdb;" & _
  10. "DefaultDir=C:\test;" & _
  11. "Uid=Admin;Pwd=;"
  12.  
  13. ' the query string
  14. QueryString = "SELECT Table1.Table1_Name FROM Table1 " & _
  15. "WHERE Table1.Table1_Name LIKE 'C*';"
  16.  
  17. Debug.Print QueryString
  18.  
  19. rs0.Open QueryString, AccessConnect, adOpenStatic
  20.  
  21. rs0.MoveFirst '<- error is generated if recordset is empty
  22.  
  23. rs0.Close
  24.  
  25. End Sub
Any help is appreciated.

Gregg
Mar 7 '07 #1
4 1499
Killer42
8,435 Expert 8TB
You'll find much more information about this kind of thing in the Access forum. But I think (not certain) that replacing the "*" with "%" might help.
Mar 8 '07 #2
How correct you are, on both counts. Thank you, thank you.

For anyone else wondering about DAO / ADO SQL wildcard differences:
look here
Mar 8 '07 #3
Killer42
8,435 Expert 8TB
How correct you are, on both counts. Thank you, thank you.
Glad to be some help. :)

I'll pass along that link to the Access forum Moderator(s), too.
Mar 8 '07 #4
NeoPa
32,556 Expert Mod 16PB
How correct you are, on both counts. Thank you, thank you.

For anyone else wondering about DAO / ADO SQL wildcard differences:
look here
Thank you Gregg, that's a very interesting link that I'm happy to see used.
However, you should be aware that the wildcard character sets are differentiated, not by using Access or not, but on the ANSI-92 compatibility.
From version 2003, Access has the option to be compliant with this standard (%;_;^; etc rather than *;?;!). ADP & T-SQL from SQL Server, are already compliant as standard. It's rare in my experience though, even now, to get Access database questions where the OP has the standards applied mind you.
I'm not sure about ADODB, it may default to the ANSI-92 standard too, which would explain your situation.
Mar 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: A.V.C. | last post by:
Hello, I found members of this group very helpful for my last queries. Have one problem with CASE. I can use the column name alias in Order By Clause but unable to use it in WHERE CLAUSE. PLS...
8
by: William Bradley | last post by:
Following is the code I am using, behind a command button, on a form to print out only the report of that particular form. ******************** Code Start ************************ Dim strDocName...
2
by: Bill Moran | last post by:
I'm having some problems using \copy I have a directory full of test data that I want to be installed automatically when "make database" is issued. While the Makefile rules would seem simple,...
1
NeoPa
by: NeoPa | last post by:
The ANSI standards for SQL specify that literal dates should specifically be entered in m/d/y format. In this case (y) can refer to (yy) or (yyyy). This is completely independent of regional...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
2
by: cberthu | last post by:
Hi all, I am wondering, when I issue this sql: SELECT CASE WHEN LOCATE('*',STRIP(SURRUSR)) <0 THEN REPLACE(SURRUSR,'*','%') WHEN LOCATE('%',STRIP(SURRUSR)) <0 THEN REPLACE(SURRUSR,'%','_')...
6
m6s
by: m6s | last post by:
1. After hours of researching, I used these snippets : void Object::TokenizeLines(const string& str, vector<string>& tokens, const string& delimiters) // Skip delimiters at beginning....
4
by: bearophileHUGS | last post by:
This is the best praise of semantic indentation I have read so far, by Chris Okasaki: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html A quotation: I have...
5
by: gpaps87 | last post by:
hi, i wanted to know whether we can use strtok command to mark delimiters as tokens as well.In Java,we have a command: StringTokennizer(String str, String delimiters, boolean delimAsToken) ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.