473,657 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple field primary key relationship

Help! I have two tables that i am wishing to join that involve a
multiple field primary key on the primary table.

Primary table: ScheduleHistory
SID *PK
Schedule *PK
Secondary table: Transactions
SID
Schedule
...

When i run the following code, i get an "Invalid field definition
'SID;Schedule' in definition of index or relationship." on line 6.
I am able to manually create this relationship.

1 Set rel = dbs.CreateRelat ion ("ScheduleHisto ryTransactions" ,
"ScheduleHistor y", "Transactio ns")
2 rel.Attributes = dbRelationUpdat eCascade
3 Set fld = rel.CreateField ("SID;Schedule" )
4 fld.ForeignName = "SID;Schedu le"
5 rel.Fields.Appe nd fld
6 dbs.Relations.A ppend rel

This seems pretty straight forward, but i can't for the life of me
figure out what i'm doing wrong. Anyone have any ideas?!?

-s
Nov 12 '05 #1
2 10647
CDB
Alternatively, you could use the SQL approach (within VBA). Here is a proc
from my Fixit module, which accepts composite keys:
Private Sub AddRelation(str Table As String, strRelName As String, _
strForeignKey As String, strForeignTable As String, strForeignField As
String)
'^^^^^^^^^^^^^^ ^^^^^^^^
Dim strSql As String
On Error GoTo procerr
strSql = "ALTER TABLE " & strTable & " ADD CONSTRAINT " & strRelName & _
" FOREIGN KEY (" & strForeignKey & ") REFERENCES " & strForeignTable &
_
" (" & strForeignField & ");"
IniVal.DataDb.E xecute strSql
procexit:
Exit Sub
procerr:
strSql = strSql & "**FAILED** " & vbNewLine & Err.Description
Err.Clear
xdlg cbNote, cbLog, strSql
Resume procexit
End Sub

I use a class module for the common values and objects such as
Inival.DataDb. This points to the back end. "xdlg" is a handler in my
MessageStuff module.

Clive
"suzanne shelton" <ch*********@ya hoo.com> wrote in message
news:ea******** *************** ***@posting.goo gle.com...
Help! I have two tables that i am wishing to join that involve a
multiple field primary key on the primary table.

Primary table: ScheduleHistory
SID *PK
Schedule *PK
Secondary table: Transactions
SID
Schedule
...

When i run the following code, i get an "Invalid field definition
'SID;Schedule' in definition of index or relationship." on line 6.
I am able to manually create this relationship.

1 Set rel = dbs.CreateRelat ion ("ScheduleHisto ryTransactions" ,
"ScheduleHistor y", "Transactio ns")
2 rel.Attributes = dbRelationUpdat eCascade
3 Set fld = rel.CreateField ("SID;Schedule" )
4 fld.ForeignName = "SID;Schedu le"
5 rel.Fields.Appe nd fld
6 dbs.Relations.A ppend rel

This seems pretty straight forward, but i can't for the life of me
figure out what i'm doing wrong. Anyone have any ideas?!?

-s

Nov 12 '05 #2
thanks, allen! worked like charm.
"Allen Browne" <ab************ ***@bigpond.net .au> wrote in message news:<t1******* ************@ne ws-server.bigpond. net.au>...
Suzanne, I think you have to append each field in turn to the Fields of the
Relation.

Set fld = rel.CreateField ("SID")
fld.ForeignName = "SID"
rel.Fields.Appe nd fld

Set fld = rel.CreateField ("Schedule")
fld.ForeignName = "Schedule"
rel.Fields.Appe nd fld

dbs.Relations.A ppend rel
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"suzanne shelton" <ch*********@ya hoo.com> wrote in message
news:ea******** *************** ***@posting.goo gle.com...
Help! I have two tables that i am wishing to join that involve a
multiple field primary key on the primary table.

Primary table: ScheduleHistory
SID *PK
Schedule *PK
Secondary table: Transactions
SID
Schedule
...

When i run the following code, i get an "Invalid field definition
'SID;Schedule' in definition of index or relationship." on line 6.
I am able to manually create this relationship.

1 Set rel = dbs.CreateRelat ion ("ScheduleHisto ryTransactions" ,
"ScheduleHistor y", "Transactio ns")
2 rel.Attributes = dbRelationUpdat eCascade
3 Set fld = rel.CreateField ("SID;Schedule" )
4 fld.ForeignName = "SID;Schedu le"
5 rel.Fields.Appe nd fld
6 dbs.Relations.A ppend rel

This seems pretty straight forward, but i can't for the life of me
figure out what i'm doing wrong. Anyone have any ideas?!?

-s

Nov 12 '05 #3

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

Similar topics

5
3363
by: Bill | last post by:
I have a book cataloge where I have an author id linked up to the book. However, I'm finding that some books have mulitple authors, and I'm wondering if there is a way to add more than one id to the author id field. Or do I have to have many author id fields? Any way around that? Thanks, Bill *** Sent via Developersdex http://www.developersdex.com ***
26
14118
by: pb648174 | last post by:
I have a table called BidItem which has another table called BidAddendum related to it by foreign key. I have another table called BidFolder which is related to both BidItem and BidAddendum, based on a column called RefId and one called Type, i.e. type 1 is a relationship to BidItem and type 2 is a relationship to BidAddendum. Is there any way to specify a foreign key that will allow for the different types indicating which table the...
6
2638
by: Christopher Harrison | last post by:
Is there a way to store an indefinite number of keys in one field and self join them? Imagine, for example, you have a table of users with a "friends" column. Say user 1 is friends with users 9, 7, 24 and 6; then would it be possible to store this array/list/whatever-you-want-to-call-it into user 1's friends cell and extract the join in a query, some how? An easy and obvious way, that is; I can think of string processing hacks ;) Thanks...
4
4545
by: Erik Thorsen | last post by:
I need help with a tricky questions which I belive have a simple solution? For those who know Nwind.mdb, the example database that comes with microsoft access, it has several different tables. One of them is categories. What I need to do is somehow make it possible for a product to be listed in several categories. However, I do not know how to do this. Does anyone have a clue??? Any help is appreciated!
4
5337
by: Abbey Krystowiak | last post by:
Does anyone know if I can have a field in a row where I can add two lines of info without adding a whole new line? and then there would be a drop down menu? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
5
38630
by: Sami | last post by:
I can create queries and reports based on info from one table. How do I create one using information from multiple tables. What do I need to make sure the information from one table will be correctly assigned to specific person from another table? Thanks.
0
1220
by: Andrew W | last post by:
I am trying to set up a relationship between three fields that make the primary key of two tables. I am able to do this thru the Access Relationships utility, but not thru VBA. I get the message: 'No unique index found for the referenced field of the primary table". I've checked the dataype and length of each of the three text fields that make the primary key. It seems like Access is trying to make one part of the relationship at a time....
2
4092
by: SteveMPullen | last post by:
I have an Access DB with 5 tables. 3 of the tables have a primary key with a field of "Project Name". I have created a form to add a new "Project Name" to the 3 tables. When I add the new "Project Name" the 1st table gets updated but the 2nd and 3rd tables do not get the update. 1st table has 1 field: Project Name - primary key 2nd table has 30 fields: Project Name - primary key 3rd table has 24 fields: Project Name - primary key I...
11
3665
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night) and the 'employee name'. There is another table which assigns an ID to the Shifts, i.e. 1,2 and 3 for morn, eve & night shifts respectively. From the mother table, the incentive is calculated datewise for each employee as per his shift duty. In...
0
8420
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
8740
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...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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
2743
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
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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.