the*_*i11 2 excel ms-access vba
我正在为访问数据库编写一个sql语句,无论输入如何,都将返回一个唯一值.我正在使用此代码但是我在执行语句中遇到类型不匹配.
strSQL = "SELECT FilePath " _
& "FROM ToolFiles " _
& "WHERE Project_Num = '" & theSelectedProj & "'" _
& "AND Tool_Name = '" & theSelectedProjName & "'"
filePath = cn.Execute(strSQL)
Run Code Online (Sandbox Code Playgroud)
有没有办法从sql语句返回一个字符串?
谢谢
快速回答是否.ADO Execute()方法返回一个记录集对象,您需要将其读入字符串变量.这样的事情应该这样做:
Dim rs As ADODB.Recordset
....
Set rs = cn.Execute(strSQL)
If Not (rs Is Nothing) Then
With rs
If Not (.BOF) And Not (.EOF) Then
strFilePath = Format$(.Fields(1).Value)
End If
End With
End If
Run Code Online (Sandbox Code Playgroud)