我对MS Access和VBA比较陌生。我正在尝试为此数据库执行一些代码并获取错误消息'运行时错误3061.参数太少。当它到达OpenRecordSet子句时,预期为1“。
我一直在研究和查看这几天,但无法弄清楚错误的原因。我知道在关闭表单时,错误是在WHERE子句中的SELECT中。
奇怪的是,当我将条件更改为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
答案 0 :(得分:1)
SelStr = "SELECT Record_Num FROM User_Log WHERE Record_Num = " & _
Record_Match_Temp
如果字段不是数字,请在Record_Match_Temp
周围添加单引号。