Primary Key Value

  • Thread starter Thread starter DougW
  • Start date Start date
D

DougW

I want to get the value of the primary key (which uses autonumber) once I
find a particular record. How do I do that?

The table has a primary key field simply called "ID"

Thanks.
 
Where do you want to do that and how do you want to use it?
A bit more detail would be helpful to get you a better answer.
 
I know this will seem strange, but I want to use the PK and delete all
records with a primary key >= the record that I search for and find.

I am importing an Excel spreadsheet with some weird data and when it is
imported, the PK is added in sequence of the rows, of course. I then am going
to search for specific text that exists only in one record, and then delete
that record and all records after that record.

The reason is that the rest of the field values in the records don't make it
possible to create a query criteria which I can use to eliminate the bad
records.

I am doing this in Visual Basic for Access.
 
Aha!
One line of code. Assume you have a variable named lngID which is a long
integer that is the value of the ID and you want to delete all the records in
the table with ah higher number:

Currentdb.Execute "DELETE * FROM MyTable WHERE ID > " & lngID & ";",
dbFailOnError
 
Back
Top