Hiya

I have a data control that i need to add the validation to. I had aded it to the text boxes that my access database is linked to and code is below.

visual basic
-----------------------------------------------------------------------

Private Sub txtField_Validate(Index As Integer, Cancel As Boolean)
If InStr(txtField(0), " ") Then
MsgBox "No spaces allowed", vbOKOnly, "ISBN No"
Cancel = True
txtField(0).Text = ""
ElseIf Val(txtField(2).Text) > 20 Then
MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
Cancel = True
txtField(2).Text = ""
ElseIf Not IsNumeric(txtField(5).Text) Or InStr(txtField(5), " ") Then
MsgBox "NoInStock must be numberic with no spaces", vbOKOnly, "NoInStock"
txtField(5).Text = ""
Cancel = True
End If
----------------------------------------------------------------------

I have tried to change this to the datacontrol validate event instead and where I have my text box array change to rdatstock.recordset.Category(or which evey field name I need) and to remove the cancel=truw to datstock.recordset.cancelupdate, but I end up with a run time error of:

Runtime errorUpdate or cancelupdate without addnew or edit.

Code I change to as example is:
Visual basic code
----------------------------------------------------------------------
If Val(datStock.Recordset.Category) > 20 Then
MsgBox "Category must be between 1 and 20", vbOKOnly, "Category"
datStock.Recordset.CancelUpdate
'txtField(2).Text = ""
End If
-----------------------------------------------------------------------

I tried adding the datstock.recordset.edit, but did not work, has anyone had trouble with this?

Any help gratefully accepted.....

Thanks

tracey