0

我对 MS Access 和 VBA 比较陌生。我正在尝试为此数据库编写一些代码并收到错误消息“运行时错误 3061。参数太少。到达 OpenRecordSet 子句时应为 1"。

我已经研究并查看了几天,但无法找出错误的原因。我知道当表单被关闭时,错误出现在 SELECT 中,特别是在 WHERE 子句中。

奇怪的是,当我将条件更改为 Record_Num = 2 或任何特定数字时,它似乎可以工作,但我需要使用 Record_Match_Temp 变量。

任何帮助将不胜感激。提前致谢。这是代码

Option Compare Database
    Dim Record_Match_Temp As Integer
    Dim Logged_Now As String


Private Sub Form_Close()
    Dim db2 As Database
    Dim rs2 As Recordset2
    Dim SelStr As String

    Set db2 = CurrentDb()
    SelStr = "SELECT Record_Num FROM User_Log WHERE Record_Num = Record_Match_Temp"

    Set rs2 = db2.OpenRecordset(SelStr)

 End Sub

Private Sub Form_Load()
    Form_User_Name = Environ("UserName")
    Logged_Now = Now()

    Dim db As Database
    Dim rs As Recordset
    Set db = CurrentDb()

    Set rs = db.OpenRecordset("Select * from [User_Log]")

    rs.AddNew
    rs![Log_User_Name] = Environ("UserName")
    rs![Logged_Computer] = Environ("ComputerName")
    rs![Logged_In] = Logged_Now
    rs![Record_Match] = rs![Record_Num]
    Record_Match_Temp = rs![Record_Num]
    ' rs![Logged_Out] = Now()
    rs.Update

 End Sub



Private Sub Form_Timer()
  Date_Time.Requery

End Sub
4

1 回答 1

1
SelStr = "SELECT Record_Num FROM User_Log WHERE Record_Num = " & _
                                                  Record_Match_Temp

Record_Match_Temp如果字段不是数字,请在周围添加单引号。

于 2013-05-17T20:16:22.767 回答