ODBC驱动程序不支持EXCEL VBA中请求的属性

时间:2017-11-09 03:51:22

标签: excel vba excel-vba

我有这个驱动程序问题的问题,这里是我的代码,在我以前的工作表中工作正常,但当我复制代码并将其传输到此处时,错误弹出“运行时错误ODBC驱动程序不支持请求的属性“似乎是什么问题?

Dim strSQL As String
Dim cnn As ADODB.Connection



Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

strSQL = "SELECT * FROM [Data$] WHERE "
If cmbGroup.Text <> "" Then
strSQL = strSQL & " [Group Name]='" & cmbGroup.Text & "'"
End If

If cmbPolicy.Text <> "" Then
If cmbGroup.Text <> "" Then
strSQL = strSQL & " AND [Policy Status]='" & cmbPolicy.Text & "'"
Else
strSQL = strSQL & " [Policy Status]='" & cmbPolicy.Text & "'"
End If
End If

If cmbOfficer.Text <> "" Then
If cmbGroup.Text <> "" Or cmbPolicy.Text <> "" Then
strSQL = strSQL & " AND [Case Officer]='" & cmbOfficer.Text & "'"
Else
strSQL = strSQL & " [Case Officer]='" & cmbOfficer.Text & "'"
End If
End If

If cmbGroup.Text <> "" Or cmbPolicy.Text <> "" Or cmbOfficer.Text <> "" Then

Set cnn = New ADODB.Connection



OpenDB cnn


rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic 'this code gets the error




Set cnn = Nothing




If rs.RecordCount > 0 Then
Sheets("Company View").Visible = True
Sheets("Company View").Select
Range("dataSet").Select
Range(Selection, Selection.End(xlDown)).ClearContents

ActiveCell.CopyFromRecordset rs
With Range("dataSet")
.Select
.Copy
End With
Range(Selection, Selection.End(xlDown)).PasteSpecial (xlPasteFormats)
Application.CutCopyMode = False

Else
MsgBox "I was not able to find any matching records.", vbExclamation + 
vbOKOnly
Set rs = Nothing
End If
Exit Sub

End If

这是我的ADODB连接

Private Sub OpenDB(ByRef cnn As ADODB.Connection)

cnn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, 
*.xlsm, *.xlsb)};DBQ=" & _
ActiveWorkbook.Path & Application.PathSeparator & ActiveWorkbook.Name
cnn.Open

End Sub

谢谢!

0 个答案:

没有答案