Solved

Syntax for Inserting a record with an autonumber field

Posted on 2004-09-06
7
354 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get the closest date in a query in Access 2010 8 24
2 IIF's in Access query 25 32
Progress bar in access form 11 25
Modify report 8 11
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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