How to auto-populate fields in an MS Access Form with VB?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zeilak
    New Member
    • Mar 2007
    • 4

    How to auto-populate fields in an MS Access Form with VB?

    I am running Windows XP, Access 2002.
    I want to know the VB code for the following:
    I want to type in the ID # (it's the primary key and is auto-numbering) and then have the access form autopopulate three fields for that ID # record. (The three fields are called pu, am, and qu). Pu should populate with a vaule of 1. Am should populate with a value of 38. Qu should populate with a value of 1.
    Can you please send me the code?
    Thank you!
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Moved your thread to the Access forum

    Comment

    • zeilak
      New Member
      • Mar 2007
      • 4

      #3
      I know how to open VB within Access. What I don't know is how to write code! Can you please help me?

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by zeilak
        I know how to open VB within Access. What I don't know is how to write code! Can you please help me?
        In Access the language is VBA which is different from vb so this is the correct forum for your question

        Comment

        • Denburt
          Recognized Expert Top Contributor
          • Mar 2007
          • 1356

          #5
          Sounds like you are just looking to set the default property. Right click on the control and go to properties then look for the default value.

          If you wanted these values to change for whatever reason you could use the "On Current" event and insert the code for it in there.

          Let me know if you need more specifics.

          Comment

          • zeilak
            New Member
            • Mar 2007
            • 4

            #6
            I can't just set a default code because it won't be for every record. Just after a certain point in time, I want to type a record ID number and then have it auto populate for that one record only. Can anyone help me write the code for that?

            Comment

            • Denburt
              Recognized Expert Top Contributor
              • Mar 2007
              • 1356

              #7
              I want to type in the ID # (it's the primary key and is auto-numbering)
              You can not enter anything into a autonumber field since it generates the numbers for you.

              [QUOTE]I can't just set a default code because it won't be for every record. Just after a certain point in time, I want to type a record ID number and then have it auto populate for that one record only. Can anyone help me write the code for that?[/QUOTE}

              You really need to be a bit more specific I don't understand what you are saying. It would help if we knew how those figures might change and for what reason.

              Comment

              • zeilak
                New Member
                • Mar 2007
                • 4

                #8
                I am NOT trying to change the field that autonumbers.
                After I type in the ID # (which is the autonumber) there are several fields for that record. I want then to autopopulate three fields for that ID # record.
                (The three fields are called pu, am, and qu).
                Pu should populate with a value of 1 (true).
                Am should populate with a value of 38
                Qu should populate with a value of 1

                I will need to change it at times so that:
                Am will populate with a value of 60
                and Qu will populate with a value of 2

                These fields do not have any default vaule, and they are not autonumbered.

                Comment

                • Denburt
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1356

                  #9
                  Well you could store your values in a table a set up a form so you can change these values anytime you want. Then have the default values of these controls reference that table.... I still may not fully understand, but this is one approach.

                  Comment

                  Working...