How do I link a new record to a record on the child table?

P

Peter Stone

I have an unbound Combo Box (cboDestination) on the header of my form
(txtForm).

The combo selects destinations from a Child table (tblDestinations):

SELECT tblDestinations.DestinationsID, tblDestinations.Destination,
tblDestinations.DestinationType, tblDestinations.Publish FROM tblDestinations
ORDER BY tblDestinations.Destination;

On the After Upate property is the following event procedure that goes to
the first record for the selected destination:

Private Sub cboDestination_AfterUpdate()
Me.lstSelectRecord.Requery
Me.RecordsetClone.FindFirst _
"[DestinationsID] = " & Me![cboDestination]
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

On a page of the form there is an unbound list box (lstSelectRecord) that
displays all the record headings of the selected group plus Progress and
PublicationStatus:

SELECT tblText.TextID, tblText.DestinationsID, tblText.Heading,
tblProgress.ProgressText, tblPublicationStatus.PublicationStatusText FROM
tblProgress INNER JOIN (tblPublicationStatus INNER JOIN tblText ON
tblPublicationStatus.PublicationStatus=tblText.PublicationStatus) ON
tblProgress.Progress=tblText.Progress WHERE
(((tblText.DestinationsID)=Forms!frmText!cboDestination) And
((tblText!PublicationStatus)=tblPublicationStatus!PublicationStatus) And
((tblText!Progress)=tblProgress!Progress));

All this seems to work fine.

I have a label (lblSelectNewRecord) that a user double clicks to .....

Private Sub lblSelectNewRecord_DblClick(Cancel As Integer)
DoCmd.GoToRecord , , acNewRec
End Sub

which it does, but when I try to modify and save that new record I get the
following message:

You cannot add or change a record because a related record is required in
table 'tblDestinations'

How do I link the new record to the record of the Destination that's
displayed in the Comco Box: cboDestination?

Help please

Peter
 
S

Sandra Daigle

Using the DblClick event you need to assign the selected value to the
DestinationsID control:

me.DestinationsID=me.cboDestination
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top