MS Access db错误

时间:2015-01-09 19:50:37

标签: database ms-access access-vba

我在这一行得到的错误3061参数太少

Set rs = db.OpenRecordset(strSQL)

这是完整的代码

Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset ''Requires reference to Microsoft DAO x.x Library
Set db = CurrentDb()
MsgBox Me.LName
MsgBox Me.EmpID
strSQL = "SELECT LastName AS damn FROM [Employees]" & _
                 "WHERE [Employees].EmployeeID = Me.EmpID"
Debug.Print strSQL
Set rs = db.OpenRecordset(strSQL)
MsgBox rs!damn
Me.LName = rs!damn
MsgBox Me.LName
rs.Close
db.Close

1 个答案:

答案 0 :(得分:3)

我能想到的最好的是

"WHERE [Employees].EmployeeID = Me.EmpID" 

应该是

"WHERE [Employees].EmployeeID = " & Me.EmpID

另外,HansUp为您提供了一个很好的方法来解决这个问题。