PC Review


Reply
Thread Tools Rate Thread

Primary Key Value

 
 
DougW
Guest
Posts: n/a
 
      8th Jul 2008
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.

--
DougW
 
Reply With Quote
 
 
 
 
Klatuu
Guest
Posts: n/a
 
      8th Jul 2008
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.
--
Dave Hargis, Microsoft Access MVP


"DougW" wrote:

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

 
Reply With Quote
 
DougW
Guest
Posts: n/a
 
      8th Jul 2008
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.
--
DougW


"Klatuu" wrote:

> 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.
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "DougW" wrote:
>
> > 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.
> >
> > --
> > DougW

 
Reply With Quote
 
Klatuu
Guest
Posts: n/a
 
      8th Jul 2008
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
--
Dave Hargis, Microsoft Access MVP


"DougW" wrote:

> 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.
> --
> DougW
>
>
> "Klatuu" wrote:
>
> > 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.
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "DougW" wrote:
> >
> > > 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.
> > >
> > > --
> > > DougW

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot create new primary partition - only 2 primary partitions on disk Vistanoob Windows Vista Performance 6 28th May 2009 06:13 PM
How to use BOOT.INI for two primary partitions? First Primary partiton is formatted David Welch Windows XP Help 8 3rd May 2009 02:59 AM
How to use BOOT.INI for two primary partitions? First Primary partiton is formatted David Welch Windows XP General 0 2nd May 2009 11:02 AM
Backing up primary winxp so secondary can be primary when needed? DrB Windows XP Setup 0 11th Jul 2004 03:49 AM
System primary account in the primary domain missing Pradeep Microsoft Windows 2000 Active Directory 1 15th May 2004 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:01 PM.