M
Marc
I am using Access to manipulate data that is stored in Visual FoxPro
(don't ask and I can't change this) free tables. Basically, it's a
recipe table that can have multiple recursive levels of ingredients
(i.e. Salad Mix contains Chopped Lettuce Mix, which contains Lettuce).
I have successfully programmed VBA functions to recursively seek out
the lowest level ingredient (one for which there is no recipe).
However, it is SLOW SLOW SLOW, and I was hoping for some advice with
regards to speeding it up. The passthrough database has over 5000
records in it.
qryARRECP01 is the passthrough recipe file. There are three custom
functions that call to Passthrough Queries -- getrawcode, getrawqty,
getrawwieght -- which obtain the ultimate raw ingredient, the amount of
this ingredient required and the resulting ingredient remaining after
processing (to calculate yield).
Following is the SQL code for the query:
SELECT qryARRECP01.recipe, qryARRECP01.item,
getrawcode([qryARRECP01]![item]) AS rawingred,
getrawqty([qryarrecp01]![item],[qryarrecp01]![recipe]) AS qty,
getrawweight([qryarrecp01]![recipe],[qryarrecp01]![item],[rawingred])
AS weight, [weight]/[qty] AS yield
FROM qryARRECP01 INNER JOIN qryARINVT01 ON qryARRECP01.recipe =
qryARINVT01.item
WHERE (((qryARRECP01.item) Not In ("LABOR","PACKPO","PACK")))
ORDER BY qryARRECP01.recipe, qryARRECP01.item;
I will include the code for just getrawcode, because the other three
queries are fairly similar (though getrawweight is even slower because
it searches two passthrough queries.
Function GetRawCode(ByVal ingrcheck As String) As String
Dim db As Database
Dim rs As DAO.Recordset
'Open Recipe Query
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryARRECP01", dbOpenDynaset, dbReadOnly)
If (Not rs.EOF) Then
'Call recursive function to locate raw ingredient
GetRawCode = FindRawIngred(ingrcheck, rs)
End If
rs.Close 'Close Table
Set db = Nothing 'Clear reference to database
End Function
Function FindRawIngred(ByVal ingrcheck As String, rs As DAO.Recordset)
As String
Dim sSQL As String
sSQL = "[recipe] = """ & ingrcheck & """"
rs.FindFirst sSQL 'Search recordset for matching item code
If rs.NoMatch Then 'When item code is not found (e.g.
is a raw ingredient)
FindRawIngred = ingrcheck 'Set the raw ingredient as the
item code
Else
If Trim(rs!item) = "LABOR" Then rs.FindNext sSQL
FindRawIngred = FindRawIngred(rs!item, rs) 'Run FindRawIngred on
item code
End If
End Function
Any thoughts, suggestions or advice would be very much appreciated.
Best regards,
marc
(don't ask and I can't change this) free tables. Basically, it's a
recipe table that can have multiple recursive levels of ingredients
(i.e. Salad Mix contains Chopped Lettuce Mix, which contains Lettuce).
I have successfully programmed VBA functions to recursively seek out
the lowest level ingredient (one for which there is no recipe).
However, it is SLOW SLOW SLOW, and I was hoping for some advice with
regards to speeding it up. The passthrough database has over 5000
records in it.
qryARRECP01 is the passthrough recipe file. There are three custom
functions that call to Passthrough Queries -- getrawcode, getrawqty,
getrawwieght -- which obtain the ultimate raw ingredient, the amount of
this ingredient required and the resulting ingredient remaining after
processing (to calculate yield).
Following is the SQL code for the query:
SELECT qryARRECP01.recipe, qryARRECP01.item,
getrawcode([qryARRECP01]![item]) AS rawingred,
getrawqty([qryarrecp01]![item],[qryarrecp01]![recipe]) AS qty,
getrawweight([qryarrecp01]![recipe],[qryarrecp01]![item],[rawingred])
AS weight, [weight]/[qty] AS yield
FROM qryARRECP01 INNER JOIN qryARINVT01 ON qryARRECP01.recipe =
qryARINVT01.item
WHERE (((qryARRECP01.item) Not In ("LABOR","PACKPO","PACK")))
ORDER BY qryARRECP01.recipe, qryARRECP01.item;
I will include the code for just getrawcode, because the other three
queries are fairly similar (though getrawweight is even slower because
it searches two passthrough queries.
Function GetRawCode(ByVal ingrcheck As String) As String
Dim db As Database
Dim rs As DAO.Recordset
'Open Recipe Query
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryARRECP01", dbOpenDynaset, dbReadOnly)
If (Not rs.EOF) Then
'Call recursive function to locate raw ingredient
GetRawCode = FindRawIngred(ingrcheck, rs)
End If
rs.Close 'Close Table
Set db = Nothing 'Clear reference to database
End Function
Function FindRawIngred(ByVal ingrcheck As String, rs As DAO.Recordset)
As String
Dim sSQL As String
sSQL = "[recipe] = """ & ingrcheck & """"
rs.FindFirst sSQL 'Search recordset for matching item code
If rs.NoMatch Then 'When item code is not found (e.g.
is a raw ingredient)
FindRawIngred = ingrcheck 'Set the raw ingredient as the
item code
Else
If Trim(rs!item) = "LABOR" Then rs.FindNext sSQL
FindRawIngred = FindRawIngred(rs!item, rs) 'Run FindRawIngred on
item code
End If
End Function
Any thoughts, suggestions or advice would be very much appreciated.
Best regards,
marc