Hey guys, first time post here but looks like a decent forum!
I'm moving a lot of our web based admin stuff over from a PHP based online system to Access, using ODBC link tables.
In PHP I had a neat enough little script to run through and generate a list of categories like this:
Main Category
--->Sub Category
--->Sub Category 2
--->---->Sub Sub Category
--->Sub Category 3
and so on!
I have a table with the categories in, with columns for cat_name, cat_id, and cat_parent. If the parent is zero then it's a main category.
I've transferred the code into VBA but it's real slow. I've around 200 categories and nothing more than 1/2 levels deep, so I don't see why the recursion seems to be taking so long. In PHP it generates this in no time, but Access is being real slow! Any suggestions?
My code is shown below:
Private Sub Display_cats(parent As Integer, hide As Integer, depth As Integer)
Dim sSQL As String
sSQL = "SELECT catid, catname, parent FROM [categoriesW] WHERE parent= " & parent & " AND catid <> " & hide & " AND catname NOT LIKE 'temp%' AND catid <> 0 ORDER BY catname;"
Dim catname As String
Dim prefix As String
depth = depth + 1
For i = 1 To depth
prefix = prefix & "--->"
Next i
Dim MyDB As Database, MyRec As Recordset
Set MyDB = CurrentDb
Set MyRec = MyDB.OpenRecordset(sSQL, dbOpenForwardOnly)
While MyRec.EOF = False
If MyRec![parent] = 0 Then
catname = StrConv(MyRec![catname], vbUpperCase)
Else
catname = prefix & MyRec![catname]
End If
Combo20.AddItem (catname & ";" & MyRec![catid])
Display_cats MyRec![catid], hide, depth
MyRec.MoveNext
Wend
depth = depth - 1
MyRec.Close
MyDB.Close
End Sub
I'm moving a lot of our web based admin stuff over from a PHP based online system to Access, using ODBC link tables.
In PHP I had a neat enough little script to run through and generate a list of categories like this:
Main Category
--->Sub Category
--->Sub Category 2
--->---->Sub Sub Category
--->Sub Category 3
and so on!
I have a table with the categories in, with columns for cat_name, cat_id, and cat_parent. If the parent is zero then it's a main category.
I've transferred the code into VBA but it's real slow. I've around 200 categories and nothing more than 1/2 levels deep, so I don't see why the recursion seems to be taking so long. In PHP it generates this in no time, but Access is being real slow! Any suggestions?
My code is shown below:
Private Sub Display_cats(parent As Integer, hide As Integer, depth As Integer)
Dim sSQL As String
sSQL = "SELECT catid, catname, parent FROM [categoriesW] WHERE parent= " & parent & " AND catid <> " & hide & " AND catname NOT LIKE 'temp%' AND catid <> 0 ORDER BY catname;"
Dim catname As String
Dim prefix As String
depth = depth + 1
For i = 1 To depth
prefix = prefix & "--->"
Next i
Dim MyDB As Database, MyRec As Recordset
Set MyDB = CurrentDb
Set MyRec = MyDB.OpenRecordset(sSQL, dbOpenForwardOnly)
While MyRec.EOF = False
If MyRec![parent] = 0 Then
catname = StrConv(MyRec![catname], vbUpperCase)
Else
catname = prefix & MyRec![catname]
End If
Combo20.AddItem (catname & ";" & MyRec![catid])
Display_cats MyRec![catid], hide, depth
MyRec.MoveNext
Wend
depth = depth - 1
MyRec.Close
MyDB.Close
End Sub