Running SQL in VBA

  • Thread starter Thread starter Sok Hong
  • Start date Start date
S

Sok Hong

I am currently trying to run a SQL statement depending on
what selection user chooses. It's supposed to modify a
query I've ran depending on the user's selection. However
my code doesn't seem to be running at all.

Dim SQL As String

If [List5].Value = "1" Then

SQL = "SELECT [Requirements Master Table].[Req #],
[Requirements Master Table].Priority, [Requirements Master
Table].[Full Description], [Requirements Master
Table].Comments, [Requirements Master Table].Workstream "
& _
"FROM [Requirements Master Table] " & _
"WHERE ((([Requirements Master Table].Status)=6)
AND (([Requirements Master Table].Workstream)=1))"

DoCmd.RunSQL SQL

Any suggestions?
 
It appears that you have an unbalanced number of parentheses in:

"WHERE ((([Requirements Master Table].Status)=6)
AND (([Requirements Master Table].Workstream)=1))"

Try adding an additional ) to the end of the expression:

"WHERE ((([Requirements Master Table].Status)=6)
AND (([Requirements Master Table].Workstream)=1)))"

Also, I recommend that you Dim your string variable as strSQL rather than
SQL. "SQL" is a reserved word in Access and unpredictable results may occur
when you name an object, field or variable with a reserved word. For more
info on that subject, see:

http://support.microsoft.com/default.aspx?scid=kb;en-us;209187


hth,
 
Back
Top