PC Review


Reply
Thread Tools Rate Thread

Automate Query Runnung

 
 
=?Utf-8?B?QW5hbnRo?=
Guest
Posts: n/a
 
      6th Nov 2006
I have a Access Table that has 20 queries.

Query-1
Quert-2 etc upto Query-20

Can somebody help me with a small VB routine or Macro that would run all the
20 Queries at a strike of a key (just like we have DO command in Foxpro)
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      6th Nov 2006
Hi Ananth,

It's not clear to me whether or not your queries are all considered action
queries, but here is a procedure that should get you started for the most
common query types in Access. First, set a reference to the DAO Object
Library if it is not already set. Use version 3.6 for Access 2000/2002/2003,
or version 3.51 for Access 97. To check whether or not you already have this
reference set, open a new standard module. Then click on Tools > References.
If you find it checked, then just click on OK to dismiss this dialog. If not,
scroll down the list until you find it, and place a check mark in it to
select it. Then dismiss the references dialog box.

Copy the following code and paste it into your new module.
Notes:
1.) I removed the indentation from the SELECT Case, to help prevent word
wrap in a newsgroup message from splitting a line of code into two lines.

2.) The name of the table referenced is: tblQueries
The names of the queries are in a field named: QueryName

3.) I included a numeric field, indexed unique (no duplicates), which allows
one to specify a sort order. This field is named: RunOrder
This gives you the ability to easily change the order that queries are run,
without having to rename them to match a -number naming convention.

After pasting the code, click on Debug > Compile ProjectName, where
ProjectName is the name of your VBA project (likely the same name as your
database). Fix any compile errors before trying to do anything else.

To run the code, have your blinking mouse cursor anywhere within the
procedure. Then press the F5 button.


Option Compare Database
Option Explicit

Sub RunSavedQueries()
On Error GoTo ProcError

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strQueryName As String

Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT QueryName " _
& "FROM tblQueries ORDER BY RunOrder")

With rs
Do Until (.BOF Or .EOF) = True
strQueryName = rs("QueryName")
Set qdf = db.QueryDefs(strQueryName)

Debug.Print strQueryName, qdf.Type

Select Case qdf.Type
Case 0, 16, 128 'Select queries: 0=Select, 16=Crosstab, 128=Union
DoCmd.OpenQuery strQueryName
Case 32, 48, 80 'Action queries: 32=Delete, 48=Update/Append, 80=Make Table
db.Execute strQueryName, dbFailOnError
Case Else
'Do nothing for the present time.
End Select

rs.MoveNext
Loop
End With

ExitProc:
'Cleanup
On Error Resume Next
Set qdf = Nothing
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure RunSavedQueries..."
Resume ExitProc
End Sub



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"Ananth" wrote:

> I have a Access Table that has 20 queries.
>
> Query-1
> Quert-2 etc upto Query-20
>
> Can somebody help me with a small VB routine or Macro that would run all the
> 20 Queries at a strike of a key (just like we have DO command in Foxpro)

 
Reply With Quote
 
=?Utf-8?B?QW5hbnRo?=
Guest
Posts: n/a
 
      6th Nov 2006
Many Thanks for your elaborate reply. It is too techincal for me.

I am a novice in VB and in Access Macro.

I have a Access DB called Spend Data 2006 ,that has 5 Tables
Using Access Design Feature, I had created 20 Queries, which are titled
Query 1, Query 2, Query 3 etc…

The DB has a Master Table on which these 20 Queries work. Most of these
queries are update queries, that has run sequentially (starting from query1
and end by executing query 20, which is cross tab query that produces the
results)

What I meant was,I want a solution that will run the 20 queries
automatically, conclude with displaying the cross tab results (20th Query)



"Tom Wickerath" wrote:

