A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Setting PK as not nullable via code



 
 
Thread Tools Display Modes
  #1  
Old March 19th, 2010, 10:08 AM posted to microsoft.public.access
John
external usenet poster
 
Posts: 308
Default Setting PK as not nullable via code

Hi

I need to run through all table in the db and set the primary key in each as
not nullable. How can I achieve this via code?

Many Thanks

Regards


  #2  
Old March 19th, 2010, 10:27 AM posted to microsoft.public.access
Allen Browne
external usenet poster
 
Posts: 11,706
Default Setting PK as not nullable via code

"John" wrote in message
...
I need to run through all table in the db and set the primary key in each
as not nullable. How can I achieve this via code?


No need: if a field is (in) the primary key, it cannot be null.

It is actually possible to set the Required property of the field to Yes
using DAO code if you need to. Refer to:
CurrentDb.TableDefs("MyTable").Fields("MyField").R equired

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

  #3  
Old March 19th, 2010, 06:18 PM posted to microsoft.public.access
David W. Fenton
external usenet poster
 
Posts: 3,373
Default Setting PK as not nullable via code

"Allen Browne" wrote in
:

"John" wrote in message
...
I need to run through all table in the db and set the primary key
in each as not nullable. How can I achieve this via code?


No need: if a field is (in) the primary key, it cannot be null.


In your standard Jet/ACE table created via the Access UI, that is
enforced by the index. I don't know if it's better to also set the
Required property or not. I think the validation rule (or required
property) fires before the check against the index, but I don't know
if that has any impact on performance or locks or anything.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.