open record set with sql

M

Marc

stPlanID = Me!agtplan
stTest = "[PlanID] = " & stPlanID & ""

this works:

rst.Open "SELECT * FROM tblAgtSplits WHERE ([PlanID] = 8)",_
CurrentProject.Connection

but this doesn't and I can't figure out why:

rst.Open "SELECT * FROM tblAgtSplits WHERE (stTest)",_
CurrentProject.Connection
 
B

Brendan Reynolds

rst.Open "SELECT * FROM tblAgtSplits WHERE (" & stTest & ")"

SQL Server doesn't 'know' that stTest is the name of a variable. You have to
get VBA to evaluate the variable and concatenate the value of the variable,
rather than its name, into the SQL statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top