Question : MS Access table with variable number of fields - adding field values

Hi

I have a table that is created by a make table query.  Each time it is created it will potentially have a different number of fields.  There are a finite number of fields names but any combination may be present in the table in any order.

The fields contain values and I need to create another query that results in a total of the values.  However I am having problems with this query because of the variable number of fields that could be in the table.

How can I solve this?

Many thanks

Answer : MS Access table with variable number of fields - adding field values

You just need to get the number of fields each time and then do your calculations. Maybe this snippet of code I use can be helpful or give you some ideas. It loops through all fields in a table and loads their names into a combobox (lstTables.Text is the name of the table I'm examaning):

     For Each Table In jetDB.TableDefs
        If Table.Name Like lstTables.Text Then
           For Each field In jetDB.TableDefs(TabNdx%).Fields
              lstFields.AddItem field.Name
              For i% = 0 To 2
                 cboSort(i%).AddItem field.Name
                 cboSrch(i%).AddItem field.Name
              Next i%
           Next field
        End If
        TabNdx% = TabNdx% + 1
     Next Table

Random Solutions  
 
programming4us programming4us