LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Dates In UserForm Textboxes

What did you expect from day(0)?

How about a test:
msgbox day(0) & vblf & format(0,"mmmm dd, yyyy")

How about something like:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

Dim StartDate As Date
Dim EndDate As Date

Me.Label1.Caption = ""
If IsDate(Me.TextBox1.Text) = True Then
StartDate = CDate(Me.TextBox1.Text)
EndDate = DateSerial(Year(StartDate), _
Month(StartDate) + 12, Day(StartDate))
Me.TextBox2.Text = Format(EndDate, "dd/mm/yyyy")

Else
Me.Label1.Caption = "Please Enter a date!"
Cancel = True
End If

End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Cancel = True
.TakeFocusOnClick = False
.Caption = "Cancel"
End With

Me.Label1.Caption = ""
End Sub

ps. If you want to remove the possibility of using the wrong date (01/02/03 is
ambiguous), maybe using a calendar control to prompt the user would be better:

See Ron de Bruin's site for more info:
http://www.rondebruin.nl/calendar.htm


johnboy wrote:

Hi all,
I have a userform with two textboxes - one to enter a start date. The other
shows the calculated end date from textbox1 change event.
However, my code is not producing the required result (entered date + 12
months) I would be grateful if some kind person could assist and correct the
problem please.

Private Sub HolStartTextBox_Change()
Dim startdate As Date, enddate As Date
On Error Resume Next
startdate = CDate(HolStartTextBox.Text)
enddate = Year(startdate) & "/" & Month(startdate) + 12 & "/" & Day(0)
If IsDate(startdate) = True Then
HolEndTextBox.Text = Format(enddate, "dd/mm/yyyy")
End If
On Error GoTo 0
End Sub

--
Jon


--

Dave Peterson
 
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
Dates In UserForm Textboxes johnboy Excel Programming 2 June 28th 07 03:58 PM
UserForm TextBoxes Rob Excel Discussion (Misc queries) 2 August 6th 05 03:07 AM
userform & textboxes beginner Excel Programming 3 July 27th 04 10:56 AM
userform textboxes again Jo[_6_] Excel Programming 4 October 21st 03 07:25 PM
userform textboxes Jo[_6_] Excel Programming 4 October 21st 03 07:15 PM


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