HI, I am using the following code to limit textboxes to only allow the input of numbers and "/" to accommodate dates. The code then inputs the "/" after every second digit, to provide the following format "xx/xx/xx".
I'm having to apply this to a large number of textboxes, which makes for lots of duplication.
Can anyone suggest a workaround?
I would love to use a date picker instead of the manual textbox entry, however the machines are locked down to the point that I can't import any addins or anything like that. UNless anyone can suggest an alternative, or a way to check a valid date is being entered?
Thanks in advance.
I'm having to apply this to a large number of textboxes, which makes for lots of duplication.
Can anyone suggest a workaround?
I would love to use a date picker instead of the manual textbox entry, however the machines are locked down to the point that I can't import any addins or anything like that. UNless anyone can suggest an alternative, or a way to check a valid date is being entered?
Thanks in advance.
VBA Code:
Private Sub txt4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57, 47
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub txt4_Change()
Dim TextStr As String
With Me.txt4
TextStr = .Text
If (Len(TextStr) = 3 And Mid(TextStr, 3, 1) <> "/") Then
TextStr = Left(TextStr, 2) & "/" & Right(TextStr, 1)
ElseIf (Len(TextStr) = 6 And Mid(TextStr, 6, 1) <> "/") Then
TextStr = Left(TextStr, 5) & "/" & Right(TextStr, 1)
End If
.Text = TextStr
End Sub