Link to home
Start Free TrialLog in
Avatar of AviationAce
AviationAceFlag for United States of America

asked on

DoCmd.OutputTo acOutputTable WHERE

The following code works just fine:
DoCmd.OutputTo acOutputTable, "header", acFormatXLS, "C:\my.xls", True

However I want to filter out only selected records before it is Outputted to the XLS file.

Any ideas?
Avatar of Jim P.
Jim P.
Flag of United States of America image

Create a query that only select the records you want and then it would be:

DoCmd.OutputTo acOutputQuery, "header_Query", acFormatXLS, "C:\my.xls", True
Avatar of AviationAce

ASKER

I think my problem still remains.  I will need to change the WHERE statement before the query is ran.
In your query just put on the criteria line something like [Enter the company id to export] (with the brackets) and then when the query runs it will pop-up a box to enter your stuff.
Q-23915388.jpg
I guess I need to explain what I am doing better.  On a form there is a list box.  The user will select a value and then click a button to export just one record an XLS file.  I am good at building an SQL statement.  I just don't see a way to use the DoCmd.OutputTo command to make this happen.
In that case in the criteria of the query you would put Forms!MyFormName!MyListBoxName. When the user clicks to export, it will only select that record.
I understand that.  But can you give me an example of using as SQL SELECT WHERE statement in a DoCmd.OutputTo command?
ASKER CERTIFIED SOLUTION
Avatar of Jim P.
Jim P.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You rock!  Thanks.
Glad to be of assistance. May all your days get brighter and brighter.