PC Review Forums Newsgroups Microsoft Access Microsoft Access VBA Modules running a query created in code

Reply

running a query created in code

 
Thread Tools Rate Thread
Old 17-04-2004, 07:39 PM   #1
Paul Mars
Guest
 
Posts: n/a
Default running a query created in code



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
Old 17-04-2004, 11:25 PM   #2
Ken Snell
Guest
 
Posts: n/a
Default Re: running a query created in code

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/defaul...kb;EN-US;286335

--
Ken Snell
<MS ACCESS MVP>

"Paul Mars" <paulmarsREMOVE@netzero.com> wrote in message
news:ud1vxLKJEHA.1392@TK2MSFTNGP09.phx.gbl...
>
> 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off