Input mask violation

x18access

Registered User.
Local time
Today, 10:36
Joined
Jan 5, 2014
Messages
14
Hi, i am new to the forums :)

i am having trouble. I am trying to change the standard input mask violation error message to a personalised one.
I have found this code:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const INPUTMASK_VIOLATION = 2279
If DataErr = INPUTMASK_VIOLATION Then
MsgBox "There was an input mask violation in the field no!!"
Response = acDataErrContinue
End If
End Sub

However, i would like to change the message for a number of different text boxes. and i don't know how to isolate each one, and give each one a different message? any help!?
 
Use Me.ActiveControl in order to know what textbox raised the error.
Then use a Select Case statement in order to change the message.

Pseudocode:
Dim TextBoxName as String
TextBoxName = Me.ActiveControl.Name
Select Case TextBoxName
Case "txtBirthDate"
MsgBox("Violation in txtBirthDate")
.......
End Select
 
Something like this:

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 2279 Then 'Data entered does not match InputMask

    If Screen.ActiveControl.Name = "ControlA" Then
     Response = MsgBox("Message for ControlA", vbExclamation, "Input Mask Violation!")
     Response = acDataErrContinue
    End If

    If Screen.ActiveControl.Name = "ControlB" Then
     Response = MsgBox("Message for ControlB", vbExclamation, "Input Mask Violation!")
     Response = acDataErrContinue
    End If

    If Screen.ActiveControl.Name = "ControlC" Then
     Response = MsgBox("Message for ControlC", vbExclamation, "Input Mask Violation!")
     Response = acDataErrContinue
    End If

End If

End Sub
The code could be tightened up, but I prefer keeping things easier to read rather than 'tighter' but more cryptic; makes it easier to follow down the road!

Linq ;0)>
 
i used mihails code to perfect avail! hoorah ! thank you so much :)
 
Glad to help you, but note that missinglinq is a lot more skilled than me.
So, maybe, he has good reasons to use Screen.ActiveControl.
So, take a break until he will inform us about this.
 
The code could be tightened up, but I prefer keeping things easier to read rather than 'tighter' but more cryptic; makes it easier to follow down the road!

You have made similar comments before when posting needlessly clumsy repetititive code.

All code is cryptic to some extent. Arbitrarily eschewing certain structures because you perceive them as more complex is entirely subjective.

I cannot see how your alternative to a what can be done int a couple of lines of code could make it easier to follow. The repetition invites the reader to investigate why each control is dealt with in a separate logical block only to discover there is no reason for the dozens of lines.

Though neither is necessary in this situation, even then the use of multiple If block instead of a Select Case is obfuscating the code. You find Select Case harder to read than multiple If blocks??

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
 
If DataErr = 2279 Then 'Data entered does not match InputMask
    Response = acDataErrContinue
    MsgBox("Message for " & Screen.ActiveControl.Name", vbExclamation, "Input Mask Violation!")
End If
 
End Sub
 

Users who are viewing this thread

Back
Top Bottom