Selecting records using autonumber as key

  • Thread starter Thread starter sam
  • Start date Start date
S

sam

I have an MS 97 table that uses "autonumber" as primary
key. However, when I use sql to select (retrieve) a
record using an autonumber key number, the record is
never found. Example: "$db->Sql( "select * from Autolog
where RecNum='$Record_Number' ")"; where RecNum is the
table field name and $Record_Number is a known "valid"
entity in the table. The record is never found. Can
someone tell me why this happens?
 
Thanks a bunch, John. Oddly enough, I having the same
problem ( kinda ) when trying to add records to the same
table - the record(s) never get added. Example of sq1
script: $db->Sql( "INSERT INTO Autolog (Date,
Vehicle_Type, Mileage, Service_Type, Cost, Remarks)
VALUES '$Date', '$Vehicle_Type', '$Mileage','$Service_Type
', '$Cost', '$Remarks' )"). Of course, since the records
are autonumbered, no mention is made of "RecNum".
 
Did removing the quotes work? If so, then you need to do the same thing
with your INSERT - do not put quotes around number literals. You might also
need to add # delimiters around the $Date value. And, you should enclose
the name of the Date field in brackets - [Date] - because Date is a reserved
word.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Yes, removing the single quotes did work. Again,
thanks! I tried the other suggestions to no avail.
Thanks anyway.
-----Original Message-----
Did removing the quotes work? If so, then you need to do the same thing
with your INSERT - do not put quotes around number literals. You might also
need to add # delimiters around the $Date value. And, you should enclose
the name of the Date field in brackets - [Date] - because Date is a reserved
word.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)

Sam said:
Thanks a bunch, John. Oddly enough, I having the same
problem ( kinda ) when trying to add records to the same
table - the record(s) never get added. Example of sq1
script: $db->Sql( "INSERT INTO Autolog (Date,
Vehicle_Type, Mileage, Service_Type, Cost, Remarks)
VALUES '$Date', '$Vehicle_Type', '$Mileage','$Service_Type
', '$Cost', '$Remarks' )"). Of course, since the records
are autonumbered, no mention is made of "RecNum".


.
 
Back
Top