473,781 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating relationships using VBA

I'm creating relationships between tables using VBA and ADOX. I can
create one-to-one relationships with an inner join, but I can't figure
out how to create these relationships with an outer join (specifically
a left outer join). I'm including the code that creates the
relationships with the inner join. Any help or suggestions would be
greatly appreciated.

Thanks!

<----- CODE FOLLOWS ----->

Function CreateRelations hip()

Dim catDB As ADOX.Catalog
Dim tbl As ADOX.Table
Dim key As ADOX.key

Dim strForeignTbl As String
Dim strRelName As String
Dim strFTKey As String
Dim strRelatedTbl As String
Dim strRTKey As String

strForeignTbl = "theChildTa ble"
strRelName = "myRelationship "
strFTKey = "foreignTableKe y"
strRelatedTbl = "parentTabl e"
strRTKey = "parentTableKey "

Set catDB = New ADOX.Catalog
catDB.ActiveCon nection = CurrentProject. Connection

Set key = New ADOX.key
With key
.Name = strRelName
.RelatedTable = strRelatedTbl
.Type = adKeyForeign
.Columns.Append strFTKey
.Columns(strFTK ey).RelatedColu mn = strRTKey
End With

Set tbl = New ADOX.Table
Set tbl = catDB.Tables(st rForeignTbl)
tbl.Keys.Append key

Set key = Nothing
Set tbl = Nothing
Set catDB = Nothing

End Function

Nov 13 '05 #1
2 6125
CurrentProject. Connection.Exec ute _
"ALTER TABLE Classes " _
& "ADD CONSTRAINT ClassSchool " _
& "FOREIGN KEY (SchoolID) " _
& "References Schools (SchoolID)"

Gandalf wrote:
I'm creating relationships between tables using VBA and ADOX. I can
create one-to-one relationships with an inner join, but I can't figure
out how to create these relationships with an outer join (specifically
a left outer join).

Nov 13 '05 #2
Gandalf,
I'm with Lyle. I'd write either a CREATE TABLE statement with my
constraints declared in it or an ALTER TABLE statement to change the table
design.
--
Alan Webb
kn*******@SPAMh otmail.com
"It's not IT, it's IS

"Gandalf" <Ga***********@ gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I'm creating relationships between tables using VBA and ADOX. I can
create one-to-one relationships with an inner join, but I can't figure
out how to create these relationships with an outer join (specifically
a left outer join). I'm including the code that creates the
relationships with the inner join. Any help or suggestions would be
greatly appreciated.

Thanks!

<----- CODE FOLLOWS ----->

Function CreateRelations hip()

Dim catDB As ADOX.Catalog
Dim tbl As ADOX.Table
Dim key As ADOX.key

Dim strForeignTbl As String
Dim strRelName As String
Dim strFTKey As String
Dim strRelatedTbl As String
Dim strRTKey As String

strForeignTbl = "theChildTa ble"
strRelName = "myRelationship "
strFTKey = "foreignTableKe y"
strRelatedTbl = "parentTabl e"
strRTKey = "parentTableKey "

Set catDB = New ADOX.Catalog
catDB.ActiveCon nection = CurrentProject. Connection

Set key = New ADOX.key
With key
.Name = strRelName
.RelatedTable = strRelatedTbl
.Type = adKeyForeign
.Columns.Append strFTKey
.Columns(strFTK ey).RelatedColu mn = strRTKey
End With

Set tbl = New ADOX.Table
Set tbl = catDB.Tables(st rForeignTbl)
tbl.Keys.Append key

Set key = Nothing
Set tbl = Nothing
Set catDB = Nothing

End Function

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2227
by: Andrea | last post by:
I'm having some difficulty creating a report in Access and I need some suggestions. My company issues "Return Authorizations" when customers need to return products. A customer calls in and we provide the number. The customer then returns items for a refund or for an exchange. Here is the basic set up of the tables in question. -ReturnAuthorizationTable- ReturnNumber_PK CustomerID ReturnType
8
4329
by: Brian S. Smith | last post by:
Hi gang, Please help. I've been through the Access help, searched the Web, and I can't seem to get a straight answer. As the Subject line suggests, I want to run a fairly simple VB/Access Sub Function/Module that creates relationships for my tables. The problem is that I need to provide for some tables that may have > 32 relationships (which is apparently the limit on Indexes that Access can support). How can I prevent Access from...
3
11734
by: GGerard | last post by:
Hello Does anyone know if it is possible with Access 2000 to create relationships between tables using code? Thanks G.Gerard
4
2028
by: Ronnie | last post by:
Ok let me just say first that I am a newbie in Access and I don't know much of SQL or VB programming. But I am trying to create this contact database using Access 97. I have created 2 tables, one Personal (it has all the personal information) and the other one Organization (this one has details of diff organizations). One person can belong to more than any (upto 5 in this case) organizations. So I included orgid1, orgid2, orgid3, orgid4...
5
4704
by: Mike Turco | last post by:
What is the difference between creating relationships in the front-end vs. the back-end database? I was trying to create a relationship in a database front-end and noticed that I could not check the referential integrity box. What gives? Continuing on with that line of thinking, I understand what do the relationships do for you in a database, but what do they do physically to the tables? Thanks,
4
2545
by: jmarr02s | last post by:
I am using Access 2003 and am having difficulty creating a subform that will save records associated with a particular parent record.... The error message I receive pertains to indexes, relationships, etc... Thanks!
1
1567
by: Kosmos | last post by:
Hi...I'm new but decided to take on learning access programming for my job and I'm having trouble building relations. Any help would be very appreciated! So here's the jist of the program...I have a bunch of fields that I have the program read through and check to see if one number is missing and then reads through the serial numbers which have asset numbers within them but has to remove the characters of A-Z so it can be compared to the...
5
1864
by: Kosmos | last post by:
Hey :) hopefully someone can help me with this...I decided to take on the task of programming an access database for my legal co-op/internship...I'm studying law and music production on the side...most of the background I have in programming has to do with music production... The program I'm creating pulls data from an excel sheet (with defined fields) and brings them into an access database. The data being pulled is the following: ...
10
4456
by: Richard | last post by:
Hi folks, thanks for taking the time to read this (and hopefully point our where I'm going wrong). The scenario: I have a local Access2007 database which links in several read only mySql tables via ODBC. The problem:
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.