D
dan
I have a couple of tables, Contacts and AssocContacts, as
follows:
"Contacts"
ContactId
Name
Address
telno
etc. ...
"AssocContacts"
ContactId1
ContactId2
The AssocContacts table stores links between contacts, for
example, Dan has a link with Dave. This is obviously
stored using the ContactId's from the Contacts table.
I have set up the relationships - note that I needed to
add the Contacts table in twice in order to create two
links to it from the AssocContacts table. I don't think
that's an issue, though.
Now, I have a master form, frmContacts, which allows you
to edit the main contact details in the Contacts table,
that's fine. I also have an embedded form,
frmAssocContacts, which is meant to allow you to add an
association with the current contact in the frmContacts
form.
On the frmAssocContacts form I have a combo box which
allows the user to select a surname from a list of
contacts. Note that, when pulled down, the combo list
also shows the firstname, address and contact id values.
I also have a couple of visible locked fields which show
the first name and address of the selected contact.
In addition, I have got a couple of other "invisible" text
boxes in order to store the primary key for adding new
records in AssocContacts. the invisible text boxes are
for ContactId1 and ContactId2.
Two problems:
Problem 1:
In the combo-box, I have some code that is executed on the
Surname_Changed event. This code updates the visible
fields to show the address and first name of the contact.
It also sets the value of the invisible text boxes that
store the primary key values for the AssocContacts table.
However, an error occurs when the code tries to set the
primary key value. The code is:
Me.txtAssocConId.Value = Me.txtSurname.Column(7)
And the error is 3341, "The current field must match the
join key 'ContactId' in the table that serves as the 'one'
side of the 'one-to-many' relationship.
When I removed the line in order to debug it, I realised
that Access was trying to update the Contacts and the
AssocContacts tables, when it should only be updating the
AssocContacts table.
The query that the form uses is as follows:
SELECT DISTINCTROW Contacts.Surname, Contacts.FirstName,
Contacts.JobRole, Contacts.AddressLine1,
Contacts.AddressLine2, AssociatedContacts.ContactType,
Contacts.ContactId, AssociatedContacts.ContactId2
FROM Contacts INNER JOIN AssociatedContacts ON
Contacts.ContactId = AssociatedContacts.ContactId2;
I thought I'd be cunning and change the inner join clause
so that it joined AssociatedContacts to Contacts rather
than the other way around, but Access said that it
couldn't support that!
I assume that the problem is something to do with the way
the query joins the tables, but I'm not entirely sure how
to get around it. I just want the form to update the
correct table.
If anyone can help me then I will buy them a large beer,
or drink of their choosing!
Many thanks,
Dan.
follows:
"Contacts"
ContactId
Name
Address
telno
etc. ...
"AssocContacts"
ContactId1
ContactId2
The AssocContacts table stores links between contacts, for
example, Dan has a link with Dave. This is obviously
stored using the ContactId's from the Contacts table.
I have set up the relationships - note that I needed to
add the Contacts table in twice in order to create two
links to it from the AssocContacts table. I don't think
that's an issue, though.
Now, I have a master form, frmContacts, which allows you
to edit the main contact details in the Contacts table,
that's fine. I also have an embedded form,
frmAssocContacts, which is meant to allow you to add an
association with the current contact in the frmContacts
form.
On the frmAssocContacts form I have a combo box which
allows the user to select a surname from a list of
contacts. Note that, when pulled down, the combo list
also shows the firstname, address and contact id values.
I also have a couple of visible locked fields which show
the first name and address of the selected contact.
In addition, I have got a couple of other "invisible" text
boxes in order to store the primary key for adding new
records in AssocContacts. the invisible text boxes are
for ContactId1 and ContactId2.
Two problems:
Problem 1:
In the combo-box, I have some code that is executed on the
Surname_Changed event. This code updates the visible
fields to show the address and first name of the contact.
It also sets the value of the invisible text boxes that
store the primary key values for the AssocContacts table.
However, an error occurs when the code tries to set the
primary key value. The code is:
Me.txtAssocConId.Value = Me.txtSurname.Column(7)
And the error is 3341, "The current field must match the
join key 'ContactId' in the table that serves as the 'one'
side of the 'one-to-many' relationship.
When I removed the line in order to debug it, I realised
that Access was trying to update the Contacts and the
AssocContacts tables, when it should only be updating the
AssocContacts table.
The query that the form uses is as follows:
SELECT DISTINCTROW Contacts.Surname, Contacts.FirstName,
Contacts.JobRole, Contacts.AddressLine1,
Contacts.AddressLine2, AssociatedContacts.ContactType,
Contacts.ContactId, AssociatedContacts.ContactId2
FROM Contacts INNER JOIN AssociatedContacts ON
Contacts.ContactId = AssociatedContacts.ContactId2;
I thought I'd be cunning and change the inner join clause
so that it joined AssociatedContacts to Contacts rather
than the other way around, but Access said that it
couldn't support that!
I assume that the problem is something to do with the way
the query joins the tables, but I'm not entirely sure how
to get around it. I just want the form to update the
correct table.
If anyone can help me then I will buy them a large beer,
or drink of their choosing!
Many thanks,
Dan.