Make last month's current data be this month's previous data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpmatthews
    New Member
    • Jan 2013
    • 8

    Make last month's current data be this month's previous data

    I need VB code that will automatically pull last month's current data and place it in this month's previous data.

    We have a form that we use to document meter readings. So for example, when we take January's reading and place that in the field labeled "PresentVal ue" I would like December's reading to automatically load into the field labeled "PreviousValue" . the form also contains the Meter's description as a field, as well as the month and year by which you are inputing the data.

    Hope someone can help!
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    To help we'd need to know a little more about the tables behind your data.

    In a general sense, you need a query that will filter the records for the meter in question and then filter down again for the prior month's data - this can be done with one "WHERE" clause.
    Last edited by zmbd; Jan 31 '13, 02:08 PM. Reason: [z{added "where"}]

    Comment

    • jpmatthews
      New Member
      • Jan 2013
      • 8

      #3
      I know how I can filter the data down to what I want in the query (the present value for one month prior) but I need to be able to insert that value into the form (into the previous value field).

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        In a general sense, you need a QUERY that will filter the records for the meter in
        Notice I said "Query" above yes?
        You need that query FIRST.
        Once you have that query, you can use it in your controls or reports.

        You have provided absolutly nothing about the design or the nature of your database and the dataset.

        Please bear in mind the following:
        - Out right requests for full code are against site policy.
        Asking for someone to provide completed code or a completed project may result in the thread being delted.
        - Bytes is not a code writing nor homework service. Please read the FAQ and posting guidlines before reposting your question.

        -Please consult the FAQ and specific forum sticky threads for further information.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Also, it sounds like your design is unnormalized. There really isn't a need for a previous value field in a table because each reading should have its own row and you would be repeating data by doing so.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            You're absolutly correct Rabbit;
            I had read OP post to mean that the value should/would appear in a "control" on the form/report and not as a field within the table.

            Comment

            • jpmatthews
              New Member
              • Jan 2013
              • 8

              #7
              That's a good point about the repeated data. I never really thought about it that way.

              I think I can get it to work now, I had just run into a wall and wasn't think it through correctly. Thanks!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32653

                #8
                Please check out these links before posting any new questions :
                How to ask "good" questions -- READ BEFORE SUBMITTING A QUESTION!.
                Before Posting (VBA or SQL) Code.

                Comment

                Working...