Hi,
I learned a lot trying to resolve this one, but unfortunately I am still missing something.
I am modifying Contact Management Database template and using Northwind 2007 as a guide/reference. I have added a couple more tables (relevant here is Companies table), did relations, keys, etc. While new to Access, I do have some database experience. I have modified Contacts Extended query to include relevant tables (one right and one left join). Also, I have modified Contact Details form to include new page (or tab) with company information for the contact. Since it is expected to be more than one contact from single company, I have used combo box to allow users to select existing company from the combo box and all other fields will be auto-filled. If entry is not in the list, new form opens and company details can be added.
My problem is that when I select existing company from combo box, fields get filled, other fields manually filled, etc. - and when I try to save, I get a new company entry instead of linking to existing record.
I set the field not to allow duplicates - that helps with consistency, but is not solving the problem as I get an error report stating that no duplicates are allowed. I tried to go around the problem by creating a hidden text box, linked to the foreign key and trying to set the value there (in this case, that is Contacts.CompanyID), but I got the runtime error 3341.
Checking further on this, I realised that query that I am using is creating a new Company record for each form start and CompanyID is automatically assigned next increment value that cannot be changed.
My question is - is it the problem with the query and I need to modify it (or somehow use a different one) or it could be done in some other way?
Query is:
SELECT IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name])) AS [File As], IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name])) AS [Contact Name], Contacts.*, Companies.*, Owners.*
FROM Owners RIGHT JOIN (Contacts LEFT JOIN Companies ON Companies.CompanyID=Contacts.CompanyID) ON Owners.OwnerID=Contacts.[Owner 1]
ORDER BY IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name])), IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name]));
Thanks and regards,
BrankoG
I learned a lot trying to resolve this one, but unfortunately I am still missing something.
I am modifying Contact Management Database template and using Northwind 2007 as a guide/reference. I have added a couple more tables (relevant here is Companies table), did relations, keys, etc. While new to Access, I do have some database experience. I have modified Contacts Extended query to include relevant tables (one right and one left join). Also, I have modified Contact Details form to include new page (or tab) with company information for the contact. Since it is expected to be more than one contact from single company, I have used combo box to allow users to select existing company from the combo box and all other fields will be auto-filled. If entry is not in the list, new form opens and company details can be added.
My problem is that when I select existing company from combo box, fields get filled, other fields manually filled, etc. - and when I try to save, I get a new company entry instead of linking to existing record.
I set the field not to allow duplicates - that helps with consistency, but is not solving the problem as I get an error report stating that no duplicates are allowed. I tried to go around the problem by creating a hidden text box, linked to the foreign key and trying to set the value there (in this case, that is Contacts.CompanyID), but I got the runtime error 3341.
Checking further on this, I realised that query that I am using is creating a new Company record for each form start and CompanyID is automatically assigned next increment value that cannot be changed.
My question is - is it the problem with the query and I need to modify it (or somehow use a different one) or it could be done in some other way?
Query is:
SELECT IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name])) AS [File As], IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name])) AS [Contact Name], Contacts.*, Companies.*, Owners.*
FROM Owners RIGHT JOIN (Contacts LEFT JOIN Companies ON Companies.CompanyID=Contacts.CompanyID) ON Owners.OwnerID=Contacts.[Owner 1]
ORDER BY IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name])), IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[E-mail Address],[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name]));
Thanks and regards,
BrankoG