DS said:
Allen said:
In the BeforeInsert event of the form, use DMax() to get the highest
value so far entered for the foreign key.
This example assumes a main form where you enter your CD albums, and a
subform where you enter the tracks. A soon as you start adding a track
name, it fills in the next available TrackId for the album in the main
form:
Private Sub Form_BeforeInsert(Cancel As Integer)
With Me.Parent.AlbumId
If IsNull(.Value) Then
Cancel = True
MsgBox "Enter the main for record first."
Else
Me.[TrackId] = Nz(DMax("TrackId", "tblAlbum", "AlbumId = " &
.Value),0) + 1
End If
End With
End Sub
Thanks Allen. I'm trying it now.
DS
Allen, this works fine except I need to attach it elsewhere. I have one
Sub-Form "SalesDetails". I have 2 Listboxes. When you click Listbox1 I
want to increase the ID number, when you click Listbox2 I want to copy it
to the next record. I would imagine I would have to put it on the "On
Click" property of the Listboxes, but how would I reference it?
Thank You
Sincerely
DS