将数据范围从Access数据输入表格扩展到表格

时间:2016-03-29 15:59:12

标签: ms-access access-vba

我正在构建一个需要跟踪单个项目的库存数据库。每个项目都有一个与之关联的唯一编号。但是,我们会批量收到这些物品,并同样分发这些物品。我已经设置了一个数据输入表单来输入项目编号范围的开头和项目编号范围的结尾。例如,项目范围看起来像这样 - 1056-56701到1056-56800。项目编号始终为4位数字,后跟短划线和5位数字。我正在寻找扩展到我的数据输入表单的范围,以便范围内的每个单独的项目编号保存到我的表。在这种情况下 - 1056-56701,1056-56702,1056-56703,1056-56704 ...... 156-56800。我还需要保存每个项目范围的相应信息,因为它保存为单个数字。这将包括“收到日期'”,“'尺寸'等等。

我已经阅读了其他类似问题的其他回复,但我仍然无法使其正常运行。有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您可能需要的设计示例:

MASTER
------

Prefix      Int (primary key)
SuffixBegin String
SuffixEnd   String
ItemDescription String
DateReceived    Date
Size        String
. . . more columns for any other data common to the entire "batch"

DETAIL
------
ID  Int (primary key)
Prefix  Int (foreign key, related to the same-named column in the Master table)
Suffix  String (values such as "56701", "56702", etc.)
. . . more columns for whatever data you need to store about unique suffix items

然后,您可以找到特定项目的数据(伪SQL,未经测试):

SELECT M.ItemDescription, D.SomeSuffixSpecificData
FROM MASTER M, DETAIL D
WHERE M.Prefix = (the Prefix you're interested in)
AND D.Suffix = (the Suffix you're interested in)
JOIN M.Prefix = D.Prefix

答案 1 :(得分:0)

您可以使用此类功能列出并添加商品:

Public Function AddBulk(ByVal First As String, ByVal Last As String) As Integer

    Dim Items   As Integer
    Dim Item    As Integer
    Dim BulkId  As String

    ' Open your inventory table.
    ' Set rs = CurrentDb.OpenRecordset("Select Top 1 * From Inventory")

    For Item = Split(First, "-")(1) To Split(Last, "-")(1)
        BulkId = Split(First, "-")(0) & "-" & Item
        Debug.Print Items, BulkId
        ' Insert code to add one record to your inventory table.
        ' rs.AddNew
        '     rs!BulkId.Value = BulkId
        '     rs!OtherField.Value = somevalue
        ' rs.Update
        Items = Items + 1
    Next

    ' rs.Close

    AddBulk = Items

End Function