Forms VBA和Access 2007数据验证、登录故障

Forms VBA和Access 2007数据验证、登录故障,forms,vba,login,ms-access-2007,Forms,Vba,Login,Ms Access 2007,请容忍我,我在VBA是一个彻头彻尾的傻瓜,我本来不打算写代码,但我最终还是这么做了,因为我不知道没有它我将如何实现我想要的。我已经在网上搜索了3天,每天10个小时,运气不好。我有一个Access数据库,我想保护它。让我先解释一下我想要实现的目标: 1) 我有一个表单中的组合框,用于查找表中的值,即项的项代码。这基本上是一个库存问题。我有一个查询,它有一个计算字段,返回每个项目的剩余库存。我有另一个查询,它将商品代码作为参数,并返回该特定商品代码的剩余库存 我想做的是检查剩余库存是否为0,如果是,

请容忍我,我在VBA是一个彻头彻尾的傻瓜,我本来不打算写代码,但我最终还是这么做了,因为我不知道没有它我将如何实现我想要的。我已经在网上搜索了3天,每天10个小时,运气不好。我有一个Access数据库,我想保护它。让我先解释一下我想要实现的目标:

1) 我有一个表单中的组合框,用于查找表中的值,即项的项代码。这基本上是一个库存问题。我有一个查询,它有一个计算字段,返回每个项目的剩余库存。我有另一个查询,它将商品代码作为参数,并返回该特定商品代码的剩余库存

我想做的是检查剩余库存是否为0,如果是,则在从组合框列表中选择此项目代码时,让msgbox显示一条消息,说明该项目没有库存,因此无法发行,并重置组合框(即,好像没有进行选择)

这是我的密码;组合框的afterUpdate事件:

Private Sub Item_Code_AfterUpdate()

Dim dbMyDatabase As DAO.Database

Dim rsMyRecords As DAO.Recordset

Dim strQuery As String

strQuery = "SELECT [Store_Items].[Item Code], Store_Items.[Opening Stock], IIf((Nz([Opening Stock],0)+Nz([Quantity Purchased],0)-Nz([Quantity Issued],0)<0),0,(Nz([Opening Stock],0)+Nz([Quantity Purchased],0)-Nz([Quantity Issued],0))) AS [Remaining Stock] FROM (Purchases RIGHT JOIN Store_Items ON Purchases.[Item Code] = Store_Items.[Item Code]) LEFT JOIN Issuances ON Store_Items.[Item Code] = Issuances.[Item Code] WHERE (((Store_Items.[Item Code])=[Forms]![Issuances]![Item Code]));"

Set dbMyDatabase = CurrentDb

Set rsMyRecords = dbMyDatabase.OpenRecordset(strQuery)

Dim Msg, Style, Title, Response

Msg = "This Item is out of Stock! You Cannot Issue this item!"
Style = vbOK
Title = "Warning!"

If rsMyRecords![Item Code] <= 0 Then
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then Me![Item Code].Requery

End Sub 

请帮忙S

好吧,我设法解决了登录问题,但我仍然坚持使用数据验证位。当我单击组合框中列表中的项目代码时,出现运行时错误3421

当我从组合框中选择一个项目代码时,这就是我希望发生的事情。我想从该商品代码的查询中获取计算字段(此计算字段包含商品的计算剩余库存),如果为0,则我想显示消息并阻止用户输入此记录,因此我想重置组合框可以吗

如果股票处于某个水平,我只想显示一个msgbox,仅此而已,通常让用户输入记录,否则,用户只需正常输入记录

我在这一行收到运行时错误3421“数据类型转换错误”:

Set rs=db.OpenRecordset(“从[InventoryStatusSpecificItem]中选择[剩余库存],其中[Item Code]=[Forms]![Issuations]![ItemCBO]”,动态集)

Private Sub LoginBUtton_Click()

'Check to see if data is entered into the UserName combo box

    If IsNull(Me.CBOLogin) Or Me.CBOLogin = "" Then
      MsgBox "You must select a user type.", vbOKOnly, "No User name"
        Me.CBOLogin.SetFocus
        Exit Sub
    End If

    'Check to see if data is entered into the password box

    If IsNull(Me.TextPass) Or Me.TextPass = "" Then
      MsgBox "No Password Entered, Enter a password.", vbOKOnly, "No Password"
        Me.TextPass.SetFocus
        Exit Sub
    End If

    'Check value of password in Users to see if this
    'matches value chosen in combo box

    If Me.TextPass.Value = DLookup("Password", "Users", _
            "[UserID]=" & Me.CBOLogin.Value) Then



    ElseIf (Me.CBOLogin.Value = "Developer") Then
    DoCmd.Close acForm, "LoginForm", acSaveNo
    DoCmd.OpenForm "FullAccessNav"


    ElseIf (Me.CBOLogin.Value = "Office") Then
    DoCmd.Close acForm, "LoginForm", acSaveNo
    DoCmd.OpenForm "LimitedAccessNav"


    ElseIf (Me.CBOLogin.Value = "Store") Then
    DoCmd.Close acForm, "loginForm", acSaveNo
    DoCmd.OpenForm "LimitedAccessNav"

    Else
            MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
            "Invalid Entry!"
            Me.TextPass.SetFocus

    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogonAttempts = intLogonAttempts + 1

    If intLogonAttempts > 3 Then
      MsgBox "You do not have access to this database.Please contact admin.", _
               vbCritical, "Restricted Access!"
        Application.Quit
    End If

End Sub
Private Sub ItemCBO_AfterUpdate()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Set db = CurrentDb()


    Set rs = db.OpenRecordset("SELECT [Remaining Stock] FROM [InventoryStatusSpecificItem] WHERE [Item Code] = [Forms]![Issuances]![ItemCBO]", Dynaset)



    If rs.Fields([Remaining Stock]) = "0" Then
    MsgBox "This item is out of stock! Cannot Issue!", vbExclamation + vbOKOnly, "Attention!", vbExclamation
    Me!ItemCBO = Null

    ElseIf rs.Fields("Stock Status") = "Order Now!" Then
    MsgBox "This item has reached its minimum quantity level. Only " + StrRemainingStock + " remains. Quantity Measured as " + StrMeasuredIn, vbExclamation + vbOKOnly, "Attention!"

    Else
    Me!ItemCBO.Requery

    End If

    'close recordset
    rs.Close
    Set db = Nothing