question

JohnCTX-6479 avatar image
0 Votes"
JohnCTX-6479 asked ·

Categorizing and sorting techniques

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




office-vba-dev
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JohnCTX-6479 avatar image
0 Votes"
JohnCTX-6479 answered ·

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
· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Note that I had to delete the category example since that it did not make any sense in regards to finding a match in records.

0 Votes 0 ·