Detecting Symbols in Textbox

  • Thread starter Thread starter Joseph
  • Start date Start date
J

Joseph

Hi,

I have a textbox in which only a 6 digit date in the format DDMMY
should be entered. I've got the code for if it is blank, and if it i
less than or greater than 6 digits in length. All I need now is to b
able to 'listen' for these 'illegal' symbols. Any ideas?

Cheer
 
Joseph,
The following code is for a textbox on a form with a command button...

Option Explicit

Private Sub CommandButton1_Click()
Dim intYear As Integer, intMonth As Integer, intDay As Integer
Dim dteEnteredDate As Date
On Error Resume Next

If Len(TextBox1.Text) = 6 Then
intDay = CInt(Left(TextBox1.Text, 2))
intMonth = CInt(Mid(TextBox1.Text, 3, 2))
intYear = CInt(Right(TextBox1.Text, 2))

If intDay > 0 And intMonth > 0 And intYear > 0 Then
dteEnteredDate = DateSerial(intYear, intMonth, intDay)
MsgBox Format(dteEnteredDate, "dd mmmm, yyyy")
Unload Me
Else
MsgBox "Bad date: " & TextBox1.Text
End If
ElseIf TextBox1.Text <> "False" Then
MsgBox "Date must contain six characters (DDMMYY). You entered: " &
TextBox1.Text
End If
End Sub

Private Sub TextBox1_Change()
Dim i As Integer
For i = 1 To Len(Me.TextBox1.Text)
If Not IsNumeric(Mid(Me.TextBox1.Text, i, 1)) Then
MsgBox "Your last enterd character, """ & Mid(Me.TextBox1.Text,
i, 1) & """, is not a number.", vbExclamation, "Joseph's application"
Me.TextBox1.Text = Left(Me.TextBox1.Text, Len(Me.TextBox1.Text)
- 1)
End If
Next
End Sub

I hope you can use some of it.
Dale Preuss
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top