Hi Bob
I'm not sure what you are trying to achieve, so it's difficult to advise
how to fix your code.
However, I can tell you that this line:
If IsNull(Me.subHorseDetailsChild.Form.OwnerID) + (tbName) Then
does not make any sense at all.
I assume OwnerID is a field in the recordsource of a subform named
subHorseDetailsChild, and that tbName is a textbox on the main form,
correct?
IsNull(Me.subHorseDetailsChild.Form.OwnerID) will return True (-1) or
False (0) depending on whether or not OwnerID is null.
The + (tbName) bit will attempt to add that result to the contents of
tbName.
If tbName is numeric then it will do some arithmetic - say OwnerID is
null and tbName is 999, then the result will be -1+999 (=998).
So your If statement will be the same as:
If 998 Then...
Since anything non-zero will be treated as True, this will take the Then
path.
However, if tbName is, say, "Zabeel", then the "addition" will just
result in joining two text strings, so the end result will be:
If "-1Zabeel" Then
Clearly both of these are nonsense!
So, clearly you want to check some combinations of field values for
validity, and undo the changes if they are not OK, but what DOES
constitute a valid record? Post back with some more info please!
Also, it is usual for record validation code to be in Form_BeforeUpdate,
not in the Click event of a command button. What would happen if your
user closed the form some other way, say by clicking the X in the corner?
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Bob said:
Private Sub cmdClose_Click()
If IsNull(Me.subHorseDetailsChild.Form.OwnerID) + (tbName) Then
If Me.Dirty Then
Me.Undo
End If
If IsNull(Me.subHorseDetailsChild.Form.OwnerID) + (cbFatherName) Then
If Me.Dirty Then
Me.Undo
End If
If Me.Dirty Then
Me.Undo
End If
End If
End If
DoCmd.Close acForm, Me.Name
End Sub
Cheers Bob
.........Jenny Vance