创建记录集

时间:2016-03-24 02:19:35

标签: vba ms-access access-vba

我正在尝试从我在Access 2013中创建的查询创建记录集。我从查询中复制了SQL代码,并将其用作字符串。我一直在

  

运行时错误3061.参数太少。预期1.

我还尝试调用保存的查询,我得到了同样的错误。这就是我所拥有的:

Dim SQLwTRN As String
Dim Db As DAO.Database
Dim RecSet As DAO.Recordset

Set Db = CurrentDb
SQLwTRN = "SELECT Client.ID, Client.FirstName, Client.MiddleInitial, Client.Surname, Client.Address, Client.CellPhoneNumber, Client.EmailAddress, Client.TRN 
FROM Client WHERE (((Client.ID)=[Forms]![frmMember_Lookup]![txtbxMLmemnumber]));"

Debug.Print SQLwTRN

Set RecSet = Db.OpenRecordset(SQLwTRN)

' Debug.Print RecSet   ' <-- this won't work - RecSet is an Object

1 个答案:

答案 0 :(得分:0)

SQL代码无法访问表单,因此您可以连接以下值:

FROM Client WHERE Client.ID = " & [Forms]![frmMember_Lookup]![txtbxMLmemnumber] & ";"