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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,214,520
Messages
6,120,017
Members
448,936
Latest member
almerpogi

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