Primary Key Value

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.
 
K

Klatuu

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.
 
D

DougW

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.
 
K

Klatuu

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
 

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