Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2007, 01:51 AM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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( _
        Connection:=sConn, _
        Destination:=Range("a1"), _
        Sql:=sSql)

    oQt.Refresh

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
        cnPubs.Open sConn

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?

Mike





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
Saving an excel file in Access VBA theboylatham Access VBA 1 August 19th, 2005 08:14 AM
Excel VBA - Access database push to users dfeuerborn Excel VBA 1 August 19th, 2005 02:50 AM
Excel Workbook created from Access VBA clueless_may Access VBA 0 June 8th, 2004 09:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.