zelarra821
Registered User.
- Local time
- Today, 19:49
- Joined
- Jan 14, 2019
- Messages
- 847
Good afternoon.
I have a form where I show a graph based on the year that I select in a drop-down, and my problem is that it takes half a life to load, and it hangs for a while thinking.
This is the event in the form:
As you can see, there are three custom functions, and one of them is the one that gives me problems (PercentajeEstacionYear).
I've read more posts on this forum, and you recommend using Recordset (I use it). They also recommended me once for something totally different to use the Where clause to filter the data, because, if you have 1000 records, with a Where you only load the 100 you want to use, and not the 1000 (I also use that). I have simplified the recordset to the maximum, and neither.
Here is the custom function (there is one, but you need two more for the calculation):
And it is not a problem of the number of records because, although the table stores 1135 records, then for each year there are between 200-300 records no more, and I filter so that it uses only those 200-300 records.
Can anyone advise me something?
Thank you!
I have a form where I show a graph based on the year that I select in a drop-down, and my problem is that it takes half a life to load, and it hangs for a while thinking.
This is the event in the form:
Code:
Private Sub Año1_AfterUpdate()
Dim Año As String
Año = Me.Año2
Me.Grafica.RowSource = "SELECT EstacionAñoYResultado([Fecha],[Resultado]) AS Estacion, PorcentajeEstacionAño([Fecha],[Resultado]) AS PorcentajeEstacionAño" _
& " FROM TResultados INNER JOIN TServicio ON TResultados.CodigoResultado = TServicio.CodigoResultado" _
& " WHERE Year([Fecha]) = " & Año & "" _
& " GROUP BY EstacionAñoYResultado([Fecha],[Resultado]), PorcentajeEstacionAño([Fecha],[Resultado]), Year([Fecha]), OrdenEstacion([Fecha]), TResultados.CodigoResultado" _
& " ORDER BY Year([Fecha]), OrdenEstacion([Fecha]), TResultados.CodigoResultado"
End Sub
As you can see, there are three custom functions, and one of them is the one that gives me problems (PercentajeEstacionYear).
I've read more posts on this forum, and you recommend using Recordset (I use it). They also recommended me once for something totally different to use the Where clause to filter the data, because, if you have 1000 records, with a Where you only load the 100 you want to use, and not the 1000 (I also use that). I have simplified the recordset to the maximum, and neither.
Here is the custom function (there is one, but you need two more for the calculation):
Code:
Public Function PorcentajeEstacionAño(Fecha As Date, miResultado As String) As Double
PorcentajeEstacionAño = VecesResultado(Fecha, miResultado) / VecesPeriodo(Fecha)
End Function
Public Function VecesPeriodo(Fecha As Date) As Double
Dim rst As DAO.Recordset
Dim strVecesPeriodo As String
strVecesPeriodo = "SELECT Count(TResultados.Resultado) AS VecesPeriodo" _
& " FROM TResultados INNER JOIN TServicio ON TResultados.CodigoResultado = TServicio.CodigoResultado" _
& " WHERE (((EstacionYAño([Fecha]))='" & EstacionYAño(Fecha) & "'))"
Set rst = CurrentDb.OpenRecordset(strVecesPeriodo)
If Not (rst.EOF And rst.BOF) Then
VecesPeriodo = rst("VecesPeriodo")
End If
rst.Close
Set rst = Nothing
End Function
Public Function VecesResultado(Fecha As Date, miResultado As String) As Double
Dim rst As DAO.Recordset
Dim strVecesResultado As String
strVecesResultado = "SELECT Count(TResultados.Resultado) AS VecesResultado" _
& " FROM TResultados INNER JOIN TServicio ON TResultados.CodigoResultado = TServicio.CodigoResultado" _
& " WHERE (((EstacionYAño([Fecha]))='" & EstacionYAño(Fecha) & "')) And Resultado ='" & miResultado & "'"
Set rst = CurrentDb.OpenRecordset(strVecesResultado)
If Not (rst.EOF And rst.BOF) Then
VecesResultado = rst("VecesResultado")
End If
rst.Close
Set rst = Nothing
End Function
And it is not a problem of the number of records because, although the table stores 1135 records, then for each year there are between 200-300 records no more, and I filter so that it uses only those 200-300 records.
Can anyone advise me something?
Thank you!