auto input to sub form

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Main table (ID, name)
sub table (id, assignee)
link up 2 tables by ID and id

i have created the main and sub forms, if i MANUALLY input "assignee" in
sub table, then ACCESS will create id & ID in both tables to link up
automatically.

i create the following code to auto input the assignee field, i see the auto
input"Unassigned" in the "Form Screen" and i see the new record in the table
but the record has no record id.

is it the difference of input by code and by manually? Could it be solved?
thanks a lot.

******** code ***********
Private Sub Form_BeforeInsert(Cancel As Integer)

Me.FrmOfficer!assignee = "Unassigned"

End Sub
 
Assign the primary key from the main form's table to the foreign key of the
subform's table:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Enter a record in the main form first."
Else
Me.ID = Me.Parent.ID
Me.FrmOfficer!assignee = "Unassigned"
End If
End Sub
 
Thanks Allen

Your method seems more advanced.


Allen Browne said:
Assign the primary key from the main form's table to the foreign key of
the subform's table:

Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Enter a record in the main form first."
Else
Me.ID = Me.Parent.ID
Me.FrmOfficer!assignee = "Unassigned"
End If
End Sub
 
Back
Top