By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,806 Members | 1,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,806 IT Pros & Developers. It's quick & easy.

SQL insert into table using variables

100+
P: 134
I tried and search around the web, but could not find an answer to it,
You see I am trying to insert 3 variables into the table, but seem like those " and ' cause the problem, No matter how I play with the ' and ", it still don;t work What wrong with the statement, could you please help.



Dim cust As String
Dim tel As String
Dim cont As String

cust = "Albert Longman"
tel = "1234567890"
cont = "123456789"



Dim sqls As String

sqls = "insert into tblinvoice(customer, contact, telephone) values(' " & cust & " '," & cont & " ','" & tel & ")"
DoCmd.RunSQL strstmt
Dec 20 '06 #1
Share this Question
Share on Google+
3 Replies


MSeda
Expert 100+
P: 159
try this

Dim cust As String
Dim tel As String
Dim cont As String
Dim sqls As String

cust = "Albert Longman"
tel = "1234567890"
cont = "123456789"


sqls = "insert into tblinvoice(customer, contact, telephone) values('" & cust & "', '" & cont & "', '" & tel & "');"
DoCmd.RunSQL sqls
Dec 20 '06 #2

100+
P: 134
try this

Dim cust As String
Dim tel As String
Dim cont As String
Dim sqls As String

cust = "Albert Longman"
tel = "1234567890"
cont = "123456789"


sqls = "insert into tblinvoice(customer, contact, telephone) values('" & cust & "', '" & cont & "', '" & tel & "');"
DoCmd.RunSQL sqls

Yeah It working, Thanks so much.
Dec 21 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
You are missing a couple of single quotes, also what the spaces and you were running strstmt.

Try this

Expand|Select|Wrap|Line Numbers
  1. Dim cust As String
  2. Dim tel As String
  3. Dim cont As String
  4.  Dim sqls    As String
  5.  
  6.    cust = "Albert Longman"
  7.    tel = "1234567890"
  8.    cont = "123456789"
  9.  
  10.    sqls = "INSERT INTO tblinvoice (customer, contact, telephone) " _
  11.       "VALUES ('" & cust & "','" & cont & "','" & tel & "');"
  12.    DoCmd.RunSQL sqls
  13.  
  14.  
Mary
Dec 21 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.