Salve a tutti.
Sto creando un programmino ke scarica i valori (in un mese definito dall utente) presenti in un database e li divide per settimane in un foglio excel.
Il programma funziona correttamente in questo modo:
w1_date_start = FormatDateForDB(ReportForm.DataTxtBx.Value) & "01"
w1_date_end = FormatDateForDB(ReportForm.DataTxtBx.Value) & "07"
w2_date_start = FormatDateForDB(ReportForm.DataTxtBx.Value) & "08"
w2_date_end = FormatDateForDB(ReportForm.DataTxtBx.Value) & "15"
w3_date_start = FormatDateForDB(ReportForm.DataTxtBx.Value) & "16"
w3_date_end = FormatDateForDB(ReportForm.DataTxtBx.Value) & "23"
w4_date_start = FormatDateForDB(ReportForm.DataTxtBx.Value) & "24"
w4_date_end = FormatDateForDB(ReportForm.DataTxtBx.Value) & "31"
' week 1
sql = "SELECT w1.wonum FROM wostatus w1, wostatus w2 WHERE (w1.wonum = w2.wonum and w1.status = 'WSCHED' and w2.status = 'CLOSE' and w1.changedate >='" _
& w1_date_start & "' and w1.changedate <= '" & w1_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O16") = recordSet.RecordCount
recordSet.Close
sql = "SELECT wonum FROM wostatus WHERE (status = 'WSCHED' and changedate >='" _
& w1_date_start & "' and changedate <= '" & w1_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O17") = recordSet.RecordCount
recordSet.Close
'week 2
sql = "SELECT w1.wonum FROM wostatus w1, wostatus w2 WHERE (w1.wonum = w2.wonum and w1.status = 'WSCHED' and w2.status = 'CLOSE' and w1.changedate >='" _
& w2_date_start & "' and w1.changedate <= '" & w2_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O20") = recordSet.RecordCount
recordSet.Close
sql = "SELECT wonum FROM wostatus WHERE (status = 'WSCHED' and changedate >='" _
& w2_date_start & "' and changedate <= '" & w2_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O21") = recordSet.RecordCount
recordSet.Close
'week 3
sql = "SELECT w1.wonum FROM wostatus w1, wostatus w2 WHERE (w1.wonum = w2.wonum and w1.status = 'WSCHED' and w2.status = 'CLOSE' and w1.changedate >='" _
& w3_date_start & "' and w1.changedate <= '" & w3_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O24") = recordSet.RecordCount
recordSet.Close
sql = "SELECT wonum FROM wostatus WHERE (status = 'WSCHED' and changedate >='" _
& w3_date_start & "' and changedate <= '" & w3_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O25") = recordSet.RecordCount
recordSet.Close
'week 4
sql = "SELECT w1.wonum FROM wostatus w1, wostatus w2 WHERE (w1.wonum = w2.wonum and w1.status = 'WSCHED' and w2.status = 'CLOSE' and w1.changedate >='" _
& w4_date_start & "' and w1.changedate <= '" & w4_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O28") = recordSet.RecordCount
recordSet.Close
sql = "SELECT wonum FROM wostatus WHERE (status = 'WSCHED' and changedate >='" _
& w4_date_start & "' and changedate <= '" & w4_date_end & "')"
recordSet.Open sql, ConnStr
recordSet.ActiveConnection = Nothing
ReportBook_Sheet.Range("O29") = recordSet.RecordCount
recordSet.Close
Adesso... come faccio a impostare che al posto di "01" come giorno di inizio ci sia il primo mercoledi del mese impostato dall utente e al posto di "07" ci sia il martedi della settimana successiva?
Vorrei anche aggiungere la possibilta' che nel caso il mese non finisca di un martedi, il programma andrebbe a cercare il primo martedi del mese successivo.
Spero di essere stato abbastanza chiaro.
Un ringraziamento a chi mi sapra' aiutare.

Rispondi quotando