Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refresh an Access Query using VBA code in Excel

I have linked data in an excel workbook from a tabel in an Access database
The table has been created from a Make tabel query in the same database. For
the data in the Access table to be up to date I need to run the Access query.
Can somone suggest a suitable VBA code for me to run in Excel that will
connect to the Access database and run (refresh) the query.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Refresh an Access Query using VBA code in Excel

set a reference to the Microsoft Active data Obkject 2.6 Library
(Tools/references)

Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String

MyFile = "Risk.mdb"
SQL = "qsecurities" ' this is th ename of the query
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile
rst.Open SQL, con, adOpenStatic





"Peter G" wrote:

I have linked data in an excel workbook from a tabel in an Access database
The table has been created from a Make tabel query in the same database. For
the data in the Access table to be up to date I need to run the Access query.
Can somone suggest a suitable VBA code for me to run in Excel that will
connect to the Access database and run (refresh) the query.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Refresh an Access Query using VBA code in Excel

Set the reference to the Microsoft ActiveX data as you suggested, entered
the path and name of my mdb-file and also the name of the query. Ran the code
but no readcion in my Access database.

-Does the code you have suggested run the query in the backgound?
-The Access make table query requires some interaction confirming that data
is to be overwritten, a new fil will be created etc, does your code
automatically conform all the questions?
Is it necessary to "close down" Access after runnuing the query?

/PG


"Patrick Molloy" wrote:

set a reference to the Microsoft Active data Obkject 2.6 Library
(Tools/references)

Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String

MyFile = "Risk.mdb"
SQL = "qsecurities" ' this is th ename of the query
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile
rst.Open SQL, con, adOpenStatic





"Peter G" wrote:

I have linked data in an excel workbook from a tabel in an Access database
The table has been created from a Make tabel query in the same database. For
the data in the Access table to be up to date I need to run the Access query.
Can somone suggest a suitable VBA code for me to run in Excel that will
connect to the Access database and run (refresh) the query.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Refresh an Access Query using VBA code in Excel

Hi ... this doesn't open the access database as if you were using Microsift
Access. Its opens a connection to the database that allows to you to run TSQL
statements - and these can be the usual --- data retrieval, inserting amendig
etc, or commands that do things likeadding tables, or addign columns to
tables, and so on. It cannot be interactive as the database would normally be
in a server room and not in your own pc.
As it only opens a connection, there's no Access Application to close. Note
though that if you do have Access open with this database, then you might
inadvertently put a lock on the table if you have it open, Locks prevent two
or more users amendign the same record in a table. Locks also occur if, as
can easily happen with Access, the op edits a table. Another application,
like Excel, running sql against the database will not be able to read the
table while its being edited...and it will wait for euther a specified tome
out, or a default time out, before returning the code to the applicatios
control.

"Peter G" wrote:

Set the reference to the Microsoft ActiveX data as you suggested, entered
the path and name of my mdb-file and also the name of the query. Ran the code
but no readcion in my Access database.

-Does the code you have suggested run the query in the backgound?
-The Access make table query requires some interaction confirming that data
is to be overwritten, a new fil will be created etc, does your code
automatically conform all the questions?
Is it necessary to "close down" Access after runnuing the query?

/PG


"Patrick Molloy" wrote:

set a reference to the Microsoft Active data Obkject 2.6 Library
(Tools/references)

Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String

MyFile = "Risk.mdb"
SQL = "qsecurities" ' this is th ename of the query
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile
rst.Open SQL, con, adOpenStatic





"Peter G" wrote:

I have linked data in an excel workbook from a tabel in an Access database
The table has been created from a Make tabel query in the same database. For
the data in the Access table to be up to date I need to run the Access query.
Can somone suggest a suitable VBA code for me to run in Excel that will
connect to the Access database and run (refresh) the query.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Refresh an Access Query using VBA code in Excel

This is a little strange! Thanks for your explanations regarding
interactivity, locking etc.
I have still not had any luck with the code. I have inserted a breakpoint in
the code and checked that the values of the variables (path, sql text) are
correct. I have tried running the code with Access running and also with it
closed down. Can you give me some suggestions how to try to trace what I am
doing incorrectly?

/PG

"Patrick Molloy" wrote:

Hi ... this doesn't open the access database as if you were using Microsift
Access. Its opens a connection to the database that allows to you to run TSQL
statements - and these can be the usual --- data retrieval, inserting amendig
etc, or commands that do things likeadding tables, or addign columns to
tables, and so on. It cannot be interactive as the database would normally be
in a server room and not in your own pc.
As it only opens a connection, there's no Access Application to close. Note
though that if you do have Access open with this database, then you might
inadvertently put a lock on the table if you have it open, Locks prevent two
or more users amendign the same record in a table. Locks also occur if, as
can easily happen with Access, the op edits a table. Another application,
like Excel, running sql against the database will not be able to read the
table while its being edited...and it will wait for euther a specified tome
out, or a default time out, before returning the code to the applicatios
control.

