dbOpenDynaset-'Object variable or With block variable not set'

dbOpenDynaset - 'Object variable or With block variable not set'

我有一个名为 'qryAddressBook' 的查询。我希望能够垂直循环遍历名为 'Client_Address' 的特定字段中的记录,并在 table 'tblClient'.

的单行中显示这些记录

我过去用 tables 使用“Set rs = dbs.OpenRecordset(“tblAddressBook”, dbOpenTable)”没有问题....

...我遵循了 Access Database.OpenRecordset 方法 (DAO) 中显示的语法:https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/database-openrecordset-method-dao

我继续收到一条错误消息 'Object variable or With block variable not set',它突出显示了我的代码中的以下文本:

Set rs = dbs.OpenRecordset("qrySpecificNCR", dbOpenDynaset)

这是我的总代码:

DoCmd.OpenQuery "qryAddressBook"

Dim dbs As DAO.Database
Dim rs As Recordset
Dim SeqNum As Integer

Set dbs = CurrentDb

SeqNum = 1

Set rs = dbs.OpenRecordset("qryAddressBook", dbOpenDynaset)

Do Until rs.EOF

    Dim srtAddress As String
    srtAddress = rs.Fields("Client_Address").Value

    Dim strSQLAddress As String
    strSQLAddress = "UPDATE tblClient SET " & SeqNum & " = '" & srtAddress & "' WHERE Record = 1;"

        DoCmd.RunSQL strSQLAddress 

        SeqNum = SeqNum + 1

rs.MoveNext

Loop

我仍然不明白显式部分...但是我发现了错误。

我的 qryAddressBook 有以下代码行:

FROM qryGlobalAddress
WHERE (((qryAddress.Client) = [FORMS]![frmClientAddress]![CmbClientName]));

我正在从组合框中推送表单参数。当我将其更改为特定的客户端名称时,例如:

FROM qryGlobalAddress
WHERE (qryAddress.Client) = 'Smith, John';

然后 Set rs = dbs.OpenRecordset("qryAddressBook", dbOpenDynaset) 工作得很好。

现在的问题是我需要找出一种将表单参数推送到查询的方法。 :(

连接表格组合值

"FROM qryGlobalAddress WHERE (((qryAddress.Client) = '" & [FORMS]![frmClientAddress]![CmbClientName] & "'));"