Hey, I am trying to pull a query from an access database into excel through VBA.
This is the code I am using:
Public Sub foo()
Dim cn As Object
Dim rs As Object
Dim strSql As String
Dim strConnection As String
Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=G:\Sales Analysis\dbo.Service_IoD.accdb"
strSql = "SELECT Count(*) FROM Qry1;"
cn.Open strConnection
Set rs = cn.Execute(strSql)
MsgBox rs.Fields(0) & " rows in Qry1"
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
However when I run the macro i get
Run-time error '-2147217904 (80040e10)':
No Value Given for one or more required parameters.
The paramiter is set:
Sheets("Home").Range("A1").Value
Just cannot work out where I would put the code?
Any help would be much appreciated.
Bookmarks