473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on a SQL Insert into Question

102 New Member
I am a beginner and need help with a SQL Insert into question. The INSERT INTO has 15 fields to insert into one record. They are text fields. I am doing a

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO [dbo_part shortages] (key, buyer, [date added], [part number], description, supplier, program, customer, line, reason, [nsii prod short], [customer ship to short], qty, [inv number], [inv due date]) "
  2.    & "VALUES(" _
  3.    & "'" & Rkey            & "'," _
  4.    & "'" & Rbuyer          & "'," _
  5.    & "'" & Rdateadded      & "'," _
  6.    & "'" & RPartNumber     & "'," _
  7.    & "'" & RDescription    & "'," _
  8.    & "'" & RSupplier       & "'," _
  9.    & "'" & RProgram        & "'," _
  10.    & "'" & RCustomer       & "'," _
  11.    & "'" & RLine           & "'," _
  12.    & "'" & RReason         & "'," _
  13.    & "'" & RNSIIProdShort  & "'," _
  14.    & "'" & RCustomerSTS    & "'," _
  15.    & "'" & Rqty            & "'," _
  16.    & "'" & RInvNumber      & "'," _
  17.    & "'" & RInvDueDate     & "')"    
but am having trouble with punctuation. Any help will be appreciated.
Jun 23 '14 #1
7 1122
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code or formatted data.

What trouble are you having with punctuation?
Jun 23 '14 #2
twinnyfo
3,653 Recognized Expert Moderator Specialist
sc5502,

Only your text strings will require single quotes int he insert query. Numbers just need to have the variable. Date may require the "#" tag preceding and following the variable.

What errors are you receiving when you try to run the code?
Jun 23 '14 #3
zmbd
5,501 Recognized Expert Moderator Expert
I highly recomend that you build your string first (as follows) and then use the string variable in the function.

Expand|Select|Wrap|Line Numbers
  1. Dim zSQL As String
  2.  
  3. zSQL = _
  4.     "INSERT INTO [dbo_part shortages] " & _
  5.         "(key, buyer, [date added]" & _
  6.         ", [part number], description" & _
  7.         ", supplier, program, customer, line, reason" & _
  8.         ",  [nsii prod short], [customer ship to short]" & _
  9.         ",  qty, [inv number], [inv due date])" & _
  10.         " VALUES(" & _
  11.         "'" & Rkey & "'" & _
  12.         ", '" & Rbuyer & "'" & _
  13.         ", '" & Rdateadded & "'" & _
  14.         ", '" & RPartNumber & "'" & _
  15.         ", '" & RDescription & "'" & _
  16.         ", '" & RSupplier & "'" & _
  17.         ", '" & RProgram & "'" & _
  18.         ", '" & RCustomer & "'" & _
  19.         ", '" & RLine & "'" & _
  20.         ", '" & RReason & "'" & _
  21.         ", '" & RNSIIProdShort & "'" & _
  22.         ", '" & RCustomerSTS & "'" & _
  23.         ", '" & Rqty & "'" & _
  24.         ", '" & RInvNumber & "'" & _
  25.         ", '" & RInvDueDate & "')"
  26. '>see, now you can insert a debug code to check how
  27. '>your string is actually resolving.
  28. 'debug.print zsql
  29. '>
  30. DoCmd.RunSQL
You also a have " ' ' " around items such as [Rqry] if this isn't a text field then you most likely will incure a type error

as this is an action query, you should consider transactions and the Database.Execute Method.... you can trap any errors with the execute methods and with the transaction method you can rollback. f needed.


BTW: To show you this I had to fix a few typos so you might see if the above works in your full code.
Jun 23 '14 #4
sc5502
102 New Member
Thank you. I get a runtime error of 3127- Insert into statement unknown field name '[Customer Ship to Short]. I check this and it is in the database. Do you know what is wrong?
Jun 24 '14 #5
sc5502
102 New Member
Got my problem resolved. A misspelling. Thank you very much.
Jun 24 '14 #6
sc5502
102 New Member
I got it fixed. Thank you.
Jun 24 '14 #7
zmbd
5,501 Recognized Expert Moderator Expert
Yea... would you mind sharing the final solution for others that might search and find this thread?
Jun 24 '14 #8

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

Similar topics

3
3733
by: Frank Py | last post by:
I need to insert a last and first name field taken from a full name field on the same table. If I have 25 rows of customers in this table, what would be the best way to do this? I can split the...
5
4701
by: TThai | last post by:
HI, I'm trying to insert records to a table using bcp command. The problem is the input file to the bcp is a text file that looks like this: Text file data: 1234 abc def ghi jkl mno ...
1
1894
by: Mattias B | last post by:
Hello! I have a question about how stl's insert works on containers and on vector in particular. The question is: is it OK to insert a value before end() with something like: vector<int>...
20
8536
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
11
7485
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
2
1249
by: Daniel Tan | last post by:
I got a syntax error in SQL insert into statement , hope someone can help me .Thanks. job_search = "='" & Me.Jobno & "' " sqlstr = "INSERT INTO Custorder (job_order) " & _ "values " &...
4
943
by: jsugamele | last post by:
This is my first shot at .net. This is a website and I am trying to create a comments form. Simply I want the user to hit the submit button and have the data stored into a database and a copy...
9
3201
by: David Eades | last post by:
Hi all Complete newbie here, so apologies if this is the wrong forum. I've been asked to use mysql and asp to make a simple bidding system (rather like a simple ebay), whereby users can use a...
4
6231
by: Evyn | last post by:
Hi all, I'm starting to fool around with STL and in particular std::map. How do I iterate through one map and insert every pair in another map? I have the following so far: map<double,...
1
3729
by: PrakashRS | last post by:
Given the table T1, created by: CREATE TABLE t1 (id INTEGER GENERATED BY DEFAULT AS IDENTITY, c1 CHAR(3) ) The following SQL statements are issued: INSERT INTO t1 VALUES (1, 'ABC') INSERT INTO...
0
7114
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,...
1
7034
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
7488
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...
0
5623
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,...
1
5045
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
1544
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.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.