Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching the Ctrl+Z in a textbox 1

Status
Not open for further replies.

Bresart

Programmer
Feb 14, 2007
314
ES
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.
 
Howdy Bresart . . .

You say:
Bresart said:
[blue]Hi, i have a form with validation defined by code: [purple]the two table fields are not required[/purple] and ...[/blue]
Then in your forms [blue]Before Update[/blue] event you say:
Bresart said:
[blue]If MsgBox("[purple]The field 'Term' is required[/purple]."
and
("[purple]The field 'Definition' is required.[/purple]" [/blue]
Besides the code itself, all things appear to be ambiguous! [surprise]

Could you explain this without any reference to code ... as if you were just brainstorming!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I think that you can make the code simpler and not have this problem. Instead of code for definition and term, just have code for Before Update, perhaps:

Code:
Sub form_beforeupdate(cancel As Integer)
Dim varGoTo As Variant

varGoTo = Null

If Trim(term & "") = "" Or Trim(definition & "") = "" Then
    If Trim(term & "") = "" Then
        strmsg = "The field 'Term' is required."
        varGoTo = "Term"
    End If

    If Trim(definition & "") = "" Then
        strmsg = strmsg + vbCrLf & "The field 'Definition' is required."
        varGoTo = Nz(varGoTo, "Definition")
    End If

    If MsgBox(strmsg & vbCrLf & vbCrLf & "¿Cancelling the record editing?", 292, "") = vbYes Then
        Me.Undo
    Else
        DoCmd.CancelEvent
        DoCmd.GoToControl varGoTo
    End If
End If
 
Thanks TheAceMan1 Remou.

TheAceMan1, what i need is to put in a boolean if the value of the field is currently valid or invalid (which is set in the Field_BeforeUpdate event), and in the Form_BeforeUpdate event i only check the value of the boolean.

Remou, that works perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top