我在MS Access中有一个表,我正在尝试选择数据。该表中有一个userID,因此我只想选择具有特定用户ID的信息。我正在做的是将userID传递给访问中的表单,所以我希望能够在我的查询中引用frm字段。当我在下面运行此代码时,它告诉我参数太少了。
dim rs1 as DAO.recordset
strSQL = "Select * from [dbo_tempDetail] where [userID] = [Forms]![frmUserInfo]![txtCLIENTID];"
Set rs1 = CurrentDb.OpenRecordset(strSQL, , dbOpenDynamic)
rCount = rs1.RecordCount
这里有什么问题
编辑2
strSQL = "Select * from [dbo_tempDetail] where userID = '" & [Forms]![frmUserInfo]![txtClientID] & "' "
Set rs1 = CurrentDb.OpenRecordset(strSQL, , dbOpenDynamic)
rCount = rs1.RecordCount
答案 0 :(得分:4)
SELECT语句必须是使用表单值的串联字符串。 VBA可能知道[Forms]![frmUserInfo]![txtCLIENTID]
是什么,但SELECT不知道。
strSQL = "Select * from [dbo_tempDetail] where [userID] = " & _
[Forms]![frmUserInfo]![txtCLIENTID] & ";"
'might have to quote the txtCLIENTID value
strSQL = "Select * from [dbo_tempDetail] where [userID] = '" & _
[Forms]![frmUserInfo]![txtCLIENTID] & "';"