Results 1 to 6 of 6
  1. #1
    alyon is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    89

    Command Button: Print for Grouped Reports

    I know how to program a command button to print a single record:
    DoCmd.OpenReport "[Report]", acPreview, , "[ID] = " & Me.[ID]
    DoCmd.PrintOut
    DoCmd.Close acReport, "[Report]"

    I also have created a command button to print one person's multiple records:
    DoCmd.OpenReport "[Report]", acPreview, , "[name] = " & Me.[txtname]
    DoCmd.PrintOut
    DoCmd.Close acReport, "[Report]"

    ...I'm stating what I already know, to clarify what I've already tried..
    But I have a mileage log report based off one form and one table that is grouped to print by months, I need to know how to create code for a command button, that allow's you to pick the month, and print only that current/monthly record. The idea of the 'name' above won't work because they don't have something in common, except the month in the date textbox, but there's also the day and year in the same textbox... and they will not be happy if they have to have a seperate textbox for month, day, and year. :/ Any help would be greatly appreciated!

    Thank You in Advance,
    A. Lyon

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Along the lines of:

    DoCmd.OpenReport "[Report]", acPreview, , "Month([DateField]) = " & Month(Me.[TextboxName])

    Perhaps also adding a criteria for year.

    By the way, if you drop the acPreview the report will print to the default printer, eliminating the need for the other 2 lines.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    alyon is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    89
    Hahaha, I had forgot I made this post, still hadn't got it working, and stumbled upon my post and your reply today! Works perfect! Thank you so much. And if it's not too much trouble, could you tell me how to add the year in? Please and thank you!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    DoCmd.OpenReport "[Report]", acPreview, , "Month([DateField]) = " & Month(Me.[TextboxName]) & " AND Year([DateField]) = " & Year(Me.[TextboxName])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    alyon is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    89
    Works Perfect. :] Sooo, can I maybe get your help with one more part of this?
    I have a report to print monthly, for which the code above is PERFECT.
    However, I also have a report that needs to be printed every two weeks..... suggestions?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would probably use Between with 2 dates. You can probably find formulas here to calculate the dates, depending on how they're determined:

    A plethora of date functions
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 02-22-2011, 05:04 AM
  2. Print different Reports at once
    By Brian62 in forum Reports
    Replies: 5
    Last Post: 01-21-2011, 11:19 AM
  3. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  4. Option to Print Sub-reports
    By Hotwheels59 in forum Reports
    Replies: 0
    Last Post: 06-21-2010, 03:29 PM
  5. Replies: 1
    Last Post: 04-22-2010, 04:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums