Connecting Tech Pros Worldwide Help | Site Map

relations

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 09:56 PM
nicolaas
Guest
 
Posts: n/a
Default relations

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

  #2  
Old November 12th, 2005, 09:56 PM
Allen Browne
Guest
 
Posts: n/a
Default Re: relations

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" <google@ngaru.com> wrote in message
news:28ac5d7.0405032021.24756b12@posting.google.co m...[color=blue]
> 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[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.