473,714 Members | 2,158 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 10648
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
3366
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
14137
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
2640
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
4551
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
5340
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
38642
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
1223
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
4098
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
3672
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
8814
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
9318
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9079
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
9032
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...
0
7957
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
6638
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
4730
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
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
2528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.