Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Userform and Text Box Date

Please help. I have been trying to find a way to mask the date fields in my
userform. (there are many) But can seem to find something that works for
one reason or another. Searching through some forums I found this that I
found would be good and easy but somehow I messed it up. What I want it to
do is when form opens my date fields (testing with textbox64 except my
txtformdate is exempt from this) should be greyed out as mm/dd/yyyy. When
user enters date the date is then changed to black color font. If it is not
a date, then it would displaye Msg Box Data entered is not a date Please try
again. What I have below is not working. Can someone please help. Thank
you in advance.



Private Sub TextBox64_Click(ByVal Cancel As MSForms.ReturnBoolean)
With UserForm2.TextBox64
.Text = ""
.ForeColor = RGB(0, 0, 51)
With UserForm2.TextBox64
If Not IsDate(UserForm2.TextBox64.Text) Then
MsgBox """The Data entered is not a Date""" _
& Chr(10) & " ""Please Try again"""

Exit Sub

End If

End With

End Sub





Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(Date,"mm-dd-yyyy")
With Me.TextBox64
.Text = "dd/mm/yy"
.ForeColor = RGB(204, 204, 204)
.Font.Size = 10
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Userform and Text Box Date

hi,
what version excel are you using? i don't seem to have a click event for
textboxes.
anyway, i edited your code to 3 subs and i "think" it does what you want.
i'm using 03.
Private Sub UserForm_Initialize()
With Me.TextBox1
.Text = "dd/mm/yy"
.ForeColor = RGB(204, 204, 204)
.Font.Size = 10
End With

End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
TextBox1.ForeColor = RGB(0, 0, 51)
End Sub

Private Sub TextBox1_AfterUpdate()

If Not IsDate(TextBox1.Text) Then
MsgBox """The Data entered is not a Date""" _
& Chr(10) & " ""Please Try again"""
TextBox1.Text = ""
TextBox1.SetFocus
Exit Sub
End If

End Sub

works in 03
regards
FSt1

"TotallyConfused" wrote:

Please help. I have been trying to find a way to mask the date fields in my
userform. (there are many) But can seem to find something that works for
one reason or another. Searching through some forums I found this that I
found would be good and easy but somehow I messed it up. What I want it to
do is when form opens my date fields (testing with textbox64 except my
txtformdate is exempt from this) should be greyed out as mm/dd/yyyy. When
user enters date the date is then changed to black color font. If it is not
a date, then it would displaye Msg Box Data entered is not a date Please try
again. What I have below is not working. Can someone please help. Thank
you in advance.



Private Sub TextBox64_Click(ByVal Cancel As MSForms.ReturnBoolean)
With UserForm2.TextBox64
.Text = ""
.ForeColor = RGB(0, 0, 51)
With UserForm2.TextBox64
If Not IsDate(UserForm2.TextBox64.Text) Then
MsgBox """The Data entered is not a Date""" _
& Chr(10) & " ""Please Try again"""

Exit Sub

End If

End With

End Sub





Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(Date,"mm-dd-yyyy")
With Me.TextBox64
.Text = "dd/mm/yy"
.ForeColor = RGB(204, 204, 204)
.Font.Size = 10
End With

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Userform and Text Box Date

Thank you very much this worked! Please one more question. To add this
formatting to other text boxes, do I just add the textboxes name to the subs
below? or do I need to write up individuals sub for each text box that I
want this formatting to apply. Sorry but I am new to code and really trying
to get a grip on this. Thank you.

"FSt1" wrote:

hi,
what version excel are you using? i don't seem to have a click event for
textboxes.
anyway, i edited your code to 3 subs and i "think" it does what you want.
i'm using 03.
Private Sub UserForm_Initialize()
With Me.TextBox1
.Text = "dd/mm/yy"
.ForeColor = RGB(204, 204, 204)
.Font.Size = 10
End With

End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
TextBox1.ForeColor = RGB(0, 0, 51)
End Sub

Private Sub TextBox1_AfterUpdate()

If Not IsDate(TextBox1.Text) Then
MsgBox """The Data entered is not a Date""" _
& Chr(10) & " ""Please Try again"""
TextBox1.Text = ""
TextBox1.SetFocus
Exit Sub
End If

End Sub

works in 03
regards
FSt1

"TotallyConfused" wrote:

Please help. I have been trying to find a way to mask the date fields in my
userform. (there are many) But can seem to find something that works for
one reason or another. Searching through some forums I found this that I
found would be good and easy but somehow I messed it up. What I want it to
do is when form opens my date fields (testing with textbox64 except my
txtformdate is exempt from this) should be greyed out as mm/dd/yyyy. When
user enters date the date is then changed to black color font. If it is not
a date, then it would displaye Msg Box Data entered is not a date Please try
again. What I have below is not working. Can someone please help. Thank
you in advance.



Private Sub TextBox64_Click(ByVal Cancel As MSForms.ReturnBoolean)
With UserForm2.TextBox64
.Text = ""
.ForeColor = RGB(0, 0, 51)
With UserForm2.TextBox64
If Not IsDate(UserForm2.TextBox64.Text) Then
MsgBox """The Data entered is not a Date""" _
& Chr(10) & " ""Please Try again"""

Exit Sub

End If

End With

End Sub





Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(Date,"mm-dd-yyyy")
With Me.TextBox64
.Text = "dd/mm/yy"
.ForeColor = RGB(204, 204, 204)
.Font.Size = 10
End With

End Sub

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
Get a date to display in date format on a UserForm ryguy7272 Excel Programming 12 March 22nd 08 10:31 PM
Userform text box return date value? Matt[_39_] Excel Programming 3 July 28th 06 06:29 PM
UserForm text box Date formatting Dan Excel Programming 2 November 1st 04 04:38 AM
Date in userform being saved as general not date which affects sor Michael Malinsky[_3_] Excel Programming 0 July 28th 04 06:58 PM
Userform to select start date and end date Johnny B. Excel Programming 0 November 28th 03 05:56 PM


All times are GMT +1. The time now is 12:15 AM.

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

About Us

"It's about Microsoft Excel"