Error 3201

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.
 
J

Jeanette Cunningham

Shipp,
move the validation code to the Before Update event of the main form.
Remove the line
Me.Dirty = false
It is not needed here and is probably causing the error message.

With a main form subform setup using link master and child fields,
the main form record is automatically saved when you go to the subform.

The line Me.Dirty = False can be changed to
If Me.Dirty = True Then
Me.Dirty = False
End If

Those 3 lines go on the close button for the main form.

Jeanette Cunnningham
 

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