> Hi Ananth,
>
> It's not clear to me whether or not your queries are all considered action
> queries, but here is a procedure that should get you started for the most
> common query types in Access. First, set a reference to the DAO Object
> Library if it is not already set. Use version 3.6 for Access 2000/2002/2003,
> or version 3.51 for Access 97. To check whether or not you already have this
> reference set, open a new standard module. Then click on Tools > References.
> If you find it checked, then just click on OK to dismiss this dialog. If not,
> scroll down the list until you find it, and place a check mark in it to
> select it. Then dismiss the references dialog box.
>
> Copy the following code and paste it into your new module.
> Notes:
> 1.) I removed the indentation from the SELECT Case, to help prevent word
> wrap in a newsgroup message from splitting a line of code into two lines.
>
> 2.) The name of the table referenced is: tblQueries
> The names of the queries are in a field named: QueryName
>
> 3.) I included a numeric field, indexed unique (no duplicates), which allows
> one to specify a sort order. This field is named: RunOrder
> This gives you the ability to easily change the order that queries are run,
> without having to rename them to match a -number naming convention.
>
> After pasting the code, click on Debug > Compile ProjectName, where
> ProjectName is the name of your VBA project (likely the same name as your
> database). Fix any compile errors before trying to do anything else.
>
> To run the code, have your blinking mouse cursor anywhere within the
> procedure. Then press the F5 button.
>
>
> Option Compare Database
> Option Explicit
>
> Sub RunSavedQueries()
> On Error GoTo ProcError
>
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
> Dim qdf As DAO.QueryDef
> Dim strQueryName As String
>
> Set db = CurrentDb()
> Set rs = db.OpenRecordset("SELECT QueryName " _
> & "FROM tblQueries ORDER BY RunOrder")
>
> With rs
> Do Until (.BOF Or .EOF) = True
> strQueryName = rs("QueryName")
> Set qdf = db.QueryDefs(strQueryName)
>
> Debug.Print strQueryName, qdf.Type
>
> Select Case qdf.Type
> Case 0, 16, 128 'Select queries: 0=Select, 16=Crosstab, 128=Union
> DoCmd.OpenQuery strQueryName
> Case 32, 48, 80 'Action queries: 32=Delete, 48=Update/Append, 80=Make Table
> db.Execute strQueryName, dbFailOnError
> Case Else
> 'Do nothing for the present time.
> End Select
>
> rs.MoveNext
> Loop
> End With
>
> ExitProc:
> 'Cleanup
> On Error Resume Next
> Set qdf = Nothing
> rs.Close: Set rs = Nothing
> db.Close: Set db = Nothing
> Exit Sub
> ProcError:
> MsgBox "Error " & Err.Number & ": " & Err.Description, _
> vbCritical, "Error in procedure RunSavedQueries..."
> Resume ExitProc
> End Sub
>
>
>
> Tom Wickerath
> Microsoft Access MVP
>
> http://www.access.qbuilt.com/html/ex...tributors.html
> http://www.access.qbuilt.com/html/search.html
> __________________________________________
>
> "Ananth" wrote:
>
> > I have a Access Table that has 20 queries.
> >
> > Query-1
> > Quert-2 etc upto Query-20
> >
> > Can somebody help me with a small VB routine or Macro that would run all the
> > 20 Queries at a strike of a key (just like we have DO command in Foxpro)

 
Reply With Quote
 
Armen Stein
Guest
Posts: n/a
 
      6th Nov 2006

I rarely recommend Access Macros for anything, but simply running a
series of queries is one thing they do well. Create a new Macro, and
add these lines:

SetWarnings No
OpenQuery Query1
OpenQuery Query2
etc...
SetWarning Yes

Note that the Yes, No, Query1, etc. are specified in the detail sheet
below, not on the statement itself.

The SetWarnings No statement turns off all the confirmation warnings
for your action queries. If you want to see those, delete that line
from your macro.

On Mon, 6 Nov 2006 03:51:02 -0800, Ananth
<(E-Mail Removed)> wrote:

