Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Call a subroutine using variable subroutine name | Excel Discussion (Misc queries) | |||
Calling a function from a subroutine loop | Excel Programming | |||
calling a subroutine outside a spreadsheet | Excel Programming | |||
Function Calling Subroutine | Excel Programming | |||
Calling the Solver via a subroutine | Excel Programming |