Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for "Printing Report" Button

Status
Not open for further replies.

Sadukar

Technical User
Feb 19, 2003
159
IE
Hi All,

I am trying to print a report Between Two Dates without using a query.
If I were to use a form with 2 txt boxs and one "Print" Button, What would the code be?

Thanks for the help,
Sarah
 
Sarah,

Why not use the AutoFilter feature to select the from-thru rows and then print? Skip,
Skip@theofficeexperts.com
 
Skip,
I am doing this in Access 97. I want to keep my form very simple. I.E. Just click put in dates and Print. It is a Work Due Report and this database will be used by people with low computer skills.

Any sugestions with the code?

Thanks
Sarah

 
Hi Sarah,

I don't know what you already have so, from the top ..

1. Create a new form and go into Design View
2. Add 2 text boxes and format them as dates. Call them, say, StartDate and EndDate
3. Add a control button. The wizard will appear.
4. Using the wizard set up the button to print your report. Call the button, say, PrintButton.
5. Now go look at the generated code (in Form Design, select "Code" from the "View" menu). You should find a Sub called PrintButton_Click
6. In the sub will be the following code

Code:
    Dim stDocName As String
    
    stDocName = "YourTableName" 
    DoCmd.OpenReport stDocName, acNormal
7. Add to / Change this code to read

Code:
Code:
Dim stDateCrit As String
    stDateCrit = "[YourColumn] between #" & StartDate & "#" _
                               & " and #" & EndDate & "#"
Code:
    Dim stDocName As String
    
    stDocName = "YourTableName" 
    DoCmd.OpenReport stDocName, acNormal
Code:
, , stDateCrit

If you substitute your own table name and date column name in the above code, that should be all you need.

Enjoy,
Tony
 
Hi Tony,
Thanks for the help,
It worked.


Would you explain what the # and _ is about in the code.

Thanks Again
S.
 

Sarah,

Glad to be of help.

The # symbols are simply the way date literals have to be specified in Access.

The _ is a continuation mark. I coded it that way simply to make it neater to look at in the post. You can (indeed must) omit it if you concatenate the two lines.

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top