VBA: Optimización de rutas de distribución
28/12/2023Access: GitHub
30/12/2023
'Código de la creación de los combos. Añadir en un formulario o crear una función
'Combo de años
num = 0
Set comb = Me.cboAno
num = comb.ListCount
'Vaciamos el combo
For i = 1 To num
comb.RemoveItem 0
Next i
strSQL = "SELECT First(Year([Mi_fecha])) AS anofac, Count(Mis_Facturas.[Mi_fecha]) AS Repeticion " & _
"FROM Mis_Facturas " & _
"GROUP BY Year([Mi_fecha]) " & _
"HAVING (((Count(Mis_Facturas.[Mi_fecha]))>=1))"
Set rstTable = CurrentDb.OpenRecordset(strSQL)
Do Until rstTable.EOF
'Rellenamos de nuevo el combo
comb.AddItem rstTable!anofac
rstTable.MoveNext
Loop
Set rstTable = Nothing
Set comb = Nothing
'Combo de trimestres
num = 0
Set comb = Me.cboTrim
num = comb.ListCount
For i = 1 To num
comb.RemoveItem 0
Next i
strSQL = "SELECT First(Format([Mi_fecha],""" & "q" & """)) AS trimestre, Count(Mis_Facturas.[Mi_fecha]) AS Repeticion " & _
"FROM Mis_Facturas " & _
"GROUP BY Format([Mi_fecha],""" & "q" & """) " & _
"HAVING (((Count(Mis_Facturas.[Mi_fecha]))>=1))"
Set rstTable = CurrentDb.OpenRecordset(strSQL)
Do Until rstTable.EOF
comb.AddItem "T" & rstTable!trimestre
rstTable.MoveNext
Loop
Set rstTable = Nothing
Set comb = Nothing
'Combo de meses
Set comb = Me.cboMes
num = comb.ListCount
For i = 1 To num
comb.RemoveItem 0
Next i
strSQL = "SELECT First(monthname(month([Mi_fecha]))) AS mesfac, Count(Mis_Facturas.[Mi_fecha]) AS Repeticion " & _
"FROM Mis_Facturas " & _
"GROUP BY month([Mi_fecha]) " & _
"HAVING (((Count(Mis_Facturas.[Mi_fecha]))>=1))"
Set rstTable = CurrentDb.OpenRecordset(strSQL)
Do Until rstTable.EOF
strItem = rstTable!mesfac
comb.AddItem strItem
rstTable.MoveNext
Loop
Set rstTable = Nothing
Set comb = Nothing