Wrox Programmer Forums
|
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 January 16th, 2007, 03:26 AM
Authorized User
 
Join Date: Apr 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default connect to access

Hi,

I would like to connect to an access database via Excel and use the data from a query into a varable within excel. How do I connect to access?

rgrds,

Paul.

 
Old January 16th, 2007, 04:07 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Here is the way to connect
Set Cn = New ADODB.Connection
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb;Persist Security Info=False"
Cn.ConnectionTimeout = 40
Cn.Open



Set RS = New ADODB.Recordset

    sQuery = "Select * From Table"

    RS.ActiveConnection = Cn
    RS.Source = sQuery
    RS.Open

    ' --------------------------------------------
' Write your code to copy the values to Excel

For more info on connection, refer http://www.connectionstrings.com/?carrier=access2007


Cheers,
Shasur


http://www.vbadud.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Connect to Access Dragonist ADO.NET 22 February 23rd, 2007 07:17 PM
Connect textbox to Access field aya_hbkenshin04 Classic ASP Databases 0 May 3rd, 2006 12:52 PM
Using DSN To Connect Access Dabase hunzian78@yahoo.com ASP.NET 1.0 and 1.1 Basics 0 March 22nd, 2006 07:26 AM
Connect to existing access page Ronaldx Java Basics 0 November 9th, 2005 08:38 PM
Cannot Connect to Access DB mjmfgm Classic ASP Databases 8 March 9th, 2004 07:34 PM





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