Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 -- Josep ----------------------------------------------------------------------- Joseph's Profile: http://www.excelforum.com/member.php...nfo&userid=563 View this thread: http://www.excelforum.com/showthread.php?threadid=27811 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "Joseph" wrote: Hi, I have a textbox in which only a 6 digit date in the format DDMMYY should be entered. I've got the code for if it is blank, and if it is less than or greater than 6 digits in length. All I need now is to be able to 'listen' for these 'illegal' symbols. Any ideas? Cheers -- Joseph ------------------------------------------------------------------------ Joseph's Profile: http://www.excelforum.com/member.php...fo&userid=5637 View this thread: http://www.excelforum.com/showthread...hreadid=278119 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Symbols on the keyboard are not the symbols on the screen.... | Excel Discussion (Misc queries) | |||
Textbox Bug? Missing/delayed update of textbox filled via VBA | Excel Programming | |||
Textbox Bug? Missing/delayed update of textbox filled via VBA | Excel Programming | |||
How to move cursor from one textbox control to another textbox con | Excel Programming | |||
How to move cursor from one textbox control to another textbox con | Excel Programming |