473,461 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to pass a variable in insert

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
8 2126
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
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
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
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
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
You can also use single quotes (i.e. ...VALUES ('" & jobnumber &
"')...) to make it a bit easier to read and understand.

Nov 21 '05 #7
Thanks a lot guys

It works

Nov 21 '05 #8
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ray | last post by:
Group, Passing inline values to a udf is straightforward. However, how or is it possible to pass a column from the select of one table into a udf that returns a table variable in a join to the...
3
by: nicver | last post by:
I am fixing a client's Web site and for some reason an ASP class does not want to use the variables it retrieves when it initialiases. This is an excerpt of the class and it is enough to show...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: ILCSP | last post by:
Hello, I'm fairly new to the concept of running action pass through queries (insert, update, etc.) from Access 2000. I have a SQL Server 2000 database and I'm using a Access 2K database as my...
21
AccessIdiot
by: AccessIdiot | last post by:
Hi there, Extreme newbie here so hopefully this is an easy one. I have a switchboard with three buttons. Each button will open the same form BUT I need to pass a string depending on which...
5
by: techbuddha | last post by:
Hi new to the forum and visual basic. I am attempting to fix a migration of excel to access. The excel sheets where simple copied as is into access. for example one table lists the academic...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
10
by: Dan | last post by:
Hi, I create 5 dropdownlist in code-behind. I want to insert their selectedvalues in a table by making a string separated with ":" I can get their selecedvalues but i'm stuck when i want to...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.