S
SHIPP
I have a main form and a subform. I have the following code in the subform:
Private Sub cboItemID_Exit(Cancel As Integer)
On Error GoTo HandleErr
Const cstrProcName As String = "sfrmCustomerItems - cboItemID_Exit"
If IsNull([cboItemID]) Then
Me.Undo
Else
Me.PackSize = DLookup("PackSize", "tblItem", "[ItemID]=" & Me.cboItemID)
Me.Desc = DLookup("Desc", "tblItem", "[ItemID]=" & Me.cboItemID)
Me.ShelfLife = DLookup("ShelfLife", "tblItem", "[ItemID]=" & Me.cboItemID)
If Me.cboItemID <> Me.cboItemID.OldValue Or Nz(Me.FullPalletPrice, 0) =
0 Or Nz(Me.FullLayerPrice, 0) = 0 Then
Me.FullPalletPrice = DLookup("FullPalletPrice", "tblItem", "[ItemID]="
& Me.cboItemID)
Me.FullLayerPrice = DLookup("FullLayerPrice", "tblItem", "[ItemID]=" &
Me.cboItemID)
End If
Me.Dirty = False
End If
ExitHere:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
cstrProcName
End Select
GoTo ExitHere
End Sub
Whenever I go to add a new record to the main form I get the following error
messge:
Error 3201: You cannot add or change a record because a related record is
required in tblItem.
The pencil is visible in the first record of the subform as if I am trying
to enter a record there prior to me creating a main form record. I am
assuming I have the above code in the wrong spot. Any help would be
appreciated.
Private Sub cboItemID_Exit(Cancel As Integer)
On Error GoTo HandleErr
Const cstrProcName As String = "sfrmCustomerItems - cboItemID_Exit"
If IsNull([cboItemID]) Then
Me.Undo
Else
Me.PackSize = DLookup("PackSize", "tblItem", "[ItemID]=" & Me.cboItemID)
Me.Desc = DLookup("Desc", "tblItem", "[ItemID]=" & Me.cboItemID)
Me.ShelfLife = DLookup("ShelfLife", "tblItem", "[ItemID]=" & Me.cboItemID)
If Me.cboItemID <> Me.cboItemID.OldValue Or Nz(Me.FullPalletPrice, 0) =
0 Or Nz(Me.FullLayerPrice, 0) = 0 Then
Me.FullPalletPrice = DLookup("FullPalletPrice", "tblItem", "[ItemID]="
& Me.cboItemID)
Me.FullLayerPrice = DLookup("FullLayerPrice", "tblItem", "[ItemID]=" &
Me.cboItemID)
End If
Me.Dirty = False
End If
ExitHere:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical,
cstrProcName
End Select
GoTo ExitHere
End Sub
Whenever I go to add a new record to the main form I get the following error
messge:
Error 3201: You cannot add or change a record because a related record is
required in tblItem.
The pencil is visible in the first record of the subform as if I am trying
to enter a record there prior to me creating a main form record. I am
assuming I have the above code in the wrong spot. Any help would be
appreciated.