I have a form that calculates and displays inventory of certain items on hand for each day of the week. The procedure is in a do-while loop that calls a function 24 times (with different criteria sent each time) and assigns the value each time to a different unbound field in that form.
Everything is working just fine in means of calculating and asigning everything correctly, but there is an issue with speed! It takes about 2 minutes to load the form and calculate all the values. The function that is called those 24 times contains several Dcount() functions. I'm looking for something to replace those Dcount() functions with something faster.
I found the Tcount module and replaced all Dcount() with Tcount() and not much speed difference, and also got some errors with Tcount(). I'm thinking maybe something along the lines of recordsets. I haven't used them much and dont know all the uses I can do with it but maybe someone here can assist me with doing it. My current code is:
Maybe something like:
dim rs as recordset
set rs = currentDB().openrecordset("[scheduled Dumpsters Local]")
rs.recordcount......
But I dont know how to filter the recordset and then count the number in that filter.
i would need to use the criteria of each of the current Dcount() functions in each .recordcount procedure.
How would i do that, and is using recordsets going to be faster? If not what else can I do to speed up this process?
Everything is working just fine in means of calculating and asigning everything correctly, but there is an issue with speed! It takes about 2 minutes to load the form and calculate all the values. The function that is called those 24 times contains several Dcount() functions. I'm looking for something to replace those Dcount() functions with something faster.
I found the Tcount module and replaced all Dcount() with Tcount() and not much speed difference, and also got some errors with Tcount(). I'm thinking maybe something along the lines of recordsets. I haven't used them much and dont know all the uses I can do with it but maybe someone here can assist me with doing it. My current code is:
Code:
Function SetformState()
Dim i As Integer
Dim n As Integer
Dim a(1 To 12) As String
a(1) = "Monday"
a(2) = "Tuesday"
a(3) = "Wendesday"
a(4) = "Thursday"
a(5) = "Friday"
a(6) = "Saturday"
i = 1
Do While i < 25
Select Case i
Case 1 To 6
Me("text" & i) = Availableboxes("10 yard box", a(i))
i = i + 1
Case 7 To 12
Me("text" & i) = Availableboxes("15 yard box", a(i))
i = i + 1
Case 13 To 18
'i varaible gets out of range for using it in array declare new array value...
n = 1
Me("text" & i) = Availableboxes("20 yard box", a(n))
i = i + 1
n = n + 1
Case 19 To 24
Me("text" & i) = Availableboxes("30 yard box", a(n))
i = i + 1
n = n + 1
End Select
Loop
End Function
Function Availableboxes(Sizelookup, Day As String)
Dim TotalforSize As Integer
Dim Numberout1 As Integer
Dim Numberout2 As Integer
Dim TotalNumberout As Integer
Dim ScheduledforDelivery As Integer
Dim ScheduledforPickup As Integer
Dim Size As String
Dim Str As String
Debug.Print Sizelookup
TotalforSize = DLookup("[quantity]", "[Box Inventory]", "[Size] ='" & Sizelookup & "'")
Debug.Print TotalforSize
Numberout1 = DCount("*", "[Scheduled Dumpsters Local]", "[Delivery Day] = 'past'" _
& "and [Pickup Day] <> 'past'" _
& "and [Size] = 'Concrete Load'" _
& "and InStr(1,[Description], """ & Left(Sizelookup, 2) & """)>0" _
& "or [Size] = 'stumps'" _
& "and InStr(1,[Description], """ & Left(Sizelookup, 2) & """)>0")
Debug.Print Numberout1
Numberout2 = DCount("*", "[Scheduled Dumpsters Local]", "[Delivery Day] = 'past'" _
& "and [Pickup Day] <> 'past'" _
& "and [Size] ='" & Sizelookup & "'")
Debug.Print Numberout2
TotalNumberout = Numberout1 + Numberout2
Debug.Print TotalNumberout
ScheduledforDelivery = DCount("*", "[Scheduled Dumpsters Local]", "[Delivery Day] <> 'Past'" _
& "and [Size] ='" & Sizelookup & "'")
Debug.Print ScheduledforDelivery
ScheduledforPickup = DCount("*", "[scheduled Dumpsters Local]", "[Pickup Day] = '" & Day & "'" _
& "and [Size] ='" & Sizelookup & "'")
Debug.Print ScheduledforPickup
Availableboxes = TotalforSize - TotalNumberout - ScheduledforDelivery + ScheduledforPickup
End Function
Maybe something like:
dim rs as recordset
set rs = currentDB().openrecordset("[scheduled Dumpsters Local]")
rs.recordcount......
But I dont know how to filter the recordset and then count the number in that filter.
i would need to use the criteria of each of the current Dcount() functions in each .recordcount procedure.
How would i do that, and is using recordsets going to be faster? If not what else can I do to speed up this process?