Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Open Access from Excel

I currently have code in Excel VBA that pulls data from Access in my Excel
worksheet. However, it runs about 10 times faster if Access is already open.
And (I'm not sure of this), I think it helps if an Access query is open and
in design view.

Can I have the code to:
1. Open Access database XXXX.mdb, if it is not already open
2. Open the query YYYY in design view
3. Ensure that the Excel worksheet is still active

Hope this isn't a big ask - thanks very much in advance

regards
Daniel Bonallack
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Open Access from Excel

Daniel,
How are you pulling the data into excel ?

NickHK

"Daniel Bonallack" wrote in
message ...
I currently have code in Excel VBA that pulls data from Access in my Excel
worksheet. However, it runs about 10 times faster if Access is already

open.
And (I'm not sure of this), I think it helps if an Access query is open

and
in design view.

Can I have the code to:
1. Open Access database XXXX.mdb, if it is not already open
2. Open the query YYYY in design view
3. Ensure that the Excel worksheet is still active

Hope this isn't a big ask - thanks very much in advance

regards
Daniel Bonallack



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Open Access from Excel

Hi Nick

Thanks for responding. I'm using VBA code in Excel to run an SQL query on
the closed Access database, and import the data into Excel.

Do you need me to be more specific? I can copy in the code if you want, but
it's quite long.

Daniel


"NickHK" wrote:

Daniel,
How are you pulling the data into excel ?

NickHK

"Daniel Bonallack" wrote in
message ...
I currently have code in Excel VBA that pulls data from Access in my Excel
worksheet. However, it runs about 10 times faster if Access is already

open.
And (I'm not sure of this), I think it helps if an Access query is open

and
in design view.

Can I have the code to:
1. Open Access database XXXX.mdb, if it is not already open
2. Open the query YYYY in design view
3. Ensure that the Excel worksheet is still active

Hope this isn't a big ask - thanks very much in advance

regards
Daniel Bonallack




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Open Access from Excel

Daniel,
You using VBA with ADO recordset or Excel's DataGet External data
functionality.
Just post the opening code.

NickHK

"Daniel Bonallack" wrote in
message ...
Hi Nick

Thanks for responding. I'm using VBA code in Excel to run an SQL query on
the closed Access database, and import the data into Excel.

Do you need me to be more specific? I can copy in the code if you want,

but
it's quite long.

Daniel


"NickHK" wrote:

Daniel,
How are you pulling the data into excel ?

NickHK

"Daniel Bonallack" wrote in
message ...
I currently have code in Excel VBA that pulls data from Access in my

Excel
worksheet. However, it runs about 10 times faster if Access is

already
open.
And (I'm not sure of this), I think it helps if an Access query is

open
and
in design view.

Can I have the code to:
1. Open Access database XXXX.mdb, if it is not already open
2. Open the query YYYY in design view
3. Ensure that the Excel worksheet is still active

Hope this isn't a big ask - thanks very much in advance

regards
Daniel Bonallack






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Open Access from Excel

I guess this would be the basic code.
So I want to check that Access is open, and preferably have a query open in
design view
Thanks!

Sub GetBaseData()

Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset

DBFullName = "xxx.mdb"


' Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct


With Recordset
Src = "daniel's sql query code"
.Open Source:=Src, ActiveConnection:=Connection

Sheets("data").Select

' Write the field names
For Col = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next

' Write the recordset
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With

Set Recordset = Nothing
Connection.Close
Set Connection = Nothing

End Sub

"NickHK" wrote:

Daniel,
You using VBA with ADO recordset or Excel's DataGet External data
functionality.
Just post the opening code.

NickHK

"Daniel Bonallack" wrote in
message ...
Hi Nick

Thanks for responding. I'm using VBA code in Excel to run an SQL query on
the closed Access database, and import the data into Excel.

Do you need me to be more specific? I can copy in the code if you want,

but
it's quite long.

Daniel


"NickHK" wrote:

Daniel,
How are you pulling the data into excel ?

NickHK

"Daniel Bonallack" wrote in
message ...
I currently have code in Excel VBA that pulls data from Access in my

Excel
worksheet. However, it runs about 10 times faster if Access is

already
open.
And (I'm not sure of this), I think it helps if an Access query is

open
and
in design view.

Can I have the code to:
1. Open Access database XXXX.mdb, if it is not already open
2. Open the query YYYY in design view
3. Ensure that the Excel worksheet is still active

Hope this isn't a big ask - thanks very much in advance

regards
Daniel Bonallack








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Open Access from Excel

Daniel,
I see no reason why you would need to open Access; you are using Jet/OLEDB
to query the .mdb, so Access is irrelevant.
The source of the apparent delay lies elsewhere.

NickHK

"Daniel Bonallack" wrote in
message ...
I guess this would be the basic code.
So I want to check that Access is open, and preferably have a query open

in
design view
Thanks!

Sub GetBaseData()

Dim DBFullName As String
Dim Cnct As String, Src As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset

DBFullName = "xxx.mdb"


' Open the connection
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct


With Recordset
Src = "daniel's sql query code"
.Open Source:=Src, ActiveConnection:=Connection

Sheets("data").Select

' Write the field names
For Col = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next

' Write the recordset
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With

Set Recordset = Nothing
Connection.Close
Set Connection = Nothing

End Sub

"NickHK" wrote:

Daniel,
You using VBA with ADO recordset or Excel's DataGet External data
functionality.
Just post the opening code.

NickHK

"Daniel Bonallack" wrote in
message ...
Hi Nick

Thanks for responding. I'm using VBA code in Excel to run an SQL

query on
the closed Access database, and import the data into Excel.

Do you need me to be more specific? I can copy in the code if you

want,
but
it's quite long.

Daniel


"NickHK" wrote:

Daniel,
How are you pulling the data into excel ?

NickHK

"Daniel Bonallack" wrote

in
message ...
I currently have code in Excel VBA that pulls data from Access in

my
Excel
worksheet. However, it runs about 10 times faster if Access is

already
open.
And (I'm not sure of this), I think it helps if an Access query

is
open
and
in design view.

Can I have the code to:
1. Open Access database XXXX.mdb, if it is not already open
2. Open the query YYYY in design view
3. Ensure that the Excel worksheet is still active

Hope this isn't a big ask - thanks very much in advance

regards
Daniel Bonallack








Reply
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
open access from excel ? יריב החביב Excel Discussion (Misc queries) 2 July 21st 08 01:49 PM
Excel cannot open Access MDB Neva Excel Discussion (Misc queries) 0 April 4th 05 08:35 PM
help to open pwd Excel from Access Ed Excel Programming 1 June 30th 04 01:56 PM
Open Access db from Excel Will[_7_] Excel Programming 0 May 13th 04 09:32 PM
Open Excel from access John[_46_] Excel Programming 4 September 8th 03 05:44 PM


All times are GMT +1. The time now is 05:50 PM.

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"