PDA

View Full Version : Excel wants to talk to Access



msa969
06-21-2010, 07:26 AM
Hello I am trying to connect to a MS Access database using Excel.
I have put the database on the D drive of my PC. I am using Access 2007 and Excel 2007. The database is located here and is called:
D:\test.accdb. The table's name is tbDataSumproduct and the three columns(fields) containing the data are Month, Product and City


Sub proSQLQuery1()
Dim varConnection
Dim varSQL
Range("A1").CurrentRegion.ClearContents
varConnection = "ODBC; DSN=MS Access Database;DBQ=C:\test.accdb; Driver={Driver do Microsoft Access (*.accdb)}"
varSQL = "SELECT tbDataSumproduct.Month, tbDataSumproduct.Product, tbDataSumproduct.City FROM tbDataSumproduct"
With ActiveSheet.QueryTables.Add(Connection:=varConnection, Destination:=ActiveSheet.Range("A1"))
.CommandText = varSQL
.Name = "Query-39008"
.Refresh BackgroundQuery:=False
End With
End Sub



---------------------------
ODBC Microsoft Access Driver Login Failed
---------------------------
Unrecognized database format 'D:\test.accdb'.
---------------------------
OK Cancel
---------------------------

Also this occurs Run time error '-2147217842 (80040e4e)': Automation error

Why is it not working?
Note I have not put a username and password but it is also requesting on
What am i do wrong?