PC Review


Reply
Thread Tools Rate Thread

Write data to Access table with INSERT when table has auto number

 
 
=?Utf-8?B?SG9raWV2YW5kYWw=?=
Guest
Posts: n/a
 
      20th Dec 2006
I want to write Excel table data to an access table using INSERT but need to
skip the first field because it has datatype 'AutoNumber' which doesn't
accept bing written to. Below is where I'm at, trying to write nothing (i.e.
' ') to the first field in the Access Table where the AutoNumber data type is
defined.

sSQL = "INSERT INTO tblTest VALUES ('','CatD8N', '4.5', '4', 'RMM1',
'10/10/2005', 'Comemtn 1');"

cnAccess.Execute sSQL
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      20th Dec 2006
Hi Hokie

The SQL command needs to be modified a little because you are not inserting
a complete row.

The syntax for insert is

INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)

So when you form your SQL string you need to specify the table columns:

sSQL = "INSERT INTO tblTest (field2, field3, field4, field5, field6, field7)
VALUES ('CatD8N', 4.5, 4, 'RMM1', '10/10/2005', 'Comemtn 1');"

I assume that the numbers are defined as numbers and I have removed the
quotes as they are not needed.

You need to change the field2.... to te actual name of the fields in the
database.


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Hokievandal" wrote:

> I want to write Excel table data to an access table using INSERT but need to
> skip the first field because it has datatype 'AutoNumber' which doesn't
> accept bing written to. Below is where I'm at, trying to write nothing (i.e.
> ' ') to the first field in the Access Table where the AutoNumber data type is
> defined.
>
> sSQL = "INSERT INTO tblTest VALUES ('','CatD8N', '4.5', '4', 'RMM1',
> '10/10/2005', 'Comemtn 1');"
>
> cnAccess.Execute sSQL

 
Reply With Quote
 
 
 
 
New Member
Join Date: Aug 2012
Posts: 1
 
      18th Aug 2012
Thank you so much.you helped me a lot.


Quote:
Originally Posted by =?Utf-8?B?TWFydGluIEZpc2hsb2Nr?= View Post
Hi Hokie

The SQL command needs to be modified a little because you are not inserting
a complete row.

The syntax for insert is

INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)

So when you form your SQL string you need to specify the table columns:

sSQL = "INSERT INTO tblTest (field2, field3, field4, field5, field6, field7)
VALUES ('CatD8N', 4.5, 4, 'RMM1', '10/10/2005', 'Comemtn 1');"

I assume that the numbers are defined as numbers and I have removed the
quotes as they are not needed.

You need to change the field2.... to te actual name of the fields in the
database.


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Hokievandal" wrote:

> I want to write Excel table data to an access table using INSERT but need to
> skip the first field because it has datatype 'AutoNumber' which doesn't
> accept bing written to. Below is where I'm at, trying to write nothing (i.e.
> ' ') to the first field in the Access Table where the AutoNumber data type is
> defined.
>
> sSQL = "INSERT INTO tblTest VALUES ('','CatD8N', '4.5', '4', 'RMM1',
> '10/10/2005', 'Comemtn 1');"
>
> cnAccess.Execute sSQL
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Detect Data, Auto Print Data, Auto Erase Data Loop Gamma's and Ruiter's Microsoft Excel Programming 8 14th Sep 2011 01:40 PM
Set Auto Number to say something other than "Auto Number" =?Utf-8?B?bmFpdmVwcm9ncmFtbWVy?= Microsoft Access 2 28th Oct 2005 07:19 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Microsoft Excel Discussion 2 23rd Jun 2005 11:40 PM
two tables in Access. Table 1 has 6000 records table 2 has 200. I. =?Utf-8?B?bmFwb2xhcg==?= Microsoft Access Queries 1 4th Apr 2005 08:44 PM
auto-number field as basis of second auto-number field ron Microsoft Access Database Table Design 2 12th Dec 2003 06:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 PM.