LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Import to excel Access database directly to a variable (not using

In Patrick's code, he is writing the information to the worksheet. You
could put it in an array with something like

Dim v as Variant

v = Application.Transpose(rst)

or work with rst directly.

--
Regards,
Tom Ogilvy

"Patrick Molloy" wrote in message
...
sure is -- help covers it.
In the IDE set a reference to the Microsoft ActiveX Data Obects Library
you probably have v2.7

Adapt the code below, which should be pasted into a standatd module.
The variable MyFile is assigned the Access Databas enaem that I'm using.

You
should replace this with the full path etc of the Access database that you
want to use
You should also edit the SQL script accordingly...as my demo is pretty
simple, so is my sql
run the code and a connection is made to the database, the recordset in
memory gets populated according to the sql script. From the recordset

fields,
the field names are dropped intio the sheet as table headers and finally

the
data is copied directlyto the sheet



Option Explicit

Sub LoadDataFromAccess()
Dim MyFile As String
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String
Dim i As Long

MyFile = "Risk.mdb"
SQL = "SELECT * FROM BondTable"

con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile

rst.Open SQL, con, adOpenStatic

Cells.Clear

For i = 0 To rst.Fields.Count - 1
Cells(1, i + 1).Value = rst.Fields(i).Name
Next

Range("A2").CopyFromRecordset rst

rst.Close
con.Close

Set rst = Nothing
Set con = Nothing

End Sub

"internacio" wrote:


Hi all,

I would like to know if itīs possible to import data from access using
directly a variable in VBA excel instead of pasting all values in my
worksheet.

Thanks a lot.


--
internacio
------------------------------------------------------------------------
internacio's Profile:

http://www.excelforum.com/member.php...o&userid=30960
View this thread:

http://www.excelforum.com/showthread...hreadid=506308




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import into Access from Excel, passing a variable for the field... [email protected] Excel Worksheet Functions 1 April 12th 07 09:44 AM
Database query to import from Access to Excel David T Excel Discussion (Misc queries) 0 August 31st 06 07:12 PM
How to import multiple sheet of excel into Access database to a diffrent tables?? baka Excel Discussion (Misc queries) 0 July 6th 06 05:48 AM
Excel error while trying to import data from an Access database - MSQRY32.exe has generated errors X_HOBBES Excel Discussion (Misc queries) 0 March 15th 05 06:46 PM
Exporting data directly from Excel to an un-opened Access database using VBA Chris Dunigan Excel Programming 2 November 21st 03 03:16 PM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright Đ2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"