Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variables in SQL statement

Status
Not open for further replies.

japplebee

Programmer
Oct 11, 2001
5
US
I'm having troubles getting this to work. I'm updating a recordsource with information stored in variables. So far this works:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSN=webif"
Set RS = Conn.execute("INSERT INTO inbounds (customer) VALUES ('1236547')")

But when I replace the last line with this, it gives me a syntax error:

Set RS = Conn.execute("INSERT INTO inbounds (customer) VALUES (" & g_custnum & ")")

It must be how I'm inserting the variables, but I'm at a loss on how to fix it.

Any help is appreciated!
 
Hi

In the first statement you are surrounding the value 1236547 with single quotes, but when you are doing it with the variable you haven't put them in!

Set RS = Conn.execute("INSERT INTO inbounds (customer) VALUES ('" & g_custnum & "')")

Derren
[The only person in the world to like Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top