Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 December 7th, 2005, 10:07 AM
Authorized User
 
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loop Through Queries

Hi All,

I am trying to work out how to export all queries in a database that start with "Lookahead Report", to Excel, with the click of a button.

I have worked out how to export them using vba, but I don't yet know how to loop through all the queries to see if they start with "Lookahead Report".

Would someone be able to help me out with this?

Thanks

Patrick

Visit my site: http://www.drybonesuk.com
__________________
Visit my site: http://www.drybonesuk.com
 
Old December 7th, 2005, 10:58 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi ozPatt,

There is a system table that holds the names of all of your queries, table etc. I would go to tools, options and then have it show the System tables, then just do a query that pulls all objects of a certain type (Whatever the queries are listed as) and where the name begins with your specific text.

Let me know if you need more information than this,

Mike

Mike
EchoVue.com
 
Old December 7th, 2005, 11:16 AM
Authorized User
 
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI, thanks very much for your reply. While I was just copying some code for you, I realised what I had done wrong. I forgot to set one of the objects. The code I have used is as follows:

Code:
'EXPORT LOOKAHEAD REPORTS TO EXCEL
Public Sub ExportLookaheads()
    'locals
    Dim obj As AccessObject
    Dim dbs As Object
    'set object
    Set dbs = Application.CurrentData
    'loop through and export
    For Each obj In dbs.AllQueries
        If Left(obj.Name, 16) = "Lookahead Report" Then
            DoCmd.OutputTo ObjectType:=acOutputQuery, ObjectName:=obj.Name, OutputFormat:=acFormatXLS, OutputFile:=conRootDir & "Lookahead Reports\" & obj.Name & ".xls"
        End If
    Next obj
End Sub
thanks very much for your response, without it I wouldn't have been replying and may not have found the problem!

Thanks again

Patrick

Visit my site: http://www.drybonesuk.com
 
Old December 7th, 2005, 11:19 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No Worries! Looks like I learnt something new as well.

Thanks

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine two queries snufse SQL Server 2005 6 June 24th, 2008 09:42 PM
Combining two Queries arholly Access 1 January 16th, 2007 06:40 PM
Combining Queries or results from 2 queries Ford SQL Server 2000 24 November 7th, 2005 08:54 PM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM
Queries xzvi0r Access 5 September 8th, 2003 10:03 AM





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