Results 1 to 4 of 4

Thread: Adding data

  1. #1
    Join Date
    May 2010
    Posts
    2

    Unanswered: Adding data

    I am working with an Access database that, through macros I run every week, replaces data in the tables with inputs from text and excel files. The data gets wiped out and replaced with the recent week's activity. As an example, one of the columns of data in the table is Cost. If week one's cost is 50, week two's cost is 100, and week three's cost is 25, when I run the macro on week 3 the data in the cost column is 25. What I want is for that data to be 175.

    Is there a function in Access to add the new data to the existing data rather than replace it? If not a function, then perhaps there's a way to add something to the current macro, or add an additional one to make it happen.

    Thanks.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Function AddToColumn(ByVal AddValue As Long)
    
        Dim strSQL As String
    
        strSQL = "UPDATE Table1 SET Col1 = Col1 + " & AddValue
        CurrentDb.Execute strSQL
    
    End Function
    Have a nice day!

  3. #3
    Join Date
    May 2010
    Posts
    2
    Thanks - I'll give this a shot. But before I do, do you think I should add this to the current macro or create a separate one? I haven't coded in over 5 years so I want to make sure my rusty skills don't screw the whole thing up...

    Thanks,

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you need to call the function from one form only, you can plate it in the form class module. Otherwise, create an independant module to make the function public.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •