473,508 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL insert into table using variables

134 New Member
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
3 52119
MSeda
159 Recognized Expert New Member
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
jamesnkk
134 New Member
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
14,534 Recognized Expert Moderator MVP
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

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

Similar topics

2
5614
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
15
7363
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
1
8728
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
11
16191
by: sm | last post by:
Hi All, Can anybody give me the syntax to insert a record into SQL server through VB code using variables? The following statement is failing! sInsertQuery = "INSERT INTO TestTab (Col1, Col2,...
4
7639
by: rudy | last post by:
I'm trying to insert text values into a table in a MSAccess DB the values are stored in string variables Imports System.Data.OleDb .... Dim name As String Dim position As String Dim site As...
0
2135
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
4
5098
bugboy
by: bugboy | last post by:
I'm inserting a new word into table 'w' and a definition into table 'c' which are linked in table 's' which is the relation table for the many to many relationship between 'w' and 'c'. I've been...
2
3187
by: adamace5o | last post by:
When i try to use post variables with php and mysql i can't get the insert into statement to accept varibles as values. If i use 'test' instead of $test it does work. I suspect it is something to do...
2
30106
by: franc sutherland | last post by:
Hello, I am using Access 2003. Is it possible to use string variables in the INSERT INTO statement? I am using the INSERT INTO statement to add a long list of contacts to a group by looping...
4
11232
bilibytes
by: bilibytes | last post by:
Hi, i am trying to INSERT into a table lets say 4 values: - value1 - value2 - value3 - value4 all these values are stored in variables($var1, $var2, $var3..), except one of them which is...
0
7223
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
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
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
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5047
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
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.