>Many Thanks for your elaborate reply. It is too techincal for me.
>
>I am a novice in VB and in Access Macro.
>
>I have a Access DB called Spend Data 2006 ,that has 5 Tables
>Using Access Design Feature, I had created 20 Queries, which are titled
>Query 1, Query 2, Query 3 etc…
>
>The DB has a Master Table on which these 20 Queries work. Most of these
>queries are update queries, that has run sequentially (starting from query1
>and end by executing query 20, which is cross tab query that produces the
>results)
>
>What I meant was,I want a solution that will run the 20 queries
>automatically, conclude with displaying the cross tab results (20th Query)
>
>
>
>"Tom Wickerath" wrote:
>
>> Hi Ananth,
>>
>> It's not clear to me whether or not your queries are all considered action
>> queries, but here is a procedure that should get you started for the most
>> common query types in Access. First, set a reference to the DAO Object
>> Library if it is not already set. Use version 3.6 for Access 2000/2002/2003,
>> or version 3.51 for Access 97. To check whether or not you already have this
>> reference set, open a new standard module. Then click on Tools > References.
>> If you find it checked, then just click on OK to dismiss this dialog. If not,
>> scroll down the list until you find it, and place a check mark in it to
>> select it. Then dismiss the references dialog box.
>>
>> Copy the following code and paste it into your new module.
>> Notes:
>> 1.) I removed the indentation from the SELECT Case, to help prevent word
>> wrap in a newsgroup message from splitting a line of code into two lines.
>>
>> 2.) The name of the table referenced is: tblQueries
>> The names of the queries are in a field named: QueryName
>>
>> 3.) I included a numeric field, indexed unique (no duplicates), which allows
>> one to specify a sort order. This field is named: RunOrder
>> This gives you the ability to easily change the order that queries are run,
>> without having to rename them to match a -number naming convention.
>>
>> After pasting the code, click on Debug > Compile ProjectName, where
>> ProjectName is the name of your VBA project (likely the same name as your
>> database). Fix any compile errors before trying to do anything else.
>>
>> To run the code, have your blinking mouse cursor anywhere within the
>> procedure. Then press the F5 button.
>>
>>
>> Option Compare Database
>> Option Explicit
>>
>> Sub RunSavedQueries()
>> On Error GoTo ProcError
>>
>> Dim db As DAO.Database
>> Dim rs As DAO.Recordset
>> Dim qdf As DAO.QueryDef
>> Dim strQueryName As String
>>
>> Set db = CurrentDb()
>> Set rs = db.OpenRecordset("SELECT QueryName " _
>> & "FROM tblQueries ORDER BY RunOrder")
>>
>> With rs
>> Do Until (.BOF Or .EOF) = True
>> strQueryName = rs("QueryName")
>> Set qdf = db.QueryDefs(strQueryName)
>>
>> Debug.Print strQueryName, qdf.Type
>>
>> Select Case qdf.Type
>> Case 0, 16, 128 'Select queries: 0=Select, 16=Crosstab, 128=Union
>> DoCmd.OpenQuery strQueryName
>> Case 32, 48, 80 'Action queries: 32=Delete, 48=Update/Append, 80=Make Table
>> db.Execute strQueryName, dbFailOnError
>> Case Else
>> 'Do nothing for the present time.
>> End Select
>>
>> rs.MoveNext
>> Loop
>> End With
>>
>> ExitProc:
>> 'Cleanup
>> On Error Resume Next
>> Set qdf = Nothing
>> rs.Close: Set rs = Nothing
>> db.Close: Set db = Nothing
>> Exit Sub
>> ProcError:
>> MsgBox "Error " & Err.Number & ": " & Err.Description, _
>> vbCritical, "Error in procedure RunSavedQueries..."
>> Resume ExitProc
>> End Sub
>>
>>
>>
>> Tom Wickerath
>> Microsoft Access MVP
>>
>> http://www.access.qbuilt.com/html/ex...tributors.html
>> http://www.access.qbuilt.com/html/search.html
>> __________________________________________
>>
>> "Ananth" wrote:
>>
>> > I have a Access Table that has 20 queries.
>> >
>> > Query-1
>> > Quert-2 etc upto Query-20
>> >
>> > Can somebody help me with a small VB routine or Macro that would run all the
>> > 20 Queries at a strike of a key (just like we have DO command in Foxpro)

Armen Stein
Microsoft Access MVP
www.JStreetTech.com

 
Reply With Quote
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      6th Nov 2006
Hi Ananth,

> What I meant was,I want a solution that will run the 20 queries
> automatically, conclude with displaying the cross tab results (20th Query)


