PC Review


Reply
Thread Tools Rate Thread

running a query created in code

 
 
Paul Mars
Guest
Posts: n/a
 
      17th Apr 2004

strWhere = "SELECT EmailAddress FROM Main WHERE Name =
'Forms!MainData.Filter'"

Now how do I output it??

DoCmd.OutputTo acOutputQuery, strWhere, acFormatRTF, "Email.rtf", True
Looks for a query with the name strWhere, which will not work.

Related question, why can I never find these things in help?


 
Reply With Quote
 
 
 
 
Ken Snell
Guest
Posts: n/a
 
      17th Apr 2004
You need to store the query as a temporary query, or write the results of
the query to a table and then export the table. We'll focus on the first
option in this example.

Here is code to create and save a query, use it for your routine, and then
delete it when you're routine is done:


Dim strWhere As String
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDefs

strWhere = "SELECT EmailAddress FROM Main WHERE [Name] = '" & _
"Forms!MainData.Filter'"
Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef("NewQueryName", strWhere )

DoCmd.OutputTo acOutputQuery, qdf.Name, acFormatRTF, "Email.rtf", True

qdf.Delete
Set qdf = Nothing
dbs.Close
Set dbs = Nothing


Note that it's not a good idea to use Name as the name of a field, etc. See
this Knowledge Base article for more information:
ACC2002: Reserved Words in Microsoft Access
http://support.microsoft.com/default...b;EN-US;286335

--
Ken Snell
<MS ACCESS MVP>

"Paul Mars" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> strWhere = "SELECT EmailAddress FROM Main WHERE Name =
> 'Forms!MainData.Filter'"
>
> Now how do I output it??
>
> DoCmd.OutputTo acOutputQuery, strWhere, acFormatRTF, "Email.rtf", True
> Looks for a query with the name strWhere, which will not work.
>
> Related question, why can I never find these things in help?
>
>



 
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
Can a union query be created from runSQL in VBA code =?Utf-8?B?SlQgU2FudGEgRmU=?= Microsoft Access Queries 6 26th Sep 2006 03:14 PM
Query created with code not working as intended =?Utf-8?B?SmFtZXMgTw==?= Microsoft Access Form Coding 1 17th Mar 2006 06:10 PM
ADP code hangs while running the same query in query analyser works C.W. Microsoft Access ADP SQL Server 3 23rd Dec 2005 02:05 AM
Running Query in Code =?Utf-8?B?SmF5?= Microsoft Access VBA Modules 12 5th Oct 2005 09:35 PM
Code for running query and results =?Utf-8?B?S2F0aGVyaW5l?= Microsoft Access VBA Modules 1 31st May 2004 04:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:09 AM.