"Peter G" wrote:

Set the reference to the Microsoft ActiveX data as you suggested, entered
the path and name of my mdb-file and also the name of the query. Ran the code
but no readcion in my Access database.

-Does the code you have suggested run the query in the backgound?
-The Access make table query requires some interaction confirming that data
is to be overwritten, a new fil will be created etc, does your code
automatically conform all the questions?
Is it necessary to "close down" Access after runnuing the query?

/PG


"Patrick Molloy" wrote:

set a reference to the Microsoft Active data Obkject 2.6 Library
(Tools/references)

Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String

MyFile = "Risk.mdb"
SQL = "qsecurities" ' this is th ename of the query
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile
rst.Open SQL, con, adOpenStatic





"Peter G" wrote:

I have linked data in an excel workbook from a tabel in an Access database
The table has been created from a Make tabel query in the same database. For
the data in the Access table to be up to date I need to run the Access query.
Can somone suggest a suitable VBA code for me to run in Excel that will
connect to the Access database and run (refresh) the query.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Refresh an Access Query using VBA code in Excel

Still trying to get this coed working and have arrived at the following,
which perhaps helps

1. The "Open.con" line needed a semi-colon at the end of code line.
2. If I replace the varialble sql with "SELECT Levfakt.Levnummer,
Levfakt.Fakturadat INTO AAA_Tabell FROM Levfakt" instead of the name of the
Access Query the code will actually create a table and fill it with data,
however the second time I run the code I get an error advising that the table
alread exists.

Any suggestions regarding the Query name issue?

/PG



"Peter G" wrote:

This is a little strange! Thanks for your explanations regarding
interactivity, locking etc.
I have still not had any luck with the code. I have inserted a breakpoint in
the code and checked that the values of the variables (path, sql text) are
correct. I have tried running the code with Access running and also with it
closed down. Can you give me some suggestions how to try to trace what I am
doing incorrectly?

/PG

"Patrick Molloy" wrote:

Hi ... this doesn't open the access database as if you were using Microsift
Access. Its opens a connection to the database that allows to you to run TSQL
statements - and these can be the usual --- data retrieval, inserting amendig
etc, or commands that do things likeadding tables, or addign columns to
tables, and so on. It cannot be interactive as the database would normally be
in a server room and not in your own pc.
As it only opens a connection, there's no Access Application to close. Note
though that if you do have Access open with this database, then you might
inadvertently put a lock on the table if you have it open, Locks prevent two
or more users amendign the same record in a table. Locks also occur if, as
can easily happen with Access, the op edits a table. Another application,
like Excel, running sql against the database will not be able to read the
table while its being edited...and it will wait for euther a specified tome
out, or a default time out, before returning the code to the applicatios
control.

"Peter G" wrote:

Set the reference to the Microsoft ActiveX data as you suggested, entered
the path and name of my mdb-file and also the name of the query. Ran the code
but no readcion in my Access database.

-Does the code you have suggested run the query in the backgound?
-The Access make table query requires some interaction confirming that data
is to be overwritten, a new fil will be created etc, does your code
automatically conform all the questions?
Is it necessary to "close down" Access after runnuing the query?

/PG


"Patrick Molloy" wrote:

set a reference to the Microsoft Active data Obkject 2.6 Library
(Tools/references)

Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String

MyFile = "Risk.mdb"
SQL = "qsecurities" ' this is th ename of the query
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyFile
rst.Open SQL, con, adOpenStatic





"Peter G" wrote:

I have linked data in an excel workbook from a tabel in an Access database
The table has been created from a Make tabel query in the same database. For
the data in the Access table to be up to date I need to run the Access query.
Can somone suggest a suitable VBA code for me to run in Excel that will
connect to the Access database and run (refresh) the query.

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
Import query from access into excel via vba, but will not refresh newyears Excel Programming 0 May 4th 08 06:58 AM
Query Refresh code NickHK Excel Programming 0 December 7th 06 08:17 AM
Link Access query to refresh an EXCEL file Dancer4u New Users to Excel 1 January 13th 05 05:24 PM
Web Query Logins and Access Refresh [email protected] Excel Programming 3 April 12th 04 10:46 PM
Code to run an Access query from Excel Kelly[_7_] Excel Programming 3 January 17th 04 04:12 PM


All times are GMT +1. The time now is 04:38 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"