LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Entering a date in a textbox

You're welcome - I'm glad it works for you.

I thought about this again and realised if you have a user that doesn't
know they can omit the /'s they will get double slashes. So I added a
line of code in each routine to avoid this:

If InStr(.Text, "//") Then
.Text = Replace(.Text, "//", "/")
End If

It works in both - see updated procedures below.

HTH,
Gareth

Private Sub TextBox1_Change()

With TextBox1
Select Case Len(.Text)
Case 2, 5
.Text = .Text & "/"
End Select

If InStr(.Text, "//") Then
.Text = Replace(.Text, "//", "/")
End If
End With

End Sub

Private Sub TextBox2_Change()
Dim iPos As Integer
Const myMask As String = "--/--/----"

With TextBox2

If Len(.Text) = 1 Then
.Text = .Text & myMask
Exit Sub
End If

If InStr(.Text, "//") Then
.Text = Replace(.Text, "//", "/")
End If

iPos = InStr(.Text, "-")
If iPos = 0 Then Exit Sub
.Text = Left$(.Text, iPos - 1) _
& Mid(myMask, iPos)

iPos = InStr(.Text, "-")
If iPos = 0 Then Exit Sub
.SelStart = InStr(.Text, "-") - 1

End With

End Sub


johncassell wrote:
Thanks very much for that Gareth, it worked exactly as I'd hoped and
many thanks for replying in the first place.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
condtion for entering date Vijaya Setting up and Configuration of Excel 1 May 14th 09 12:33 PM
In Excel 2003, entering date without slashes, the date is incorre. sj Excel Discussion (Misc queries) 6 January 6th 05 03:07 PM
converting date from a textbox to a date format neowok[_17_] Excel Programming 5 February 23rd 04 01:40 PM
Excel 5.0 entering date Eric G[_2_] Excel Programming 1 January 30th 04 05:14 AM
Selecting or Entering a Textbox Todd Huttenstine[_2_] Excel Programming 2 January 19th 04 06:09 PM


All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"