The solution I proposed will do exactly that. I even set up a test with each
type of query, and tested it first.

Can you tell me which part(s) of the answer I provided that you do not
understand? I don't necessarily expect you to understand the VBA code, but
you should be able to select the code, copy it (Ctrl C) and paste it into a
new module (Ctrl V).


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"Ananth" wrote:

> Many Thanks for your elaborate reply. It is too techincal for me.
>
> I am a novice in VB and in Access Macro.
>
> I have a Access DB called Spend Data 2006 ,that has 5 Tables
> Using Access Design Feature, I had created 20 Queries, which are titled
> Query 1, Query 2, Query 3 etc…
>
> The DB has a Master Table on which these 20 Queries work. Most of these
> queries are update queries, that has run sequentially (starting from query1
> and end by executing query 20, which is cross tab query that produces the
> results)
>
> What I meant was,I want a solution that will run the 20 queries
> automatically, conclude with displaying the cross tab results (20th Query)

 
Reply With Quote
 
=?Utf-8?B?VG9tIFdpY2tlcmF0aA==?=
Guest
Posts: n/a
 
      6th Nov 2006
The reason I did not suggest a solution like this is that using Set Warnings
in a macro can be rather dangerous. If any one of the macros fails for any
reason, the macro action at the end to restore warnings will never be run.
The new Access 2007 will provide for the ability to trap for errors in
macros, and respond accordingly, but in Access 2003 and all previous
versions, this is simply not possible. Consider the following quote:

From: "Inside Relational Databases, 2nd Edition, by Mark Whitehorn and Bill
Marklyn, published by Springer, p 151)

"Macros offer the next level down, extending the functionality of the GUI.
Macros are still limited, however, and do not provide anything like the
enormous flexibility of a programming language. Both the macro and the
programming languages take some effort to learn and, surprisingly, often
require relatively different skills; in other words, a good working knowledge
of macros may not make it much easier to convert to using the programming
language. Perhaps even more surprisingly, I do not believe that programming
is fundamentally more difficult to learn. Macros are easier to use but not by
orders of magnitude."

"If you are new to RDBMSs, I suggest (with as much deference as possible)
that you may well not be in a position to judge whether you need macros or
programming. In that case, my advice is clear. Unless you are sure that your
needs really are simple, don't bother learning to use macros. Once you find
that you need more than the GUI offers, go straight to the programming
language. In this way you avoid the pain of climbing one learning curve only
to discover that the view from the top is unsatisfactory and another climb
awaits you."



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________


"Armen Stein" wrote:

