带访问权限的基本库存设置

时间:2016-04-13 16:15:48

标签: ms-access ms-access-2007 inventory-management

所以,我是一个新手,可以访问并需要帮助来完成我的库存数据库。

目前我有以下表格及其中的字段: (表:字段,第一个字段是主键)

  

项目:项目编号,项目描述,项目规格再订购等级,重新订购数量,现有数量

     

Materials_Used:ID(只是一个自动编号字段),项目,项目#,金额

     

项目:项目

     

Purchase_Orders:PONum,收到日期

     

Receiving_Amount:ID(再次自动编号),Item#,Amount,PONum

我在2个区域遇到问题:

  1. 使用Receiving_Amount项目绑定PONum:目前我有一个date表单,要求用户输入POnumdate以及接收金额的子表单数据表格式。在我输入PONum和{{1}}之后,向下移动到输入我收到的项目并输入参数值框Purchase_Orders.ID和Purchase_Orders.PONumber ------由于韦恩,这个问题得到了解决!

  2. 将项目表的数量设置为在通过采购订单表格(添加到表格)和使用的材料表格(减去)

  3. 收到项目后自动更新

    Database Relationship

1 个答案:

答案 0 :(得分:0)

由于您将在多用户更新环境中工作,因此您需要确保与其他用户没有冲突。最安全的方法是使用TRANSACTION。

接下来,您需要决定如何以及何时对两个表进行更新。让我们选择'选项1'这是用户在完成时点击的按钮。单击按钮时需要调用以下子例程。您还应该跟踪用户是否对子表单进行了任何更改,但忘记单击“保存”。按钮。

然后我强烈建议您跟踪所做的更改。例如,用户输入数量为5,保存更改。明天,查看数据,看到5,并希望将其更改为6 ...这将破坏真正的库存。一种防止方法是拥有一个标记'对于PO行项目,表明他们已被处理并再次阻止更新。

以下代码只是一个示例......我编写了我认为应该是输入和输出记录集的代码,但是您需要确保选择要处理的正确输入行然后选择输出行对于表格。

在##中查找带有##的注释....修复代码以使用您的控件名称。

如果您需要更多解释,请与我们联系。

Option Compare Database
Option Explicit

'   BeginTrans, CommitTrans, Rollback Methods Example
'   After the BeginTrans method starts a transaction that isolates all the changes made,
'   the CommitTrans method saves the changes.
'   Notice that you can use the Rollback method to undo changes that you saved using
'   the Update method. Furthermore, the main transaction is nested within another transaction
'   that automatically rolls back any changes made by the user during this example.

'   One or more table pages remain locked while the user decides whether or not to accept the changes.
'   For this reason, make sure you only execute the transaction on some event - don't allow a user
'   to be interactive, else he may go to lunch and may lock pages someone else needs!

'   Add to: Receiving_Amount: ID(again autonumber), Item#, Amount, PONum
'   Subtract from: Materials_Used: ID(just an Autonumber field), Project, Item#, Amount

Sub BeginTransX_Update_Inventory()
    On Error GoTo Error_trap

    Dim wrkDefault      As DAO.Workspace
    Dim dbs             As DAO.Database
    Dim tblInput        As DAO.recordSet
    Dim tblItems        As DAO.recordSet
    'Dim tblMaterials    As DAO.recordSet

    ' Get default Workspace.
    Set wrkDefault = DBEngine.Workspaces(0)
    Set dbs = CurrentDb

    ' ## Change the following line to use the name of the form control that has your PONum
    Set tblInput = dbs.OpenRecordset("select * from MaterialsRec where PONum = " & Me.txtPONum & ";")            '<<< This will be the source of your changes. Can use a query to filter exact rows.

    ' Start transaction.
    wrkDefault.BeginTrans

    Do While Not tblInput.EOF

        Set tblItems = dbs.OpenRecordset("select * from [Items] where [Item#] = " & tblInput![item] & ";")    ' <<< This will be where the updates are applied.

        ' Increase Qty on Hand
        tblItems.Edit
        tblItems![Qty on Hand] = tblItems![Qty on Hand] + tblInput!Amount
        tblItems.Update

        '## Add a text field named 'ProcStatus' to table MaterialsRec, or delete the following update ... your choice...
        tblInput.Edit
        tblInput!ProcStatus = "updated"
        tblInput.Update

        tblInput.MoveNext
    Loop

    ' You can remove the following code if desired...
    ' Ask if the user wants to commit to all the changes made above.
    If MsgBox("Save changes?", vbYesNo) = vbYes Then
        wrkDefault.CommitTrans
    Else
        wrkDefault.Rollback
    End If

    tblInput.Close
    tblItems.Close
    'tblMaterials.Close
    Set tblItems = Nothing
    'Set tblMaterials = Nothing
    Set dbs = Nothing
    Set wrkDefault = Nothing
    Exit Sub

Error_trap:
    wrkDefault.Rollback
    MsgBox "An error was encountered, but all changes were rolled back." & vbCrLf & _
            "Err: " & Err.Number & vbCrLf & _
            "Desc: " & Err.Description
End Sub