Question SQL help

GaryInMilwaukee

New member
Local time
Today, 07:14
Joined
Jul 23, 2010
Messages
5
I know this is a basic question but I cannot get anywhere with it:

I'm trying to use a defined variable in a docmd.sql statement, but when I run it I get no results:

Here is the code:

Private Sub Command22_Click()

Dim varX As Variant
varX = "Brandi"

DoCmd.RunSQL "SELECT Items.Owner INTO temp " & _
"FROM Items " & _
"WHERE (((Items.Owner)= '$varX'));"

End Sub


It runs but with no results. I can't get the varX variable to work in then docmd.sql statement...Help!
 
Welcome to the forum.

Here:
Code:
DoCmd.RunSQL "SELECT Items.Owner INTO temp " & _
                      "FROM Items " & _
                      "WHERE (((Items.Owner)= '" & varX & "'));"
You needed to make the variable "visible" as a variable and not a string.
 
Thanks, that worked. Something so simple... Thanks again
 
Use currentdb.execute with the onfail argument instead of docmd.SQL. It uses transactions and will rollback if an error occured.
 

Users who are viewing this thread

Back
Top Bottom