PDA

Click to See Complete Forum and Search --> : Create a primary key


Oct 21st, 2000, 09:47 PM
How can I define a new primary key for my access 97 mdb
from a vb form code?

Oct 23rd, 2000, 10:57 AM
You can do this with SQL via an Execute statement (on your DAO database object or ADO connection object). You do it with either the 'CREATE TABLE' or 'ALTER TABLE' SQL statements using the 'CONSTRAINTS' clause. I suggest that you look up any or all of the above in the MS Access97 help because it's pretty clear there and far too much to write here! The only real trick is that you can name your constraints anything you want - as is illustrated by their examples.

You may need to use either a 'DROP' statement or an 'ALTER TABLE DROP CONSTRAINT' statement to get rid of an already existing PK before adding the new PK.

Good luck,
Paul

Oct 23rd, 2000, 07:18 PM
Thanks Paul!

Patrice Bourdages
Oct 24th, 2000, 11:40 AM
I don't know about doing it on the fly, but at creation, have a look at this posting:

http://forums.vb-world.net/showthread.php?threadid=29119

Look for the last reply.

Oct 24th, 2000, 07:17 PM
Patrice, are codes compatible with access97?

Patrice Bourdages
Oct 30th, 2000, 11:32 AM
Sorry for the delay... Didn't get any warning that a new message was posted...

I guess that it should work as well. I created Access97 and Access2000 MBD whitout a glitch.

Oct 30th, 2000, 09:08 PM
Thanks, I tried it already.