Re: Unique Index
- From: "paii, Ron" <paii@xxxxxxxxxxxxxx>
- Date: Tue, 15 Aug 2006 14:14:52 -0500
"RoyVidar" <roy_vidarNOSPAM@xxxxxxxx> wrote in message
news:mn.7a3f7d68e27fbf60.57374@xxxxxxxxxxx
"paii, Ron" <paii@xxxxxxxxxxxxxx> wrote in messageI will give that code a try. Will the new key show in the GUI or will I need
<WvudnRG6w5MpJn3ZnZ2dnUVZ_oednZ2d@xxxxxxxxxxx>:
"Rick Brandt" <rickbrandt2@xxxxxxxxxxx> wrote in message
news:rL2Eg.12409$gY6.9784@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
paii, Ron wrote:
I have a table listing drawing numbers for jobs. It's primary key
combines Job and numeric part of the drawing number. The structure
allows the number part to repeat for each job.
Job Dwg
6692 001
6692 002
6692 003
6721 001
6721 002
I want add a autonumber primary key. Is there a way in Access97/Jet
to create an index on job / dwg to allow the drawing field to be
unique for a job? I would like to do it at the table level instead
of the form.
No, not if you want the Dwg number to start over per Job. You could
assign that number in the code event of a form though. I would use
the BeforeUpdate event.
If Me.NewRecord Then
Me.Dwg = Nz(DMax("Dwg", "TableName", "Job = " & Me!Job), 0) + 1
End If
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
That is what I thought, using the Access GUI. I was hoping for a SQL
command that would create the index.
Thank for your reply.
I think you can create the index through DDL, but that's the means of
ensuring data integrity, not how to populate it. So, if the two fields
are the current compound primary key, and you wish those to become a
compound index and add an autonumber field to the table to be primary
key, I think something like the following air code might perhaps be of
assistance
dim db as dao.database
set db = dbengine(0)(0)
db.execute "DROP INDEX PrimaryKey ON table1"
' PrimaryKey - the name of the primary key index
db.execute "ALTER TABLE table1 ADD COLUMN id Counter"
db.execute "CREATE INDEX PrimaryKey ON table1 (id) WITH PRIMARY"
db.execute "CREATE UNIQUE INDEX idxJobDwg ON table1 (Job, Dwg) " & _
"WITH DISALLOW NULL"
set db = nothing
--
Roy-Vidar
to document.
.
- References:
- Unique Index
- From: paii, Ron
- Re: Unique Index
- From: Rick Brandt
- Re: Unique Index
- From: paii, Ron
- Re: Unique Index
- From: RoyVidar
- Unique Index
- Prev by Date: Re: Unique Index
- Next by Date: Re: Deselect all checkboxes by one query
- Previous by thread: Re: Unique Index
- Next by thread: Re: Unique Index
- Index(es):
Relevant Pages
|