Hi!
I have this code in an Access 2000 database working on WXp and W7 machines:
Code:
Function CalcoloPresenze()
Dim rst As Recordset
Dim sqlQuery, parametro As String
Dim Giorno As Integer
Dim TotaleGiorni As Integer
Dim Presenze As Integer
Dim InizioPeriodo As Date
Dim FinePeriodo As Date
Dim Data As Date
InizioPeriodo = Format(Forms!frmProgressoCalcoloPresenze!Calendario_DataInizio, "mm/dd/yyyy")
FinePeriodo = Format(Forms!frmProgressoCalcoloPresenze!Calendario_DataFine, "mm/dd/yyyy")
If InizioPeriodo <= FinePeriodo Then
TotaleGiorni = FinePeriodo - InizioPeriodo + 1
SysCmd acSysCmdInitMeter, "Calcolo Presenze: ", TotaleGiorni
Else
MsgBox "Il periodo selezionato non è valido.", vbCritical + vbOKOnly
Exit Function
End If
Data = Format(InizioPeriodo, "mm/dd/yyyy")
Presenze = 0
For Giorno = 0 To TotaleGiorni - 1
Data = Format(DateAdd("d", Giorno, Format(InizioPeriodo, "mm/dd/yyyy")), "mm/dd/yyyy")
sqlQuery = "SELECT DISTINCT Count(Clienti.Cittadinanza) AS Presenti " + _
"FROM Clienti INNER JOIN Soggiorni ON Clienti.IdCliente = Soggiorni.CodCliente " + _
"WHERE (((Soggiorni.Arrivo)<#" & Format(Data, "mm/dd/yyyy") & "#) AND ((Soggiorni.Partenza)>#" & Format(Data, "mm/dd/yyyy") & "#) AND ((Soggiorni.Presente)=True)) " + _
"OR (((Soggiorni.Arrivo)<#" & Format(Data, "mm/dd/yyyy") & "#) AND ((Soggiorni.Partenza) Is Null) AND ((Soggiorni.Presente)=True)) " + _
"OR (((Soggiorni.Arrivo)=#" & Format(Data, "mm/dd/yyyy") & "#) AND ((Soggiorni.Partenza)>#" & Format(Data, "mm/dd/yyyy") & "#) AND ((Soggiorni.Presente)=True)) " + _
"OR (((Soggiorni.Arrivo)=#" & Format(Data, "mm/dd/yyyy") & "#) AND ((Soggiorni.Partenza) Is Null) AND ((Soggiorni.Presente)=True));"
Set rst = CurrentDb.OpenRecordset(sqlQuery, dbOpenSnapshot)
Presenze = Presenze + rst.Fields("Presenti").Value
SysCmd acSysCmdUpdateMeter, Giorno
rst.Close
Set rst = Nothing
Next Giorno
MsgBox "Il totale delle presenze del periodo è " & Presenze, vbInformation, "Totale presenze del periodo"
SysCmd acSysCmdRemoveMeter
DoCmd.Close acForm, "frmProgressoCalcoloPresenze"
End Function
The code is launched from a Form (frmProgressoCalcoloPresenze) containing two Calendar controls (Calendario_DataInizio and Calendario_DataFine).
The problem is that when cycling through the dates all goes well while the date's month is <= 12, then it switches to the italian format (dd/mm/yyyy), even if I forced the use of the english format (mm/dd/yyyy) in every step.
E.g.:
Cycle from 07/01/2010 to 07/31/2010
The dateadd() function generates the following values:
07/01/2010
07/02/2010
07/03/2010
07/04..10/2010
07/11/2010
07/12/2010
13/07/2010 !!!!!!!!!!!!
14/07/2010... and so on...
Which, obviously, returns wrong data.
Any help?
Thank you very much in advance!!!
Marco