Results 1 to 7 of 7
  1. #1
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75

    Creating Multiple Records

    I am using an unbound form to move products and keep track of inventory.



    To manage the database easier each item that we physically have gets its own record. 1 record = 1 item etc..

    so on the form I have Product and Quantity.. I have my code that will create one record per product put in the form. I can't figure out how to create say 20 records for item1 and 10 records for item2

    Code:
    Private Sub Command61_Click()
    Dim DBSS As Database
    Dim rs As DAO.Recordset
    Dim i As Integer
    
    Set DBSS = CurrentDb
    Set rs = CurrentDb.OpenRecordset("SELECT ProductName, OldLocation, NewLocation FROM tblTransfers")
    
    
    
    
    For i = 1 To 20
        If Me.Controls("item" & i) & "" = "" Then
            Exit For
        Else
            With rs
                .AddNew
                !ProductName = Me.Controls("item" & i).Value
                !OldLocation = Me.txtFrom.Value
                !NewLocation = Me.txtTo.Value
                .Update
            End With
        End If
    Next i
    
    rs.Close
    Set rs = Nothing
    DoCmd.Close
    End Sub
    The Quantity TextField in the form is Quan1 to Quan20

    Hopefully i explained well enough..

    Thanks
    Zook

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I think you are heading in the wrong direction, but I may be misunderstanding your post.

    Here is a generic data model for a typical Inventory Control system.

    It may not reflect your business, but it is generic (has most common parts ) of such a system.
    You can add, drop, ignore the model. It is meant to help you get a picture of a typical inventory database.

    You should review Normalization.
    http://databases.about.com/od/specif...malization.htm
    http://rogersaccessblog.blogspot.ca/...on-part-i.html


    Here is a youtube video you should review for concepts, ideas and approaches.
    Good luck.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So you have 20 unbound text boxes for the product name and 20 text boxes for the number of items to add?

    You need two loops - you are missing an inner loop.
    Maybe something like this:

    **untested**
    Code:
    Private Sub Command61_Click()
        Dim DBSS As Database
        Dim rs As DAO.Recordset
        Dim i As Integer
        Dim j As Integer
    
        Set DBSS = CurrentDb
        Set rs = CurrentDb.OpenRecordset("SELECT ProductName, OldLocation, NewLocation FROM tblTransfers")
    
        'outer loop - products
        For i = 1 To 20
            If Me.Controls("item" & i) & "" = "" Then
                Exit For
            Else
                With rs
                    'inner loop - quantity
                    For j = 1 To Me.Controls("quan" & j)
                        .AddNew
                        !ProductName = Me.Controls("item" & i).Value
                        !OldLocation = Me.txtFrom.Value
                        !NewLocation = Me.txtTo.Value
                        .Update
                    Next j
                End With
            End If
        Next i
    
        rs.Close
        Set rs = Nothing
        DoCmd.Close
    End Sub

  4. #4
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    When I use

    For j = 1 to Me.Controls("quan" & j)

    Next j

    I get an error saying quan0 cant be found

  5. #5
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    Okay I figured out what was going on with the code:

    Code:
    For i = 1 To 20
        If Me.Controls("item" & i) & "" = "" Then
            Exit For
        Else
            With rs
                For j = 1 To Me.Controls("quan" & i).Value
                    .AddNew
                    !ProductName = Me.Controls("item" & i).Value
                    !OldLocation = Me.txtFrom.Value
                    !NewLocation = Me.txtTo.Value
                    .Update
                Next j
            End With
        End If
    Next i

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    lzook88,

    Do you have a description of your business opportunity to help readers understand what you are trying to solve/automate? You are asking about details of interacting loop constructs under a general question re Inventory Tracking. Perhaps others can read between the lines, but I prefer to hear the issue/opportunity from the poster.

  7. #7
    lzook88 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    75
    Sorry about.

    This is used for EMT Supply Inventory. We don't really care about the orders we make as much as the amount of product we currently have in each location and station. The orders are monitored through the administrative staff at our supply location. So we just want to track it coming into the main Station and being sent to the units/bags from there.

    The goal of this automation was to create a recrodset for each individual item. So say we have 5 gauzes in the Station it would create five new records that say gauze as the product and station as the location.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-13-2014, 09:38 AM
  2. Replies: 2
    Last Post: 04-18-2013, 12:42 PM
  3. Replies: 3
    Last Post: 10-18-2012, 02:25 PM
  4. Replies: 2
    Last Post: 02-28-2012, 12:43 PM
  5. Creating multiple records from a single form
    By secretary in forum Forms
    Replies: 8
    Last Post: 07-18-2011, 04:03 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