在访问数据库上使用select查询

问题描述 投票:0回答:1

首先,我试图使用执行选择查询,返回错误类型不匹配。然后在阅读了一些有趣的东西后,我发现openrecordset就是诀窍。

现在我遇到openrecordset问题,因为它只返回查询而不是选定的值。下面是我的代码:

Dim sql As String
Dim rs As DAO.Recordset

      ' this will loop through each cell in column I until end
    For x = 1 To NumRows

       sql = "select Email from Salesforce where ID =" & ActiveCell.Value
       Set rs = oDB.OpenRecordset(sql, dbOpenDynaset)
       ActiveCell.Offset(0, 13).Value = rs

所以ActiveCell.Offset(0, 13).Value = sql只是插入来自Salesforce的精选电子邮件,其中ID等于ActiveCell.Value

database vba ms-access
1个回答
0
投票

尝试使用:

 ActiveCell.Offset(0, 13).CopyFromRecordset rs
© www.soinside.com 2019 - 2024. All rights reserved.