Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am writing some code in an Excel workbook that retrieves data from an
Access database. The SQL for the recordset is generated within the code and is dependant upon two dates to define the period for which I want the data returned Code is thus (simplified) Dim datStartDate as Date Dim datEndDate as Date Dim strSQL as String datStartDate=DateSerial(Year(Date),Month(Date)-1,1) 'First of last month datEndDate=DateSerial(Year(Date),Month(Date),0) 'Last day of last month 'I live in the UK so the date is returned as dd/mm/yyyy, but i need it returned in 'the US format to apply to the SQL string, so datStartDate=Format(datStartDate,"mm/dd/yyyy") datEndDate=Format(datEndDate,"mm/dd/yyyy") strSQL="SELECT SUM(ACTS) AS A FROM STATS WHERE ACT_DATE BETWEEN " _ & "#" & datStartDate & "# AND #" & datEndDate & "#" Should work perfectly? No! datStartDate returns 08/01/2004 (Date in US format) But datEndDate returns 31/08/2004 (Not in US Format) I have tried changing the date on my PC but the end date keeps being returned in UK format and therefore being passed into the SQL string in this manner. This is driving me nuts. Can anyone help. TIA Mark Mark |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
date problem | New Users to Excel | |||
Exel increment date problem wrt todays date. | Excel Worksheet Functions | |||
Date Formula Problem - Leave date blank if Null | Excel Worksheet Functions | |||
DATE PROBLEM | Excel Worksheet Functions | |||
Date problem | Excel Programming |