Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Date formatting in Excel VBA Text Box

Hi all,

I am new to VBA programming so forgive me for an elementary question, but I
can't seem to locate the answer.

I have created a User Form so that a date is entered then that date is
placed in a cell on the Excel spreadsheet. I want to format the Text Box to
only accept a valid date format such ad 01/10/06. How do I do that?

Thanks
TimN
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Date formatting in Excel VBA Text Box

Private Sub TextBox1_Exit()
With TextBox1
If Not IsDate(.Text) Then
MsgBox ("Invalid date")
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End If
End With
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TimN" wrote in message
...
Hi all,

I am new to VBA programming so forgive me for an elementary question, but

I
can't seem to locate the answer.

I have created a User Form so that a date is entered then that date is
placed in a cell on the Excel spreadsheet. I want to format the Text Box

to
only accept a valid date format such ad 01/10/06. How do I do that?

Thanks
TimN



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Date formatting in Excel VBA Text Box

Dnia Thu, 6 Jul 2006 13:31:01 -0700, TimN napisał(a):

Hi all,

I am new to VBA programming so forgive me for an elementary question, but I
can't seem to locate the answer.

I have created a User Form so that a date is entered then that date is
placed in a cell on the Excel spreadsheet. I want to format the Text Box to
only accept a valid date format such ad 01/10/06. How do I do that?


Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim dtTmp As Date
Cancel = False
On Error GoTo err_baddate
dtTmp = CDate(Me.TextBox1.Text)
Me.TextBox1.Text = dtTmp
On Error GoTo 0
sub_ex:
Exit Sub
err_baddate:
MsgBox "Bad date", vbOKOnly + vbExclamation
Cancel = True
Resume sub_ex
End Sub

--
PL
Reply
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
Is it possible to get Excel to stop formatting text as a date? PeteeWJ Excel Discussion (Misc queries) 2 May 12th 08 06:28 PM
Date formatting from text morlo Excel Discussion (Misc queries) 5 October 22nd 07 03:54 PM
Formatting text and date together Brisbane Rob Excel Discussion (Misc queries) 2 December 10th 05 10:00 AM
Date formatting a text box JENNA Excel Programming 3 February 11th 04 09:25 AM
date to text formatting Mark Kubicki Excel Programming 3 October 6th 03 07:16 PM


All times are GMT +1. The time now is 12:14 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"