>
> I rarely recommend Access Macros for anything, but simply running a
> series of queries is one thing they do well. Create a new Macro, and
> add these lines:
>
> SetWarnings No
> OpenQuery Query1
> OpenQuery Query2
> etc...
> SetWarning Yes
>
> Note that the Yes, No, Query1, etc. are specified in the detail sheet
> below, not on the statement itself.
>
> The SetWarnings No statement turns off all the confirmation warnings
> for your action queries. If you want to see those, delete that line
> from your macro.
>
> On Mon, 6 Nov 2006 03:51:02 -0800, Ananth
> <(E-Mail Removed)> wrote:
>
> >Many Thanks for your elaborate reply. It is too techincal for me.
> >
> >I am a novice in VB and in Access Macro.
> >
> >I have a Access DB called Spend Data 2006 ,that has 5 Tables
> >Using Access Design Feature, I had created 20 Queries, which are titled
> >Query 1, Query 2, Query 3 etc…
> >
> >The DB has a Master Table on which these 20 Queries work. Most of these
> >queries are update queries, that has run sequentially (starting from query1
> >and end by executing query 20, which is cross tab query that produces the
> >results)
> >
> >What I meant was,I want a solution that will run the 20 queries
> >automatically, conclude with displaying the cross tab results (20th Query)
> >
> >
> >
> >"Tom Wickerath" wrote:
> >
> >> Hi Ananth,
> >>
> >> It's not clear to me whether or not your queries are all considered action
> >> queries, but here is a procedure that should get you started for the most
> >> common query types in Access. First, set a reference to the DAO Object
> >> Library if it is not already set. Use version 3.6 for Access 2000/2002/2003,
> >> or version 3.51 for Access 97. To check whether or not you already have this
> >> reference set, open a new standard module. Then click on Tools > References.
> >> If you find it checked, then just click on OK to dismiss this dialog. If not,
> >> scroll down the list until you find it, and place a check mark in it to
> >> select it. Then dismiss the references dialog box.
> >>
> >> Copy the following code and paste it into your new module.
> >> Notes:
> >> 1.) I removed the indentation from the SELECT Case, to help prevent word
> >> wrap in a newsgroup message from splitting a line of code into two lines.
> >>
> >> 2.) The name of the table referenced is: tblQueries
> >> The names of the queries are in a field named: QueryName
> >>
> >> 3.) I included a numeric field, indexed unique (no duplicates), which allows
> >> one to specify a sort order. This field is named: RunOrder
> >> This gives you the ability to easily change the order that queries are run,
> >> without having to rename them to match a -number naming convention.
> >>
> >> After pasting the code, click on Debug > Compile ProjectName, where
> >> ProjectName is the name of your VBA project (likely the same name as your
> >> database). Fix any compile errors before trying to do anything else.
> >>
> >> To run the code, have your blinking mouse cursor anywhere within the
> >> procedure. Then press the F5 button.
> >>
> >>
> >> Option Compare Database
> >> Option Explicit
> >>
> >> Sub RunSavedQueries()
> >> On Error GoTo ProcError
> >>
> >> Dim db As DAO.Database
> >> Dim rs As DAO.Recordset
> >> Dim qdf As DAO.QueryDef
> >> Dim strQueryName As String
> >>
> >> Set db = CurrentDb()
> >> Set rs = db.OpenRecordset("SELECT QueryName " _
> >> & "FROM tblQueries ORDER BY RunOrder")
> >>
> >> With rs
> >> Do Until (.BOF Or .EOF) = True
> >> strQueryName = rs("QueryName")
> >> Set qdf = db.QueryDefs(strQueryName)
> >>
> >> Debug.Print strQueryName, qdf.Type
> >>
> >> Select Case qdf.Type
> >> Case 0, 16, 128 'Select queries: 0=Select, 16=Crosstab, 128=Union
> >> DoCmd.OpenQuery strQueryName
> >> Case 32, 48, 80 'Action queries: 32=Delete, 48=Update/Append, 80=Make Table
> >> db.Execute strQueryName, dbFailOnError
> >> Case Else
> >> 'Do nothing for the present time.
> >> End Select
> >>
> >> rs.MoveNext
> >> Loop
> >> End With
> >>
> >> ExitProc:
> >> 'Cleanup
> >> On Error Resume Next
> >> Set qdf = Nothing
> >> rs.Close: Set rs = Nothing
> >> db.Close: Set db = Nothing
> >> Exit Sub
> >> ProcError:
> >> MsgBox "Error " & Err.Number & ": " & Err.Description, _
> >> vbCritical, "Error in procedure RunSavedQueries..."
> >> Resume ExitProc
> >> End Sub
> >>
> >>
> >>
> >> Tom Wickerath
> >> Microsoft Access MVP
> >>
> >> http://www.access.qbuilt.com/html/ex...tributors.html
> >> http://www.access.qbuilt.com/html/search.html
> >> __________________________________________
> >>
> >> "Ananth" wrote:
> >>
> >> > I have a Access Table that has 20 queries.
> >> >
> >> > Query-1
> >> > Quert-2 etc upto Query-20
> >> >
> >> > Can somebody help me with a small VB routine or Macro that would run all the
> >> > 20 Queries at a strike of a key (just like we have DO command in Foxpro)

> Armen Stein
> Microsoft Access MVP
> www.JStreetTech.com
>
>

 
Reply With Quote
 
aaron.kempf@gmail.com
Guest
Posts: n/a
 
      6th Nov 2006
if you were using Access Data Projects; then you could simply automate
the execution of a query or 10-- using SQL agent.

Access MDB isn't an enterprise level reporting platform.. it isn't
stable; it isn't reliable.

