Solved

Syntax for Inserting a record with an autonumber field

Posted on 2004-09-06
7
353 Views
Last Modified: 2008-03-06
I am trying to insert a record into a table that has four fields and I do not know the syntax for inserting a record with the an autonumbered field.

Table name - Autotest
Field 1 - id,  Number data type
FIeld 2 - name, Text data type
Field 3 - id2, Autonumber data type
Field 4 - description, Text data type

The SQL statement I am trying to run is:

INSERT INTO autotest
VALUES (1, 'chon',   , 'female');

I've tried ## in the space for the autonumber and several others but I get a data type mismathc when running it.

Please advise on the proper SQL syntax for MS Access.

Thanks,
Chon
 
0
Comment
Question by:dlabraham
7 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 50 total points
ID: 11990545
Specify which fields you want to append your data to:

INSERT INTO autotest (Field1, Field2, Field4) VALUES (1,'chon','female')
0
 
LVL 32

Expert Comment

by:jadedata
ID: 11990551
Greetings dlabraham!

INSERT INTO autotest VALUES (clng(1), 'chon',   , 'female');

since autonumbers are long data types, try specifying the datatype.

regards
:)-j-
0
 
LVL 8

Expert Comment

by:JonoBB
ID: 11990608
You cant tell an autonumber field what value you want to put in it, hence the name 'autonumber'

If the first field is an autonumber field, then you dont reference that field.
Try:

INSERT INTO Autotest (name, ID2, description) VALUES ('chon',   , 'female')
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 8

Expert Comment

by:JonoBB
ID: 11990613
Oh, and this assumes that your ID2 field can accept null values - make sure that your field definition has been set accordingly, otherwise access will spit the dummy
0
 
LVL 84
ID: 11991039
>> You cant tell an autonumber field what value you want to put in it, hence the name 'autonumber'

Yes you can insert a Long Integer value into an AutoNumber field ... although there's no reason to do so.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 11992547
As Shane implied above, do not reference the autonumer field.

INSERT INTO autotest (Field1, Field2, Field4) VALUES (1,'chon','female').

When the record is added, the autonumber datatype will create the value for that field.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 11992565
Wished I could Spell!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now