Categorizing and sorting techniques

JohnCTX 636 Reputation points
2021-03-21T03:19:04.897+00:00

I am trying to utilize my categorizing techniques by using the algorithm as described below.

  1. User inputs category
  2. If category does not exist then add it to list of categories
  3. User inputs subcategory
  4. User inputs another category
  5. If category already exists then add subcategory to existing list of categories.

Can this be done in Microsoft Access VBA?

Regards,

JohnCTX

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JohnCTX 636 Reputation points
    2021-03-21T05:16:40.073+00:00

    Here is the source code snippet below:

      Option Compare Database
        Dim DBZ As DAO.Database
        Dim SubCatRecSet As DAO.Recordset
        Dim CatRecSet As DAO.Recordset
        Dim strInputX As String
        Dim lngCatNumber As Long
        Dim lngSubCatNumber As Long
    
        Sub Sort_Them_All()
        Open "C:\Users\...\Documents\List of entries.txt" For Input As #1
        Open "C:\Users\...\Documents\List of Categories.txt" For Output As #2
    
        Set DBZ = CurrentDb
        Set CatRecSet = DBZ.OpenRecordset("Categories", dbOpenDynaset)
        Set SubCatRecSet = DBZ.OpenRecordset("Sub Categories", dbOpenDynaset)
    
        lngCatNumber = 1
        lngSubCatNumber = 1
    
        intX = 0
    
        Do Until EOF(1)
            Line Input #1, strInputX
            If InStr(1, strInputX, "(") Then
            'This line of code below generates an error and needs to be fixed.
                CatRecSet.FindFirst (strInputX)
                If CatRecSet.NoMatch = True Then
                    With CatRecSet
                        lngCatNumber = lngCatNumber + 1
                        .AddNew
                        .Fields(0).Value = lngCatNumber
                        .Fields(1).Value = strInputX
                        .Update
                    End With
                    intX = intX + 1
                End If
            End If
        Loop
    
    
    
        Close #2, 1
    
    
    
        SubCatRecSet.Close
        CatRecSet.Close
    
    
    
        End Sub