Where to place code on a subform

AdamO

Registered User.
Local time
Today, 20:52
Joined
Jun 26, 2002
Messages
40
I have code I place in BeforeUpdate on forms to check for blank and null for what I determine as mandatory fields.

I have a subform which carries a salesid from the main form. I have the default value of salesid on the subform referring to the salesid on the main form. The ID is one entry is completed on the main form first, so I must ensure this happens.

I have tried to place code in various places on the main and subform ie Open, Load, Close, Lost Focus etc. but I cannot get a message to appear before someone clicks a subform field first. Where should the code be placed.

The code would be - or a variation of:

If IsNull(Me.SalesSaleDate) Or Me.SalesSaleDate = "" Then
MsgBox "You MUST enter the service name. This field is mandatory. If you do not complete, your records will not be saved correctly!", vbOKOnly + vbCritical, "Error"
Me.SalesSaleDate.SetFocus
End
End If

Thank you
 
If I've read you correctly then the BeforeInsert event of the subform:

Code:
With Me.Parent
    If IsNull(.SalesSaleDate) Or .SalesSaleDate = vbNullString Then
        MsgBox "You MUST enter the service name. This field is mandatory. If you do not complete, your records will not be saved correctly!", vbOKOnly + vbCritical, "Error"
        Cancel = True
    End If
End With
 

Users who are viewing this thread

Back
Top Bottom