Results 1 to 3 of 3
  1. #1
    beewerks is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Location
    Longmont, Colorado
    Posts
    7

    Using form to save multiple records to table

    Hello everyone,

    I've got a form that is used for tracking products with unique serial numbers. I want to enter a product in the form and then depending on the order we get, select a quantity of product which would then make as many identical rows in the table as needed based on the before selected quantity. All of the product lines would be identical except for the serial number column, which I have set to Auto_Number. I hope this makes sense.

    Below is my INSERT INTO command button code:

    Private Sub cmdSave_Click()
    'save data to table
    CurrentDb.Execute "INSERT INTO [Product_SN_Tracking](ModelNumber, PartNumber, Description, PowerRating, WorkOrder) " & _
    " VALUES('" & Me.txtModel & "','" & Me.cboPart & "','" & Me.txtDescription & "','" & Me.txtPower & "','" & Me.txtWorkorder & "')"
    'clear cells on form after save
    Me.txtDescription = ""
    Me.txtModel = ""
    Me.txtPower = ""
    Me.txtWorkorder = ""
    Me.txtSerial = ""
    Me.cboPart = ""
    End Sub

    Where or how would I allow for duplicate rows of records to be inserted into my table?



    Thanks!
    Alex

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Just create a loop for x many items

    if your current code works just embed it in a loop, for instance if you have a quantity field on your form

    Let's say your quantity field is named QUANTITY

    Code:
    for i = 1 to QUANTITY
         currentdb.execute (... put your current code here if it works...)
    next i
    
    reset your fields here per your original code
    This would create duplicate records and assuming your target table [product_sn_tracking] had an autonumber serial number you'd be just fine.

  3. #3
    beewerks is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Location
    Longmont, Colorado
    Posts
    7
    Ha! It works! It's so simple too. Thanks so much for your help. All of my searching couldn't find this loop function.

    Quote Originally Posted by rpeare View Post
    Just create a loop for x many items

    if your current code works just embed it in a loop, for instance if you have a quantity field on your form

    Let's say your quantity field is named QUANTITY

    Code:
    for i = 1 to QUANTITY
         currentdb.execute (... put your current code here if it works...)
    next i
    
    reset your fields here per your original code
    This would create duplicate records and assuming your target table [product_sn_tracking] had an autonumber serial number you'd be just fine.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 04-04-2015, 08:53 AM
  2. Replies: 12
    Last Post: 08-04-2014, 05:11 PM
  3. Replies: 4
    Last Post: 10-30-2012, 04:33 PM
  4. Form to add multiple records to table
    By jcarstens in forum Forms
    Replies: 1
    Last Post: 05-17-2012, 06:26 PM
  5. Replies: 9
    Last Post: 01-20-2011, 02:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums