Categorzing items in a form and a subform

JohnCTX 636 Reputation points
2021-03-29T03:45:39.847+00:00

I have the following code snippet:
Sub Sort_Those_Subcategories()
Set db = CurrentDb
Set frmX = New Form_Categories
Set rx = db.OpenRecordset("Precategorized", dbOpenDynaset)
Dim Ctx As Long
Ctx = 1

Do Until rx.EOF  
    If frmX.Category.Value = rx.Fields(0).Value Then  
        rx.MoveNext  
        frmX.chdSubCat.Controls![Sub Category Number] = Ctx  
        frmX.chdSubCat.Controls![Sub Category] = rx.Fields(0).Value  
        frmX.chdSubCat.Controls![Category Number] = frmX.Category_Number.Value  
        Ctx = Ctx + 1  
    End If  
    rx.MoveNext  
Loop  
  
frmX.Refresh  
frmX.Requery  
rx.Close  
  
  
End Sub  

..and here is the screenshot:
82217-subcategory-screenshot.png

I want to improve or fix this source code snippet above, but I just don't know how.

Should I use the Seek or Find method of the DoCmd object, and add it to my code snippet?

Regards,

JohnCTX

Microsoft 365 and Office | Access | Development
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.