Validating data

  • Thread starter Thread starter Heidi
  • Start date Start date
H

Heidi

I have a subform in which data entry persons can edit
previously entered data. In the OnClose Property of this
subform, I want do make some data validations. For
example, if the data entry person made ReportType = P and
didn't fill a weight in the "Wt" field, a message box
would pop up asking them to fill in a weight for a
positive report. Then I want the subform to not close,
but set the focus on the field "Wt." This is the code I
used:

If Me.RptType = "P" And IsNull(Me.Wt) Then
MsgBox "You must enter weight.", vbOKOnly
Cancel = True
Me.Wt.SetFocus
End If

However, when the user hits the "OK" button, the subform
closes anyway and pops the user back to the main form.
What am I doing wrong???
 
In the OnClose Property of this
subform, I want do make some data validations.

It's usual to use the Form_BeforeUpdate event for this. If it's used as a
subform control, you need to do this in the module design for the form that
you are using as a subform IYSWIM.


All the best


Tim F
 
Back
Top