Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 3rd, 2007, 01:51 AM
Registered User
 
Join Date: Jun 2007
Location: fremont, CA, .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.