Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying to New Record Fields Including Combo 3-Field Primary Key

Status
Not open for further replies.

Accesser

Technical User
Jun 3, 2002
44
0
0
US
{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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top