Hi, i have a form with validation defined by code: the two table fields are not required and the validation is made by setting two respective boolean variables to True or False in the textbox_BeforeUpdate event, in this way:
Private Sub term_BeforeUpdate(Cancel As Integer)
If IsNull(Me.term.Value) = False Then
If Trim(Me.term.Value) <> "" Then
termOk = True
Else
termOk = False
End If
Else
termOk = False
End If
End Sub
Private Sub definition_BeforeUpdate(Cancel As Integer)
If IsNull(Me.definition.Value) = False Then
If Trim(Me.definition.Value) <> "" Then
definitionOk = True
Else
definitionOk = False
End If
Else
definitionOk = False
End If
End Sub
Then, in the BeforeUpdate event of the Form, the code is:
If termBien = False Then
If MsgBox("The field 'Term' is required." + vbCr + "" + vbCr + "¿Cancelling the record editing?", 292, "") = vbYes Then
Me.Undo
termOk = True
Else
DoCmd.CancelEvent
DoCmd.GoToControl "term"
End If
ElseIf definitionBien = False Then
If MsgBox("The field 'Definition' is required." + vbCr + "" + vbCr + "¿Cancelling the record editing?", 292, "") = vbYes Then
Me.Undo
definitionOk = True
Else
DoCmd.CancelEvent
DoCmd.GoToControl "definition"
End If
End if
But if i erase the 'term' content, go to another record, the event BeforeUpdate launch the question, i answer no, and in the blank field term i press Ctrl+Z, the term come back but the BeforeUpdate event of the field doesn't enter and therefore neither the Form_BeforeUpdate event. It's not the problem, because now the fields are Ok, but the value of the boolean termOk stays False, and if in next record i don't fill the Definition field, the error that picks up the Form_BeforeUpdate event is in the field term and not in the field definition.
I have then tried to catch the Ctrl+Z, really the Ctrl key, for setting the variable termOk to true, in this way:
Private Sub term_KeyUp(KeyCode As Integer, Shift As Integer)
'If KeyCode = vbKeyControl Or KeyCode = 17 Then
If IsNull(Me.term.Value) = False Then
If Trim(Me.term.Value) <> "" Then
termOk = True
Else
termOk = False
End If
Else
termOk = False
End If
End If
And the same for the field Definition. But it only works (the Ctrl detection) surprisingly some times.
I have also tried:
Private Sub term_Undo(Cancel As Integer)
If IsNull(Me.term.Value) = False Then
If Trim(Me.term.Value) <> "" Then
termOk = True
Else
termOk = False
End If
Else
termOk = False
End If
End Sub
And again the same for the field Definition. But this event doesn’t enter when Ctrl+Z is pressed.
Any idea for going around that, different of avoiding the Ctrl+Z working?
I would be gratefull for any help given.
Private Sub term_BeforeUpdate(Cancel As Integer)
If IsNull(Me.term.Value) = False Then
If Trim(Me.term.Value) <> "" Then
termOk = True
Else
termOk = False
End If
Else
termOk = False
End If
End Sub
Private Sub definition_BeforeUpdate(Cancel As Integer)
If IsNull(Me.definition.Value) = False Then
If Trim(Me.definition.Value) <> "" Then
definitionOk = True
Else
definitionOk = False
End If
Else
definitionOk = False
End If
End Sub
Then, in the BeforeUpdate event of the Form, the code is:
If termBien = False Then
If MsgBox("The field 'Term' is required." + vbCr + "" + vbCr + "¿Cancelling the record editing?", 292, "") = vbYes Then
Me.Undo
termOk = True
Else
DoCmd.CancelEvent
DoCmd.GoToControl "term"
End If
ElseIf definitionBien = False Then
If MsgBox("The field 'Definition' is required." + vbCr + "" + vbCr + "¿Cancelling the record editing?", 292, "") = vbYes Then
Me.Undo
definitionOk = True
Else
DoCmd.CancelEvent
DoCmd.GoToControl "definition"
End If
End if
But if i erase the 'term' content, go to another record, the event BeforeUpdate launch the question, i answer no, and in the blank field term i press Ctrl+Z, the term come back but the BeforeUpdate event of the field doesn't enter and therefore neither the Form_BeforeUpdate event. It's not the problem, because now the fields are Ok, but the value of the boolean termOk stays False, and if in next record i don't fill the Definition field, the error that picks up the Form_BeforeUpdate event is in the field term and not in the field definition.
I have then tried to catch the Ctrl+Z, really the Ctrl key, for setting the variable termOk to true, in this way:
Private Sub term_KeyUp(KeyCode As Integer, Shift As Integer)
'If KeyCode = vbKeyControl Or KeyCode = 17 Then
If IsNull(Me.term.Value) = False Then
If Trim(Me.term.Value) <> "" Then
termOk = True
Else
termOk = False
End If
Else
termOk = False
End If
End If
And the same for the field Definition. But it only works (the Ctrl detection) surprisingly some times.
I have also tried:
Private Sub term_Undo(Cancel As Integer)
If IsNull(Me.term.Value) = False Then
If Trim(Me.term.Value) <> "" Then
termOk = True
Else
termOk = False
End If
Else
termOk = False
End If
End Sub
And again the same for the field Definition. But this event doesn’t enter when Ctrl+Z is pressed.
Any idea for going around that, different of avoiding the Ctrl+Z working?
I would be gratefull for any help given.