473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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.CreateRelation ("ScheduleHistoryTransactions",
"ScheduleHistory", "Transactions")
2 rel.Attributes = dbRelationUpdateCascade
3 Set fld = rel.CreateField("SID;Schedule")
4 fld.ForeignName = "SID;Schedule"
5 rel.Fields.Append fld
6 dbs.Relations.Append 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 10634
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(strTable 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.Execute 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*********@yahoo.com> wrote in message
news:ea**************************@posting.google.c om...
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.CreateRelation ("ScheduleHistoryTransactions",
"ScheduleHistory", "Transactions")
2 rel.Attributes = dbRelationUpdateCascade
3 Set fld = rel.CreateField("SID;Schedule")
4 fld.ForeignName = "SID;Schedule"
5 rel.Fields.Append fld
6 dbs.Relations.Append 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*******************@news-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.Append fld

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

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

"suzanne shelton" <ch*********@yahoo.com> wrote in message
news:ea**************************@posting.google.c om...
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.CreateRelation ("ScheduleHistoryTransactions",
"ScheduleHistory", "Transactions")
2 rel.Attributes = dbRelationUpdateCascade
3 Set fld = rel.CreateField("SID;Schedule")
4 fld.ForeignName = "SID;Schedule"
5 rel.Fields.Append fld
6 dbs.Relations.Append 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
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...
26
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...
6
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,...
4
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...
4
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...
5
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...
0
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:...
2
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...
11
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)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.