Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating relationships between tables in vba 1

Status
Not open for further replies.

skinicod

Programmer
Sep 9, 2003
46
0
0
GB
Hello,

I am trying to change various attributes a database using vba. The first of these is the relationships between tables.

I think my code should look something like the following:


Dim rel As Relation

Set rel = currentdb.CreateRelation(???????)


My query therfore is - if I have two tables - "Table1" and "Table2" and I want a relationship between them on multiple fields - how do I do it.

Any help would be gratefully recieved,

Skinicod
 
Here is an example
Code:
    Dim rel As Relation
    
    
    Set rel = CurrentDb.CreateRelation("InvoiceParts", "tblInvoices", "tblParts")
    
    rel.Fields.Append rel.CreateField("InvoiceID")
    rel.Fields("InvoiceID").ForeignName = "InvoiceID"
    
    rel.Fields.Append rel.CreateField("InvoiceNumber")
    rel.Fields("InvoiceNumber").ForeignName = "InvoiceNumber"
    
    CurrentDb.Relations.Append rel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top