{Copying to a new record fields including a combination primary key}
Hi there;
I have a bound subform (Company subform) that's linked to a mainform by a combination 3-field primary key:
DocID
CompanyID
DetailsID
The bound subform has another subform (Details subform) that is not bound to the subform or mainform.
I've made a custom msgbox form with various buttons, one of which will apply/add another Details record to the company in the bound subform.
What I need to have happen is for a new record to be created in the bound Company subform that will:
keep the same CompanyID
keep the same DocID
but replace the default DetailsID (1 for new records) with the currently selected DetailsID in the unbound Details subform.
The problem is that these IDs are part of the pri-key for the bound Company subform. I can't figure out how to apply the new DetailsID to the new subform record on before insert or something. I started playing around with the code below. Any improvements would be extreeeeeemly appreciated.
Thanks.
Eric
Private Sub cmdApplyNewDetail_Click()
DoCmd.Close 'closes custom msgbox window
Forms!MainForm!sfrmCompany.SetFocus
With DoCmd
.RunCommand acCmdSelectRecord
.RunCommand acCmdCopy
.GoToRecord , , acNewRec
.RunCommand acCmdPaste
End With
Forms!MainForm!sfrmCompany.Form!DetailsID = MainForm!sfrmCompany.Form!sfrmDetails.Form!DetailsID.
Hi there;
I have a bound subform (Company subform) that's linked to a mainform by a combination 3-field primary key:
DocID
CompanyID
DetailsID
The bound subform has another subform (Details subform) that is not bound to the subform or mainform.
I've made a custom msgbox form with various buttons, one of which will apply/add another Details record to the company in the bound subform.
What I need to have happen is for a new record to be created in the bound Company subform that will:
keep the same CompanyID
keep the same DocID
but replace the default DetailsID (1 for new records) with the currently selected DetailsID in the unbound Details subform.
The problem is that these IDs are part of the pri-key for the bound Company subform. I can't figure out how to apply the new DetailsID to the new subform record on before insert or something. I started playing around with the code below. Any improvements would be extreeeeeemly appreciated.
Thanks.
Eric
Private Sub cmdApplyNewDetail_Click()
DoCmd.Close 'closes custom msgbox window
Forms!MainForm!sfrmCompany.SetFocus
With DoCmd
.RunCommand acCmdSelectRecord
.RunCommand acCmdCopy
.GoToRecord , , acNewRec
.RunCommand acCmdPaste
End With
Forms!MainForm!sfrmCompany.Form!DetailsID = MainForm!sfrmCompany.Form!sfrmDetails.Form!DetailsID.