Export "Query Text" using VBA 
Author Message
 Export "Query Text" using VBA

Anyone know how to export the actual query text (not the
recordset result) programatically of many queries
developed in Access (which now must be ported to DTS
because of Access ineptitude)?  I tried "AllQueries" but
it seems to just give me the names of the queries, total
count, etc. but not the 'select ...' part.

Thanks!

ps. This code will put the values into a string:

Dim myQueries As String
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
For Each obj In dbs.AllQueries
  myRows = myQueries & obj.Name & vbCrLf
Next obj

What I want is something like this:

Dim myQueries As String
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
For Each obj In dbs.AllQueries
  myRows = myQueries & obj.Name & " / " &
           obj.QueryText & vbCrLf
Next obj

but there is no obj.QueryText that I know of...



Sun, 11 Sep 2005 08:06:24 GMT  
 Export "Query Text" using VBA
You can use the SQL property of the DAO querydef object:

Dim qdf As DAO.QueryDef
Dim strX As String
For Each qdf In CurrentDb.QueryDefs
    strX = strX & qdf.Name & "/" & qdf.SQL & vbCrLf
Next qdf
Set qdf = Nothing
MsgBox strX

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Quote:

> Anyone know how to export the actual query text (not the
> recordset result) programatically of many queries
> developed in Access (which now must be ported to DTS
> because of Access ineptitude)?  I tried "AllQueries" but
> it seems to just give me the names of the queries, total
> count, etc. but not the 'select ...' part.

> Thanks!

> ps. This code will put the values into a string:

> Dim myQueries As String
> Dim obj As AccessObject, dbs As Object
> Set dbs = Application.CurrentData
> For Each obj In dbs.AllQueries
>   myRows = myQueries & obj.Name & vbCrLf
> Next obj

> What I want is something like this:

> Dim myQueries As String
> Dim obj As AccessObject, dbs As Object
> Set dbs = Application.CurrentData
> For Each obj In dbs.AllQueries
>   myRows = myQueries & obj.Name & " / " &
>            obj.QueryText & vbCrLf
> Next obj

> but there is no obj.QueryText that I know of...



Sun, 11 Sep 2005 10:35:26 GMT  
 Export "Query Text" using VBA
Thanks!

If DAO is on its way 'out' and ADO 'in', then I hope they
will add these properties/functions to ADO...

In case anyone else reads this, to run her code below you
have to add the DAO Object Library into References.

Thanks,

CCB

Quote:
>-----Original Message-----
>You can use the SQL property of the DAO querydef object:

>Dim qdf As DAO.QueryDef
>Dim strX As String
>For Each qdf In CurrentDb.QueryDefs
>    strX = strX & qdf.Name & "/" & qdf.SQL & vbCrLf
>Next qdf
>Set qdf = Nothing
>MsgBox strX

>--
>Sandra Daigle
>[Microsoft Access MVP]
>For the benefit of others please post all replies to this
newsgroup.


>> Anyone know how to export the actual query text (not the
>> recordset result) programatically of many queries
>> developed in Access (which now must be ported to DTS
>> because of Access ineptitude)?  I tried "AllQueries" but
>> it seems to just give me the names of the queries, total
>> count, etc. but not the 'select ...' part.

>> Thanks!

>> ps. This code will put the values into a string:

>> Dim myQueries As String
>> Dim obj As AccessObject, dbs As Object
>> Set dbs = Application.CurrentData
>> For Each obj In dbs.AllQueries
>>   myRows = myQueries & obj.Name & vbCrLf
>> Next obj

>> What I want is something like this:

>> Dim myQueries As String
>> Dim obj As AccessObject, dbs As Object
>> Set dbs = Application.CurrentData
>> For Each obj In dbs.AllQueries
>>   myRows = myQueries & obj.Name & " / " &
>>            obj.QueryText & vbCrLf
>> Next obj

>> but there is no obj.QueryText that I know of...
>.



Mon, 12 Sep 2005 06:56:14 GMT  
 Export "Query Text" using VBA
DAO isn't going anywhere for a good while - as long as we have JET we will
have DAO.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Quote:

> Thanks!

> If DAO is on its way 'out' and ADO 'in', then I hope they
> will add these properties/functions to ADO...

> In case anyone else reads this, to run her code below you
> have to add the DAO Object Library into References.

> Thanks,

> CCB

>> -----Original Message-----
>> You can use the SQL property of the DAO querydef object:

>> Dim qdf As DAO.QueryDef
>> Dim strX As String
>> For Each qdf In CurrentDb.QueryDefs
>>    strX = strX & qdf.Name & "/" & qdf.SQL & vbCrLf
>> Next qdf
>> Set qdf = Nothing
>> MsgBox strX

>> --
>> Sandra Daigle
>> [Microsoft Access MVP]
>> For the benefit of others please post all replies to this newsgroup.


>>> Anyone know how to export the actual query text (not the
>>> recordset result) programatically of many queries
>>> developed in Access (which now must be ported to DTS
>>> because of Access ineptitude)?  I tried "AllQueries" but
>>> it seems to just give me the names of the queries, total
>>> count, etc. but not the 'select ...' part.

>>> Thanks!

>>> ps. This code will put the values into a string:

>>> Dim myQueries As String
>>> Dim obj As AccessObject, dbs As Object
>>> Set dbs = Application.CurrentData
>>> For Each obj In dbs.AllQueries
>>>   myRows = myQueries & obj.Name & vbCrLf
>>> Next obj

>>> What I want is something like this:

>>> Dim myQueries As String
>>> Dim obj As AccessObject, dbs As Object
>>> Set dbs = Application.CurrentData
>>> For Each obj In dbs.AllQueries
>>>   myRows = myQueries & obj.Name & " / " &
>>>            obj.QueryText & vbCrLf
>>> Next obj

>>> but there is no obj.QueryText that I know of...
>> .



Mon, 12 Sep 2005 10:02:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Suppressing "Export to Text" Dialog

2. Exporting as "Text" Adds Space

3. GetObject("","InternetExplorer.Application") fails in Excel VBA

4. GetObject("","InternetExplorer.Application") fails in Excel VBA

5. Using "move to folder" in VBA

6. ""Declare" query

7. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

8. Export Report to ".doc"

9. Exporting the "Relationship Layout"

10. Export "anomoly"

11. Export to HTML "HTMLExportData" property

12. Error "Invalid Export DLL"

 

 
Powered by phpBB® Forum Software