INSERT into Access Database from VBA for Excel
I am trying to read and write to an Access Database (such as Northwind) Everything I have found deals with Query Tables. I just need to access small bits at a time and write back to them. I cannot figure out how to INSERT into a database using a query table object. Using a different method, the main problem is that I cannot connect to the Access Database as above. I am trying the following connection string:
sConn = "ODBC;DSN=MS Access 97 Database;"
sConn = sConn & "DBQ=C:\Program Files\Microsoft Office\"
sConn = sConn & "Office11\Samples\Northwind.mdb;"
sConn = sConn & "DefaultDir=C:\Program Files\Microsoft Office\Office11\Samples;"
sConn = sConn & "DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
This works if I am opening a connection through a Query Table like this:
Set oQt = ActiveSheet.QueryTables.Add( _
It does not work if I am trying to open a connection like this, which works for me accessing a SQL Server database:
' Create a connection object.
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
When I try to create the connection with the cnPubs.Open sconn line, I get an error stating:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Why is the data source name sufficient in the first case with the Query Tables, but not in the second case?