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

how to pass a variable in insert

P: n/a
Hi All,

I have the following code.

i m wondering how you pass the actual value of a variable to an insert
query

I want to input the value os jobnumber and finalstring

strSqlEmail1 = "INSERT INTO Table1 (job, iduser) VALUES (jobnumber,
finalstring)"

Thanks in advance

Riri

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Concatenate the values into the string, e.g.:
strSqlEmail1 = "INSERT INTO Table1 (job, iduser) VALUES (" & _
Nz(Me.jobnumber, 0) & ", ""Say what?"");"
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<el*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

I have the following code.

i m wondering how you pass the actual value of a variable to an insert
query

I want to input the value os jobnumber and finalstring

strSqlEmail1 = "INSERT INTO Table1 (job, iduser) VALUES (jobnumber,
finalstring)"

Thanks in advance

Riri

Nov 21 '05 #2

P: n/a
You need to concatenate them in. Assuming they are both numbers

strSqlEmail1 = "INSERT INTO Table1 (job, iduser) VALUES (" & jobnumber & ",
" & finalstring & ")"
--
Terry Kreft

<el*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi All,

I have the following code.

i m wondering how you pass the actual value of a variable to an insert
query

I want to input the value os jobnumber and finalstring

strSqlEmail1 = "INSERT INTO Table1 (job, iduser) VALUES (jobnumber,
finalstring)"

Thanks in advance

Riri

Nov 21 '05 #3

P: n/a
Thanks for your help . Hi again both of my fields are strings so which
formula am i using to concatenate them?

Thanks in advance

Nov 21 '05 #4

P: n/a
Thanks for your help . Hi again both of my fields are strings so which
formula am i using to concatenate them?

Thanks in advance

Nov 21 '05 #5

P: n/a
You need to concatenate them in. Assuming they are both strings <g>

strSqlEmail1 = "INSERT INTO Table1 (job, iduser) VALUES (""" & jobnumber &
""", """ & finalstring & """)"
If you notice all I've done as put a pair of double quotes whereever you
want a single double quote.
--
Terry Kreft

<el*********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Thanks for your help . Hi again both of my fields are strings so which
formula am i using to concatenate them?

Thanks in advance

Nov 21 '05 #6

P: n/a
You can also use single quotes (i.e. ...VALUES ('" & jobnumber &
"')...) to make it a bit easier to read and understand.

Nov 21 '05 #7

P: n/a
Thanks a lot guys

It works

Nov 21 '05 #8

P: n/a
Steve wrote:
You can also use single quotes (i.e. ...VALUES ('" & jobnumber &
"')...) to make it a bit easier to read and understand.

When it gets to the point that a person spends a lot of time creating a
string to do something that can be done another way, I'd do it the other
way...ex
rst.AddNew
rst!Field1 = x
rst!Field2 = y
rst.Update

Clean, easy, no wasted time parsing out a string, and easy to read.

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.