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: 11
Default calling a subroutine to format date(s)


How to complete this sub line to include datInitDate.

Private Sub datInitDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Dt, Dt2 As Date

I want to pass the value datInitDate--it is coming up as "" (empty) in the
2nd sub below. Also, the Format method is defined as setting values as String
types; the XLS spreadsheet allows me to format cells as date (dd-MMM-yyyy)
but I'm not succeeding in doing this with VBA in the form's code.

When F8-ing thru the code, I'm getting values in the Dim statement (on mouse
over) showing Dt as empty and results of Dt2 as 12:00:00 AM. And very strange
offset dates. If I include dtInitDate in the dim statment, it is empty, too.
Why is Dt showing up as empty in the Dim, but Dt2 has a time value?


Here's the code for the two subroutines:

Private Sub UserForm_Initialize() ' Initialize the form (prefill certain
fields)
Dim datInitDate As Date
Dim datComplDate As Date

datInitDate = Date$
datComplDate = DateAdd("d", 90, datInitDate)
txtRequestor.Value = Environ("username") 'autofills with user's login ID

End Sub

' Check the value of the Initialization Date and calculate ComplDate 90 days
later
Private Sub datInitDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Dt, Dt2 As Date
On Error Resume Next
Dt = datInitDate
If Dt DateSerial(1950, 1, 1) Then
datInitDate = Format$(Dt, "dd-mmm-yyyy")
Dt2 = DateAdd("m", 3, datInitDate)
datComplDate = Format$(Dt2, "dd-mmm-yyyy")
Else
datInitDate = InputBox("Please use a valid format for date this
corrective action was reported (fmm-dd-yyyy).")
End If
End Sub

Also, the Format statement sets variables as STRING values.

This is all for a form. Inside the spreadsheet, I can call the format as
10-Jan-2005, but even setting the custom format for Dt and Dt2 as dd-mmm-yyy,
I still get 01/10/2005
 
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
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
Calling a function from a subroutine loop Dan Excel Programming 1 November 27th 04 01:28 AM
calling a subroutine outside a spreadsheet dino Excel Programming 5 June 11th 04 06:14 PM
Function Calling Subroutine Curare Excel Programming 1 February 24th 04 07:11 PM
Calling the Solver via a subroutine James[_8_] Excel Programming 1 July 10th 03 01:08 AM


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