Need to enter 5 records into same table with 1 button.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dpot
    New Member
    • Oct 2014
    • 30

    Need to enter 5 records into same table with 1 button.

    I need a way to enter 5 records that have the same information with one button click. This database is being used to collect quality information, and instead of clicking a button 5 times for 5 parts, we'd like 1 button that when clicked once adds 5 records with different ID numbers; or 10 records if it's ten good parts.

    The interval doesn't much matter, I just want to know if there is a way that we can click 1 button once and it'll but will put in multiple records with different ID Numbers (1, 2, 3, 4, 5, etc) but the rest of the information is the same (Part number, date, etc)

    I tried
    Code:
     Me.Id = Me.Id + 5
    and
    Code:
     Me.Id = Me.Id * 5
    but it did the obvious. Didn't hurt to try.

    Thanks in advance!
  • Dpot
    New Member
    • Oct 2014
    • 30

    #2
    Even tried Loop function, still didn't work. Any suggestions welcome.

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3662

      #3
      Dpot,

      I'm not sure I understand exactly what you are trying to do. I don't understand why you would be entering multiple records for one part.

      Perhaps if you explained a bit better what it is that you are trying to do and why, we will be better able to assist.

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        There are basically two different ways to do this, both involving a loop. You can either use an unbound form and use the DAO.Recordset.A ddNew method or you can use a bound form and use variables to store the data for the first record and then move to a new record, set the controls to the appropriate values from the variables and save. There isn't a "Right" answer for every situation. I'll let you decide which method works best for you.

        Comment

        • Dpot
          New Member
          • Oct 2014
          • 30

          #5
          The operator does hundreds of parts a day.... with maybe 20 total bad parts. They do not want to have to sit there and enter every good part individually, she would like a way to enter them in in intervals of 5 or 10, just to save them time and frustration.. We need every part recorded, good or bad. We can't have 1 record that just says "5 good parts" we need 5 individual records displayed.

          Here's an example of the code I was trying to use with the Loop function. It does EXACTLY what I want it to (puts multiple records in) but it will not stop, it just keeps going.

          Code:
          Do Until Me.ID.Value = Me.ID.Value + 5
             Me.Check401 = True
             DoCmd.GoToRecord , , acNext
             Counter = Counter + 1
             Command303.Caption = "Entered: " + CStr(Counter)
             Me.Command303.BackColor = &HFF&
          Loop
          Last edited by zmbd; Nov 10 '14, 07:17 PM. Reason: [z{merged related posts, stepped code}]

          Comment

          • Seth Schrock
            Recognized Expert Specialist
            • Dec 2010
            • 2965

            #6
            Because the second Me.ID.Value doesn't stay at its original value. So each loop is doing the following:

            Code:
            Do Until Me.ID.Value = 6
            Do Until Me.ID.Value = 7
            Do Until Me.ID.Value = 8
            Etc.
            Before the loop, store the value of Me.ID in a variable and then test Me.ID against that variable + 5. Probably would be better to store Me.ID + 5 in the variable.

            Comment

            • Dpot
              New Member
              • Oct 2014
              • 30

              #7
              Oh dur, I didn't even look at it that way. Thank you! I'll try it.

              Comment

              • Dpot
                New Member
                • Oct 2014
                • 30

                #8
                Thanks for all the help... the following code does the job. Posting it in case anyone else may need it.

                Code:
                Dim sten As Integer
                Dim st As Integer
                Dim en As Integer
                st = IsNull(Me.ID.Value)
                en = IsNull(Me.ID.Value) + 4
                For sten = st To en
                   Me.Check401 = True 
                   DoCmd.GoToRecord , , acNext
                   Counter = Counter + 1
                   Command303.Caption = "Entered: " + CStr(Counter)
                Next

                This will add 5 new records to my table at once.
                Last edited by Dpot; Nov 11 '14, 01:05 PM. Reason: correction

                Comment

                Working...