Hi Mousiefuzz,
My speculation is that you added a frame around the TextBox, and now the Frame is the Active Control.
The following code seemed to work for me with your file:
Private Sub OnlyNumbers()
Dim sTypeName As String
Dim sControlName As String
Dim sValue As String
'Get the TypeName of the Active Control and the Control Name
sTypeName = TypeName(Me.ActiveControl)
sControlName = Me.ActiveControl.Name
'If the TypeName is 'Frame', get the TypeName of the Active Control
'and the Control Name within the Frame
If sTypeName = "Frame" Then
sTypeName = TypeName(ActiveControl.ActiveControl)
sControlName = ActiveControl.ActiveControl.Name
End If
'Test the Control for valid input
If sTypeName = "TextBox" Then
sValue = Me.Controls(sControlName).Value
With Me.ActiveControl
If Not IsNumeric(sValue) And sValue <> vbNullString Then
MsgBox "Sorry, Only numbers allowed"
Me.Controls(sControlName).Value = vbNullString
End If
End With
End If
End Sub
Lewis
Bookmarks