AC2K Output query to Excel with date critera entered on form

nowanda

Board Regular
Joined
May 27, 2002
Messages
67
Howdy!

I can print preview my report using date criteria from a form (with user entry) but I don't see how I can do the same thing when I output to Excel. Can anyone suggest another method of action? (Feel free to criticize the way I coded this too - it works - but is not pretty!)

To Print Preview (this works)
Form has a frame (Frame) with 0 = all the data to be returned; -1 for the date selection based on the Microsoft Date and Time picker (From & To)

Sub Preview_Click()
If Me.Frame = 1 Then
' *** Handle date (from and to) entry / where clause ***
If Me.From.Value > Me.To.Value Then
MsgBox ("From date must be before To date")
Exit Sub
End If

Between = "date Between #" & Me.From & "# And #" & Me.To & "#"
DoCmd.OpenReport "Report", acPreview, , Between

Else
If Me.Frame = 0 Then
DoCmd.OpenReport "Report", acPreview
End If
End If
End Sub

To Export to Exccel (this needs help)
Form has the same frame (Frame) with 0 = all the data to be returned; -1 for the date selection based on the Microsoft Date and Time picker (From & To). This code does not include any date criteria from the form at all... please help me add it somehow!

Sub Export_Excel_Click()
DoCmd.OutputTo acOutputQuery, "Report_Query", acFormatXLS, "C:\Data\Report.xls"
End Sub

Suggestions?
Nowanda:)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Easiest option is probably to just have two queries, one with date criteria linked to your form and the other without date criteria. Then just run whichever is appropriate.

HTH

Peter
 
Upvote 0
Re: AC2K Output query to Excel with date critera entered on

Oops!

The issue is specifically that I want the date criteria to be accessed for the output to excel as the print preview does...

When you want to print preview you can use a where clause to specify anything you would like:

DoCmd.OpenReport "Report", acPreview, , ¨¨where clause¨¨

But the OutputTo doesn't allow you to specify any criteria....
DoCmd.OutputTo acOutputQuery, "Report_QRY", acFormatXLS, "C:\Data\Report.xls"

Does that make more sense? I'm looking to add a where clause to my query which I am outputting to excel. :rolleyes:

Nowanda:)
 
Upvote 0
Assuming that Me.From and Me.To are fields on your form there is no need to create a where clause as the query can be linked to these fields directly. So have one query that will be linked to these fields for its criteria and another that will show all data. Then just use the appropriate query in your if statement.

Peter
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,327
Members
451,697
Latest member
pedroDH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top