473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Insert Into SQL Statment

I am trying to use the sql INSERT INTO statement to add a new record.

This is the SQL statement:
sql = "INSERT INTO tblpatients(bbid, patientname, orderdate, ordertime,
mrnumber, sex, age, drawnby, drawnbytime, doctor, dob, location,
type-r-h, donortype-r-h, componet, antibody, unitnum, expdate, coombs,
crossmatch, rhogam, unitnumber2, expdate2, fetal, commanet) VALUES
('bid', 'ptname', 'orddte', 'ordtime', 'mrnum', 'ptsex', 'ptage',
'drawby', 'drawbytime', 'doc', 'ptdob', 'loc', 'typerh', 'dnrtype',
'compo', 'antibdy', 'unitnumber', 'expdte', 'combs', 'crsmtch', 'rhogm',
'unitnumber2', 'expdte2', 'baby', 'comments')"

I then use the following command to run it.
DoCmd.RunSQL sql

What this is doing is adding a new record to the table and then printing
a report based on the new record.
I am not very good with VBA so this was the best I could come up with.
I get a SQL syntax error when I run it. I tried the way the help in
MS-Access should me but that did not work either.
Ayone have any ideas?

Michael Charney

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
1 1871
Nothing wrote:
I am trying to use the sql INSERT INTO statement to add a new record.

This is the SQL statement:
sql = "INSERT INTO tblpatients(bbid, patientname, orderdate,
ordertime, mrnumber, sex, age, drawnby, drawnbytime, doctor, dob,
location, type-r-h, donortype-r-h, componet, antibody, unitnum,
expdate, coombs, crossmatch, rhogam, unitnumber2, expdate2, fetal,
commanet) VALUES ('bid', 'ptname', 'orddte', 'ordtime', 'mrnum',
'ptsex', 'ptage', 'drawby', 'drawbytime', 'doc', 'ptdob', 'loc',
'typerh', 'dnrtype', 'compo', 'antibdy', 'unitnumber', 'expdte',
'combs', 'crsmtch', 'rhogm', 'unitnumber2', 'expdte2', 'baby',
'comments')"

I then use the following command to run it.
DoCmd.RunSQL sql

What this is doing is adding a new record to the table and then
printing a report based on the new record.
I am not very good with VBA so this was the best I could come up with.
I get a SQL syntax error when I run it. I tried the way the help in
MS-Access should me but that did not work either.
Ayone have any ideas?


Where are those VALUES items coming from? You are attempting (for example)
to insert the string literal "orddte" into a date field (assuming OrderDate
is a Date field). Did you intend those to be variable names? If so you
have to delimit the SQL string so that the variables are outside of the
quotes. This will cause the constructed statement to include the *values*
of the variables rather than the names of the variables. In addition, you
would need to add single quotes around the string values, pound delimiters
(#) around the dates, and no delimiter around the numeric values for it to
work.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street, city, zip, phone, fax, etc...) about 20 more...
1
by: Maria | last post by:
Hello I have not used db2 in a long time, and I have this very long insert script, which is giving me an error of duplicated inserts. My question is how can I put something in the statment so...
2
by: 73blazer | last post by:
Perhaps my thinking is wrong but this is what I have: 1 table (Tab1) with 1 attribute (Attr1) Attr1 char(16) for bit data ----------------------------------------------- create trigger...
8
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a way to do this with DB2, is there a way? I'm...
10
by: Daniel P. | last post by:
How can I use ADO.NET to insert lots of records in a very fast way? Thanks!
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
2
by: Denis Correard | last post by:
I have an application that create an insert statment on the fly (it would be to complex to create stored procedures for all senarios) like: insert into Table (field1, field2,field3 ,field4 ) VALUES...
0
by: isaac2004 | last post by:
im trying to make a page that reads simple user information and posts them to a table. the user can edit, delete and add new records, through a form on the page.using SQLs modifications like...
1
by: zeebiggie | last post by:
Good morning I have a form with the controls in the insert statment below. table1 has an Auto increment primary key hence is omitted in the insert statment and form. Am getting the error It didnt...
8
by: slb813 | last post by:
Hello, I am having a problem that I can't seem to work out. I am running Apache 2.2 on a Windows XP platform, using PHP5. I am attempting to insert a row into a MS Access data base with a PHP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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
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
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,...

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.