Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Syntax for Inserting a record with an autonumber field

Posted on 2004-09-06
7
Medium Priority
?
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 200 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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 85
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

609 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