bit of VBA code wrong

Duritz

Board Regular
Joined
Apr 28, 2005
Messages
226
Can someone with more VBA ability than my humble self have a quick peek at this and tell me where I've mucked it up? The error message is below: (this is querying an Access database)

Code:
sql_st = "Select * FROM data Where cat_dist = " & dist & " AND where reliability_best_now = " & reliability & " AND where EP_THEN_FINAL_MARK = '" & form & "' AND where cat_fitness = '" & fitness & "'"

and the error message says there's a Syntax error (missing operator)

cat_dist and reliability_best_now are both numbers, the other two are both text
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi Duritz, it looks like you have too many WHERE operators. Try
Code:
sql_st = "Select * FROM data Where cat_dist = " & dist & " AND reliability_best_now = " & reliability & " AND EP_THEN_FINAL_MARK = '" & form & "' AND cat_fitness = '" & fitness & "'"
If that doesn't do the trick, try also using parentheses:
Code:
sql_st = "Select * FROM data Where ((cat_dist = " & dist & ") AND (reliability_best_now = " & reliability & ") AND (EP_THEN_FINAL_MARK = '" & form & "') AND (cat_fitness = '" & fitness & "'))"
Denis
 
Upvote 0
Duritz

Just to clarify this is not really a VBA error, it's an error in the syntax of the SQL statement.:)
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top