Hello everyone,
I'm trying to run an SQL statement into an Access database from Excel. Here is the code I have so far:
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Sub DoSomething()
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "U:\test2.mdb"
End With
strSql = "select * from Yield"
With rs
Set .ActiveConnection = cnn
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open strSql
End With
If rs.EOF <> True Then
Debug.Print rs(1)
End If
End Sub
The following code runs perfectly fine. The recordset comes back with the statement results. However, when I try to put a 'Where' clause into the SQL statement like so:
strSql = "select * from Yield where Section = 'EPI'"
... the whole thing blows up and gives me an Automation Error and an Unspecified Error. The field names are all spelled correctly. The connection and cursor types seem fine as well since it returns results WITHOUT the 'Where' clause. Anyone have any ideas??? Any feedback would be greatly appreciated.
Bookmarks