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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word -> Access SQL statement problems 2

Status
Not open for further replies.

PerlIsGood

Programmer
Jan 24, 2002
154
US
Can anyone point out the problem/error in the following SQL query?

Code:
rst.Open _
  "SELECT * FROM tblClients WHERE [Billing Code] = " & UCase(sClientCode), _
  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=" & FileLoc & ";"
For Each fld In rst.Fields
  MsgBox fld.Value & ";"
Next

When I remove the WHERE clause it will pull a record from the database, not the one I need, but the code itself works. I just need to figure out how to get the variable into the statement so that I can pull the correct info...

Running the code with the WHERE clause in place I get this error:

Run-time error: 'numbers...
No value given for one or more required parameters

Any help would be greatly appreciated [peace] Notorious P.I.G.
 
Not sure if this is it, but I think you need single quote tick marks around your clientcode like this:

"SELECT * FROM tblClients WHERE [Billing Code] = '" & UCase(sClientCode) & "'",

Good Luck!
 
Generic followup for where clauses:

Strings need single quotes ', dates need pound signs #, if your field names contain embedded spaces you need square brackets []

Examples:

"[Last Name] = '" & yourvar & "'"
"Birthday > #" & yourdatevar & "#"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top