anyone that uses MDB anywhere-- for anything-- should be fired and then
SPIT UPON.

-Aaron


Tom Wickerath wrote:
> The reason I did not suggest a solution like this is that using Set Warnings
> in a macro can be rather dangerous. If any one of the macros fails for any
> reason, the macro action at the end to restore warnings will never be run.
> The new Access 2007 will provide for the ability to trap for errors in
> macros, and respond accordingly, but in Access 2003 and all previous
> versions, this is simply not possible. Consider the following quote:
>
> From: "Inside Relational Databases, 2nd Edition, by Mark Whitehorn and Bill
> Marklyn, published by Springer, p 151)
>
> "Macros offer the next level down, extending the functionality of the GUI.
> Macros are still limited, however, and do not provide anything like the
> enormous flexibility of a programming language. Both the macro and the
> programming languages take some effort to learn and, surprisingly, often
> require relatively different skills; in other words, a good working knowledge
> of macros may not make it much easier to convert to using the programming
> language. Perhaps even more surprisingly, I do not believe that programming
> is fundamentally more difficult to learn. Macros are easier to use but not by
> orders of magnitude."
>
> "If you are new to RDBMSs, I suggest (with as much deference as possible)
> that you may well not be in a position to judge whether you need macros or
> programming. In that case, my advice is clear. Unless you are sure that your
> needs really are simple, don't bother learning to use macros. Once you find
> that you need more than the GUI offers, go straight to the programming
> language. In this way you avoid the pain of climbing one learning curve only
> to discover that the view from the top is unsatisfactory and another climb
> awaits you."
>
>
>
> Tom Wickerath
> Microsoft Access MVP
>
> http://www.access.qbuilt.com/html/ex...tributors.html
> http://www.access.qbuilt.com/html/search.html
> __________________________________________
>
>
> "Armen Stein" wrote:
>
> >
> > I rarely recommend Access Macros for anything, but simply running a
> > series of queries is one thing they do well. Create a new Macro, and
> > add these lines:
> >
> > SetWarnings No
> > OpenQuery Query1
> > OpenQuery Query2
> > etc...
> > SetWarning Yes
> >
> > Note that the Yes, No, Query1, etc. are specified in the detail sheet
> > below, not on the statement itself.
> >
> > The SetWarnings No statement turns off all the confirmation warnings
> > for your action queries. If you want to see those, delete that line
> > from your macro.
> >
> > On Mon, 6 Nov 2006 03:51:02 -0800, Ananth
> > <(E-Mail Removed)> wrote:
> >
> > >Many Thanks for your elaborate reply. It is too techincal for me.
> > >
> > >I am a novice in VB and in Access Macro.
> > >
> > >I have a Access DB called Spend Data 2006 ,that has 5 Tables
> > >Using Access Design Feature, I had created 20 Queries, which are titled
> > >Query 1, Query 2, Query 3 etc...
> > >
> > >The DB has a Master Table on which these 20 Queries work. Most of these
> > >queries are update queries, that has run sequentially (starting from query1
> > >and end by executing query 20, which is cross tab query that produces the
> > >results)
> > >
> > >What I meant was,I want a solution that will run the 20 queries
> > >automatically, conclude with displaying the cross tab results (20th Query)
> > >
> > >
> > >
> > >"Tom Wickerath" wrote:
> > >
> > >> Hi Ananth,
> > >>
> > >> It's not clear to me whether or not your queries are all considered action
> > >> queries, but here is a procedure that should get you started for the most
> > >> common query types in Access. First, set a reference to the DAO Object
> > >> Library if it is not already set. Use version 3.6 for Access 2000/2002/2003,
> > >> or version 3.51 for Access 97. To check whether or not you already have this
> > >> reference set, open a new standard module. Then click on Tools > References.
> > >> If you find it checked, then just click on OK to dismiss this dialog. If not,
> > >> scroll down the list until you find it, and place a check mark in it to
> > >> select it. Then dismiss the references dialog box.
> > >>
> > >> Copy the following code and paste it into your new module.
> > >> Notes:
> > >> 1.) I removed the indentation from the SELECT Case, to help prevent word
> > >> wrap in a newsgroup message from splitting a line of code into two lines.
> > >>
> > >> 2.) The name of the table referenced is: tblQueries
> > >> The names of the queries are in a field named: QueryName
> > >>
> > >> 3.) I included a numeric field, indexed unique (no duplicates), which allows
> > >> one to specify a sort order. This field is named: RunOrder
> > >> This gives you the ability to easily change the order that queries are run,
> > >> without having to rename them to match a -number naming convention.
> > >>
> > >> After pasting the code, click on Debug > Compile ProjectName, where
> > >> ProjectName is the name of your VBA project (likely the same name as your
> > >> database). Fix any compile errors before trying to do anything else.
> > >>
> > >> To run the code, have your blinking mouse cursor anywhere within the
> > >> procedure. Then press the F5 button.
> > >>
> > >>
> > >> Option Compare Database
> > >> Option Explicit
> > >>
> > >> Sub RunSavedQueries()
> > >> On Error GoTo ProcError
> > >>
> > >> Dim db As DAO.Database
> > >> Dim rs As DAO.Recordset
> > >> Dim qdf As DAO.QueryDef
> > >> Dim strQueryName As String
> > >>
> > >> Set db = CurrentDb()
> > >> Set rs = db.OpenRecordset("SELECT QueryName " _
> > >> & "FROM tblQueries ORDER BY RunOrder")
> > >>
> > >> With rs
> > >> Do Until (.BOF Or .EOF) = True
> > >> strQueryName = rs("QueryName")
> > >> Set qdf = db.QueryDefs(strQueryName)
> > >>
> > >> Debug.Print strQueryName, qdf.Type
> > >>
> > >> Select Case qdf.Type
> > >> Case 0, 16, 128 'Select queries: 0=Select, 16=Crosstab, 128=Union
> > >> DoCmd.OpenQuery strQueryName
> > >> Case 32, 48, 80 'Action queries: 32=Delete, 48=Update/Append, 80=Make Table
> > >> db.Execute strQueryName, dbFailOnError
> > >> Case Else
> > >> 'Do nothing for the present time.
> > >> End Select
> > >>
> > >> rs.MoveNext
> > >> Loop
> > >> End With
> > >>
> > >> ExitProc:
> > >> 'Cleanup
> > >> On Error Resume Next
> > >> Set qdf = Nothing
> > >> rs.Close: Set rs = Nothing
> > >> db.Close: Set db = Nothing
> > >> Exit Sub
> > >> ProcError:
> > >> MsgBox "Error " & Err.Number & ": " & Err.Description, _
> > >> vbCritical, "Error in procedure RunSavedQueries..."
> > >> Resume ExitProc
> > >> End Sub
> > >>
> > >>
> > >>
> > >> Tom Wickerath
> > >> Microsoft Access MVP
> > >>
> > >> http://www.access.qbuilt.com/html/ex...tributors.html
> > >> http://www.access.qbuilt.com/html/search.html
> > >> __________________________________________
> > >>
> > >> "Ananth" wrote:
> > >>
> > >> > I have a Access Table that has 20 queries.
> > >> >
> > >> > Query-1
> > >> > Quert-2 etc upto Query-20
> > >> >
> > >> > Can somebody help me with a small VB routine or Macro that would run all the
> > >> > 20 Queries at a strike of a key (just like we have DO command in Foxpro)

> > Armen Stein
> > Microsoft Access MVP
> > www.JStreetTech.com
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Runnung macro has 2 results Steve Schapel Microsoft Access Macros 0 5th Mar 2010 10:28 PM
runnung word =?Utf-8?B?Q3VydA==?= Microsoft Excel Programming 0 15th Aug 2007 07:26 AM
How do you keep a runnung total? Pastor Andrew Alexander Microsoft Excel Discussion 2 20th Feb 2005 02:26 PM
Logon script runnung twice Mike Sims Microsoft Windows 2000 Active Directory 2 15th Sep 2004 10:39 PM
Outlook XP runnung very slowly Mike Trozzo Microsoft Outlook Discussion 3 19th Jan 2004 11:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.