Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL statement gives a compile error

Status
Not open for further replies.

tbiceps

IS-IT--Management
Nov 23, 2005
106
US
When I try to execute the following line of code, I get a compile error: Expected: case

SELECT MasterTBLReport.[Report Fields]FROM MasterTBLReport

This code was generated using the query tool, and it works. It does not work when integrated into VBA. Any clues?
 
You really expect that VBA will execute SQL code ?
Could you please elaborate on what you want to do in VBA ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
An example:
Code:
strSQL="SELECT MasterTBLReport.[Report Fields] FROM MasterTBLReport"
Set rs= CurrentDB.OpenRecordset(strSQL)

You could also create a QueryDef and open it.
 
Thanks Remou, I'll try to execute. I wanted to select all the records containing [Report Fields]data from a table called MasterTBLReport using VBA as opposed to the query tool. Using the query tool works, but once I get the text from the query, I will need to parse the string to extract each word.
 
Once you have your recordset, say:
[tt]strSQL="SELECT MasterTBLReport.[Report Fields] FROM MasterTBLReport WHERE [Report Fields] Like '*Report*'"[/tt]
You can loop through the recordset (eg Do While Not rs.EOF) and use Split to create an array from your string:
[tt]Split(rs![Report Fields]," ")[/tt]

 
I think I'm missing something here. When I try to execute the code below, I still get a compile error.

strSQL="SELECT MasterTBLReport.[Report Fields] FROM MasterTBLReport"
Set rs= CurrentDB.OpenRecordset(strSQL)

 
If the SQL is from the query design window, perhaps you can include a little more of your code? If not, check that the names are right, the spelling etc.
 
I still get a compile error
Any chance you could post the whole error message and which line is highlighted when in debug mode ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I will post the code, but if using the Split function how do you access each word in the string. For instance string = "I love Access" parses into

"I"
"Love"
"Access"

How do grab each word?
 
Split gives an array, so something like:
[tt]astrIOA = Split("I love Access", " ")
For i=0 to UBound(astrIOA)
Debug.Print astrIOA(i)
Next[/tt]
 
mystring = "I love Access"
a = Split(mystring)
For i = 0 To UBound(a): Debug.Print a(i): Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top