Categorizing and sorting techniques

JohnCTX 631 Reputation points

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?



0 comments No comments
{count} votes

1 answer

Sort by: Newest
  1. JohnCTX 631 Reputation points

    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
                        .Fields(0).Value = lngCatNumber
                        .Fields(1).Value = strInputX
                    End With
                    intX = intX + 1
                End If
            End If
        Close #2, 1
        End Sub