Question : VBA Excel User Form Input Validation

Hi All,

I am developing a simple forms based application in excel and am having a few problems with user input validation.

My code is working fine when checking for instances of Null but when the user enters a ] \ character, my code crashes with a Type Mismatch error.

Is anyone out here able to help me nail this once and for all?

My current source code for the On_Change event is as follows:

Private Sub RearAislewayDistance_Change()
'Checking to see if user has entered data correctly.
If IsNumeric(Me.RearAislewayDistance) Then
    If Me.RearAislewayDistance = "" Or IsNull(Me.RearAislewayDistance) Then
        MsgBox "Please provide total number of pallets shipped per week.", vbCritical
        Me.RearAislewayDistance.SetFocus
        Me.RearAislewayDistance.BackColor = vbRed
        Me.RearAislewayDistance.ForeColor = &HFFFFFF
        Exit Sub
    Else
        Me.RearAislewayDistance.BackColor = &H6FFFFF
        Me.RearAislewayDistance.ForeColor = &H80000012
        Me.RearAislewayDistance.Value = FormatNumber(Me.RearAislewayDistance, 0)
    End If
End If
End Sub


Answer : VBA Excel User Form Input Validation

Try the Load Optimized Defaults first., If that doesn't work try the other one. Good luck.
Random Solutions  
 
programming4us programming4us