Insert query problem

G

Guest

Can anyone tell me how to insert a new record into a
table when "autonumber" is turned on? I can insert
records as long as I supply a number for the RecID
("autonumber") field, but I don't want to do that. I
want to insert records and let "autonumber" supply the
next sequential number for "RecID."
 
S

Steve Schapel

There should be no problem to do this with a simple Append Query. Just
include all the other fields in the query, but not the autonumber field,
and when you run the query, the autonumber value should be ... well,
autonumbered! If this is not working for you as expected, please post
back with the SQL view of the query you are trying.
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It should work as you describe. How are you inserting the record?

SQL example:

Table:
column_1 Autonumber
column_2 Text

INSERT INTO TableName (column_2)
VALUES ("value for column_2")

This should insert the value into the table and generate a new
AutoNumber for the row. You don't have to designate the AutoNumber
column in the INSERT columns statement. I.e., don't do this:

INSERT INTO TableName(column_1, column_2)
VALUES ("value for column_2")


MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQDOw84echKqOuFEgEQKWlACePlC44CwLFmSUEsY8qkg11ILvwsMAoKHf
H1ORoR9XRlHGJkKrN6KfaRAt
=Rd70
-----END PGP SIGNATURE-----
 
G

Guest

ADD:
$DSN = "Autostats";
use win32::ODBC;
$db = new Win32::ODBC($DSN);
$db->Sql( "INSERT INTO Autolog VALUES
($Date, '$Vehicle_Type', $Mileage, '$Service_Type',
$Cost, '$Remarks' ) ");

The above syntax does not "insert" into the table,
however, the following does when a value has been
assigned to "RecNum:"

ADD:
$DSN = "Autostats";
use win32::ODBC;
$db = new Win32::ODBC($DSN);
$db->Sql( "INSERT INTO Autolog VALUES
( $RecNum, '$Date', '$Vehicle_Type',
Mileage, '$Service_Type $Cost, '$Remarks' ) ");
 
G

Guest

ADD:
$DSN = "Autostats";
use win32::ODBC;
$db = new Win32::ODBC($DSN);
$db->Sql( "INSERT INTO Autolog VALUES
($Date, '$Vehicle_Type', $Mileage, '$Service_Type',
$Cost, '$Remarks' ) ");

The above syntax does not "insert" into the table,
however, the following does when a value has been
assigned to "RecNum:"

ADD:
$DSN = "Autostats";
use win32::ODBC;
$db = new Win32::ODBC($DSN);
$db->Sql( "INSERT INTO Autolog VALUES
( $RecNum, '$Date', '$Vehicle_Type',
Mileage, '$Service_Type $Cost, '$Remarks' ) ");
 
G

Guest

ADD:
$DSN = "Autostats";
use win32::ODBC;
$db = new Win32::ODBC($DSN);
$db->Sql( "INSERT INTO Autolog VALUES
($Date, '$Vehicle_Type', $Mileage, '$Service_Type',
$Cost, '$Remarks' ) ");

The above syntax does not "insert" into the table,
however, the following does when a value has been
assigned to "RecNum:"

ADD:
$DSN = "Autostats";
use win32::ODBC;
$db = new Win32::ODBC($DSN);
$db->Sql( "INSERT INTO Autolog VALUES
( $RecNum, '$Date', '$Vehicle_Type',
Mileage, '$Service_Type $Cost, '$Remarks' ) ");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top