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 - 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]) "
-
& "VALUES(" _
-
& "'" & Rkey & "'," _
-
& "'" & Rbuyer & "'," _
-
& "'" & Rdateadded & "'," _
-
& "'" & RPartNumber & "'," _
-
& "'" & RDescription & "'," _
-
& "'" & RSupplier & "'," _
-
& "'" & RProgram & "'," _
-
& "'" & RCustomer & "'," _
-
& "'" & RLine & "'," _
-
& "'" & RReason & "'," _
-
& "'" & RNSIIProdShort & "'," _
-
& "'" & RCustomerSTS & "'," _
-
& "'" & Rqty & "'," _
-
& "'" & RInvNumber & "'," _
-
& "'" & RInvDueDate & "')"
but am having trouble with punctuation. Any help will be appreciated.
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?
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?
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. - Dim zSQL As String
-
-
zSQL = _
-
"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])" & _
-
" VALUES(" & _
-
"'" & Rkey & "'" & _
-
", '" & Rbuyer & "'" & _
-
", '" & Rdateadded & "'" & _
-
", '" & RPartNumber & "'" & _
-
", '" & RDescription & "'" & _
-
", '" & RSupplier & "'" & _
-
", '" & RProgram & "'" & _
-
", '" & RCustomer & "'" & _
-
", '" & RLine & "'" & _
-
", '" & RReason & "'" & _
-
", '" & RNSIIProdShort & "'" & _
-
", '" & RCustomerSTS & "'" & _
-
", '" & Rqty & "'" & _
-
", '" & RInvNumber & "'" & _
-
", '" & RInvDueDate & "')"
-
'>see, now you can insert a debug code to check how
-
'>your string is actually resolving.
-
'debug.print zsql
-
'>
-
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.
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?
Got my problem resolved. A misspelling. Thank you very much.
I got it fixed. Thank you.
zmbd 5,501
Recognized Expert Moderator Expert
Yea... would you mind sharing the final solution for others that might search and find this thread?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
...
|
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>...
|
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
|
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...
| |
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 " &...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |