By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Create a relationship in code

P: n/a
Hi after adding a field to a table through VBA

How do I create a foreign key constraint/relationship between this
field and a field in another table - and enforce referential integrity
through VBA code.

Thanks
Feb 21 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Thu, 21 Feb 2008 05:25:22 -0800 (PST), Yitzak
<te*********@yahoo.co.ukwrote:

Check out the CreateRelation method in the help file.
-Tom.

>Hi after adding a field to a table through VBA

How do I create a foreign key constraint/relationship between this
field and a field in another table - and enforce referential integrity
through VBA code.

Thanks
Feb 21 '08 #2

P: n/a
See:
http://allenbrowne.com/func-DAO.html#CreateRelationDAO

Shows how to create the relationship and set its properties and attributes,
and the add the fields involved in the relationship. It's all fairly
self-explanatory, provided you understand that CreateField in this context
means "add the field to the relationship", i.e. it is not actually creating
a new field in the table.

There are other ways, such as using CONSTRAINT in a DDL query.

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

"Yitzak" <te*********@yahoo.co.ukwrote in message
news:c9**********************************@28g2000h sw.googlegroups.com...
Hi after adding a field to a table through VBA

How do I create a foreign key constraint/relationship between this
field and a field in another table - and enforce referential integrity
through VBA code.

Thanks
Feb 21 '08 #3

P: n/a
On 21 Feb, 13:47, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
See:
http://allenbrowne.com/func-DAO.html#CreateRelationDAO

Shows how to create the relationship and set its properties and attributes,
and the add the fields involved in the relationship. It's all fairly
self-explanatory, provided you understand that CreateField in this context
means "add the field to the relationship", i.e. it is not actually creating
a new field in the table.

There are other ways, such as using CONSTRAINT in a DDL query.

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

"Yitzak" <terrysha...@yahoo.co.ukwrote in message

news:c9**********************************@28g2000h sw.googlegroups.com...
Hi after adding a field to a table through VBA
How do I create a foreign key constraint/relationship between this
field and a field in another table - and enforce referential integrity
through VBA code.
Thanks
Thanks guys whats this DDL I guess Data Defintion language

link to an access example for DDL?

Feb 21 '08 #4

P: n/a
Here's a DDL example that creates a Contractor table, a Booking table, and
sets a relationship wihht cascade-to-null:
http://allenbrowne.com/func-DDL.html#CreateTableDDL

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

"Yitzak" <te*********@yahoo.co.ukwrote in message
news:57**********************************@p43g2000 hsc.googlegroups.com...
>
Thanks guys whats this DDL I guess Data Defintion language

link to an access example for DDL?
Feb 21 '08 #5

P: n/a
On 21 Feb, 15:49, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Here's a DDL example that creates a Contractor table, a Booking table, and
sets a relationship wihht cascade-to-null:
http://allenbrowne.com/func-DDL.html#CreateTableDDL

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

"Yitzak" <terrysha...@yahoo.co.ukwrote in message

news:57**********************************@p43g2000 hsc.googlegroups.com...
Thanks guys whats this DDL I guess Data Defintion language
link to an access example for DDL?
Thanks Allen - just like MSSQL T-Sql

had no idea you could do this..
Feb 21 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.