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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InputMask Error 1

Status
Not open for further replies.

debbieg

Technical User
Dec 2, 2002
190
US
I have the following behind my form:
Code:
Dim CurrentControlName As String

Private Sub DateHired_Enter()
    If Len(Me.DateHired & vbNullString) = 0 Then
        Me.DateHired.SelStart = 0
    End If

    'remembers last control user was in while editing
    CurrentControlName = "DateHired"
End Sub

Private Sub SSN_Enter()
    If Len(Me.SSN & vbNullString) = 0 Then
        Me.SSN.SelStart = 0
    End If

    'remembers last control user was in while editing
    CurrentControlName = "SSN"
End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
'    MsgBox DataErr

    Select Case DataErr
        Case 2279   'InputMask violation
            InputMaskMsg
            Response = acDataErrContinue

        Case Else
            'unexpected error.  display default error message
            Response = acDataErrDisplay
    End Select
End Sub
InputMaskMsg is in a Module and is a standard message to be displayed in many forms.

What I would like to do is an undo on the control that is causing the error so the user doesn't have to do anything. But I don't know which control to undo if there are several controls with an InputMask.

Is there a way to use the CurrentControlName that I'm capturing? I tried to use CurrentControlName.Undo but it tells me this is an "Invalid qualifier".

Thanks in advance for any advice.

Debbie
 
And this ?
Me(CurrentControlName).Undo

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you, PHV.

I tried your suggestion and get Run Time Error 2465 can't find the field '' referred to in your expression.

I get the same error when using
Me.Controls(CurrentControlName).Undo

Thanks,
Debbie
 
Why not simply
Screen.ActiveControl.UnDo
or
Screen.PreviousControl.UnDo

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Where are you performing the undo?

If it is within the Form_Error event, I think you shuold be able to use something like:

[tt]me.activecontrol.undo[/tt]

and - PHV's suggestion should also have worked.

If you're performing this in the InputMaskMsg, and it is in a separate module, here's a couple of alternatives:

Declare the CurrentControlName as a public variable in a standard module. Then, after you've assigned a value to it, you should be able to use it as demonstrated by PHV - note - you'll need to prefix with form too:

[tt]forms(strFormName).controls(CurrentControlName).undo[/tt]

Pass the CurrentControlName to the sub

[tt]call InputMaskMsg(CurrentControlName) ' or perhaps
call InputMaskMsg(me.activecontrol.name)[/tt]

You'll need to include the parameter in the sub:

[tt]public sub InputMaskMsg(byval vstrCtlName as String)
' from a standard module - reference through the form
forms(strFormName).controls(vstrCtlName).undo
' from within the forms module
me.controls(vstrCtlName).undo
end sub[/tt]

If it is in a standard module, perhaps also pass the form name (me.name)?

Roy-Vidar
 
Or simpler, pass the control object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yeah, but the simplest/easiest is probably to do it inline;-)

Roy-Vidar
 
Here's what I decided to do:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
'    MsgBox DataErr

    If DataErr = 2279 Then  'InputMask violation
        Response = acDataErrContinue
        Select Case Screen.ActiveControl.Name
            Case "SSN"
                msg1 = "The Social Security No. you entered is invalid!"
                msg2 = "Do you wish to complete it?"
                style = vbYesNo + vbDefaultButton2
                answer = MsgBox(msg1 & vbCrLf & msg2, style, conTitle)
                If answer = vbNo Then
                    Screen.ActiveControl.Undo
                End If
            Case "DateHired"
                msg1 = "The Date Hired you entered is invalid!"
                msg2 = "Do you wish to complete it?"
                style = vbYesNo + vbDefaultButton2
                answer = MsgBox(msg1 & vbCrLf & msg2, style, conTitle)
                If answer = vbNo Then
                    Screen.ActiveControl.Undo
                End If
            Case "DateTerm"
                msg1 = "The Date Terminated you entered is invalid!"
                msg2 = "Do you wish to complete it?"
                style = vbYesNo + vbDefaultButton2
                answer = MsgBox(msg1 & vbCrLf & msg2, style, conTitle)
                If answer = vbNo Then
                    Screen.ActiveControl.Undo
                End If
            Case Else
                msg1 = "An input mask violation occurred in control "
                msg2 = Screen.ActiveControl.Name & "!"
                style = vbCritical
                answer = MsgBox(msg1 & msg2, style, conTitle)
        End Select
    End If
End Sub

Thanks to everyone! I love Tek-Tips!
Debbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top