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

relations

P: n/a
Hi everyone

Is there someone out there who can tell me how to create relationships
between tables using VB???
PS I am using MS ACCESS 2003 and I have read the help...
THANK YOU
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This example assumes a main table named "tblContractor" with primary key
"ContractorID", and a related table "tblBooking" with a foreign key named
"ContractorID". The result is that one contractor can have many bookings.

Sub CreateRelationDAO()
Dim db As DAO.Database
Dim rel As DAO.Relation
Dim fld As DAO.Field

'Initialize
Set db = CurrentDb()

'Create a new relation.
Set rel = db.CreateRelation("tblContractortblBooking")

'Define its properties.
With rel
'Specify the primary table.
.Table = "tblContractor"
'Specify the related table.
.ForeignTable = "tblBooking"
'Specify attributes for cascading updates and deletes.
.Attributes = dbRelationUpdateCascade + dbRelationDeleteCascade

'Add the fields to the relation.
'Field name in primary table.
Set fld = .CreateField("ContractorID")
'Field name in related table.
fld.ForeignName = "ContractorID"
'Append the field.
.Fields.Append fld

'Repeat for other fields if a multi-field relation.

End With

'Save the newly defined relation to the Relations collection.
db.Relations.Append rel

'Clean up
Set fld = Nothing
Set rel = Nothing
Set db = Nothing
Debug.Print "Relation created."
End Sub

--
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.
"nicolaas" <go****@ngaru.com> wrote in message
news:28*************************@posting.google.co m...
Hi everyone

Is there someone out there who can tell me how to create relationships
between tables using VB???
PS I am using MS ACCESS 2003 and I have read the help...
THANK YOU

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.