Hi,
I have a query:
SELECT Change_Details.*, Change_Resources.* FROM Change_Resources INNER JOIN Change_Details ON Change_Resources.Change_Number = Change_Details.Change_Number
In the relationships for the db there is a 1(Change_Details) to many (Change_Resources) relationship
If I switch to the datasheet view of this query, I can add the 1st record OK, making sure I fill in the Change_Details.Change_Number only and not the Change_Resources.Change_Number which otherwise would give me an error.
When I go to add a 2nd record with the same number I need to do it the other way round (type the number in the Change_Resources.Change_Number field) otherwise it says I'm violating the primary key. I understand the error as Change_Details.Change_Number has to be unique, but as it is a one to many relationship I thought Access would work it out.
The crux of the problem is the query is used in code and has a "where" on the end which I use to check to see if this change_details/change_resources combo already exist - If not then add the record. The problem is that if the change_details record already exists, but the change_resources doesn't then when updating the record it fails as it is a duplicate.
I can get round this by running another query 1st to check if the parent exists and then decide whether to update Change_Details.Change_Number or instead Change_Resources.Change_Number, but this seems like a fudge and would slow things down.
Hopefully I've explained the problem OK.
Thanks for any help.
Kristian
I have a query:
SELECT Change_Details.*, Change_Resources.* FROM Change_Resources INNER JOIN Change_Details ON Change_Resources.Change_Number = Change_Details.Change_Number
In the relationships for the db there is a 1(Change_Details) to many (Change_Resources) relationship
If I switch to the datasheet view of this query, I can add the 1st record OK, making sure I fill in the Change_Details.Change_Number only and not the Change_Resources.Change_Number which otherwise would give me an error.
When I go to add a 2nd record with the same number I need to do it the other way round (type the number in the Change_Resources.Change_Number field) otherwise it says I'm violating the primary key. I understand the error as Change_Details.Change_Number has to be unique, but as it is a one to many relationship I thought Access would work it out.
The crux of the problem is the query is used in code and has a "where" on the end which I use to check to see if this change_details/change_resources combo already exist - If not then add the record. The problem is that if the change_details record already exists, but the change_resources doesn't then when updating the record it fails as it is a duplicate.
Code:
SQL_Command = "SELECT Change_Resources.*, Change_Details.* " & _
"FROM Change_Resources INNER JOIN Change_Details ON Change_Resources.Change_Number = Change_Details.Change_Number " & _
"WHERE Change_Details.Change_Type = ""RFC"" and Change_Resources.Change_Number = """ & longChange_Number & _
""" and Change_Resources.Sheet_Name = """ & strSheetName & """ and Change_Resources.Role_Type_ID = " & bytRole_Type_ID
Set rstChange_Resources = CurrentDb.OpenRecordset(SQL_Command)
With rstChange_Resources
If .EOF Then
.AddNew
!Change_Type = strChange_Type
![Change_Details.Change_Number] = longChange_Number
!Change_Description = strChange_Folder
!Sheet_Name = strSheetName
!Role_Type_ID = bytRole_Type_ID
Else
.Edit
End If
!Man_Days = singMan_Days
!Resource_Date = dateFul_Date
.Update
.Close
End With
I can get round this by running another query 1st to check if the parent exists and then decide whether to update Change_Details.Change_Number or instead Change_Resources.Change_Number, but this seems like a fudge and would slow things down.
Hopefully I've explained the problem OK.
Thanks for any help.
Kristian