Sum of values in multiple columns - Column names keep changing every week

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SriKumar
    New Member
    • Jun 2012
    • 11

    Sum of values in multiple columns - Column names keep changing every week

    Hello,

    I have a problem with adding values...
    If the table headers are unchanged then adding values from different columns is not a problem. But in my table, the headers keep changing every week.

    Could someone please help me with the VBA code to add columns irrespective to the column names? One option I have is the header names start with OH 2300, OH 2301 ...

    Is there anything like: DSum anything starts with OH or Like"OH *" ?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Your data structure is unnormalized. You need to normalize it so you don't have changing field names. That way you don't have so much trouble querying.

    Comment

    • SriKumar
      New Member
      • Jun 2012
      • 11

      #3
      Hello Rabbit,

      Thanks much for the reply.
      I accept that the data structure is not normalized and there is no way for me to change it now.

      Please let me know if there is any way to make it possible with the present data structure.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        SriKumar
        I can understand your pain about being "locked" into a poorly designed database; however, every momement that you spend to get that db into a normalized form will pay you back at least a hundred fold!

        In the mean time please start with the following:

        http://support.microsoft.com/kb/210362 Yes, it's for MSA2000; however, it still applies.

        and
        Code:
        Sub FieldNames()
            Dim zrs As Recordset
            Dim zfld As Field
            '
            'establish the recordset
            Set zrs = CurrentDb.OpenRecordset("YourTableNameHere")
            '
            'step thru the field names in the open table
            For Each zfld In zrs.Fields
                MsgBox (zfld.Name)
            Next
            '
            'cleanup
            zrs.Close
            Set zrs = Nothing
        End Sub
        DON'T ASK ME WHY I HAVE THAT JUST SITTING AROUND... yep... I had a DB that was not normalized... not anymore! Over 5 years of data in that monster and the tables were monsters! It's "fixed" now and I don't regret the time I spent on it at all!

        -z

        Comment

        Working...