在空时关闭t表单时获取错误3134 [英] Getting error 3134 when closing t form when empty

查看:77
本文介绍了在空时关闭t表单时获取错误3134的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Form_Close()
        Dim sSQL, stringSQL As String
        Dim rst As DAO.Recordset

    sSQL = "SELECT BarCode, [Goods Name] FROM tblInventory WHERE BarCode='" & Me.ID & "'"
    Set rst = CurrentDb.OpenRecordset(sSQL)
    If rst.EOF Then
        stringSQL = "INSERT INTO tblInventory(BarCode,[Goods Name],Unit,[Unit Price],[Initial Stock],[Current Stock],[Exit Item]) values('" & Me.ID & "','" & Me.Description & "','" & Me.Unit & "'," & Replace(Format(Me.Price, "0.00"), ",", ".") & "," & Me.Amount & "," & Me.Amount & ",0)"
        DoCmd.SetWarnings False
        DoCmd.RunSQL (stringSQL)
        DoCmd.SetWarnings True
    Else
        stringSQL = "UPDATE tblInventory SET [Current Stock]=[Current Stock]+" & Me.Amount & " WHERE BarCode='" & Me.ID & "'"
        DoCmd.SetWarnings False
        DoCmd.RunSQL (stringSQL)   // the error is at this location// 
        DoCmd.SetWarnings True
    End If
    rst.Close
End Sub

Private Sub ID_AfterUpdate()
    Dim sSQL As String
    Dim rst As DAO.Recordset

    sSQL = "SELECT BarCode, [Goods Name], Unit, [Unit Price] FROM tblInventory WHERE BarCode='" & Me.ID & "'"
    Set rst = CurrentDb.OpenRecordset(sSQL)
    If rst.EOF Then
        MsgBox "New Parts"
        Me.Description.SetFocus
    Else
        Me.Description = rst(1).Value
        Me.Unit = rst(2).Value
        Me.Price = rst(3).Value
        Me.Amount.SetFocus
    End If
    rst.Close
End Sub





我尝试过:



我也注意到如果我只添加1个项目就可以了。但不允许将另一个项目输入到表格中。我必须在它添加另一个项目之前关闭表单。这是我在访问2010中使用的访问数据库,它正在开发以跟踪库存。我有一个表获取传入库存,jave接收传入并将其移动到一个名为tblinventory的表,当我输入新项目时,它会执行它应该执行的操作。然而,如果我尝试输入另一个项目,该项目没有进入tblinventory它确实显示在tblincoming上。我还注意到,如果我改变主意并关闭传入的输入表单我得到错误3134,此时表单为空。我试图修改代码但是在输入每个项目后它们都会出错。所以回到最初的错误。当我调试它显示在行DoCmd.RunSql(stringSQL)我已经注​​释了代码中的行。



What I have tried:

I have also noticed that if i only add 1 item it works. but does not allow another item to be input to the table. I have to close the form before it will add another item. This is an access data base i am using in access 2010, it is being developed to track inventory. I have a table that gets incoming inventory the jave takes the incoming and moves it to a table called tblinventory when i enter new item it does what it is supposed to do. however if i try to enter another item that item does not make it to the tblinventory it does show on tblincoming. I also noticed that if i change my mind and close the input form for incoming i get an error 3134, the form is empty at this time.I tried to modify the code but them get error after entering every item. so went back to the initial error. when i debug it show the on the line DoCmd.RunSql (stringSQL) I have commented the line in the code.

推荐答案

不是你的问题的答案,但仍然您的代码中存在问题。



永远不要通过连接用户输入来构建SQL查询,它被命名为SQL注入,这对您的数据库很容易并且容易出错。

名称中的单引号和程序崩溃。如果像Brian O'Conner这样的用户输入可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]
Not an answer to your question , but still a problem in your code.

Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability.
SQL injection - Wikipedia[^]
SQL Injection[^]


这篇关于在空时关闭t表单时获取错误3134的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