Software

Create an Access form that lets users specify which data to print

You can easily add a custom form button that enables your users to choose which records to print. Mary Ann Richards steps through the process.

When you want to enable your users to print only the records they need, you can set up a form that lets them do just that. For example, to create a form that generates a report listing only the records of employees hired during a specific period, follow these steps:

  1. In the Database Window, under objects, click Forms, click New, and then click OK. (In Access 2007, click Create and then click the Forms Design command in the Forms group.
  2. Click the Text box tool in the Toolbar options box. (In Access 2007, click the Text box control on the Design tab.)
  3. Click and drag to create the first unbound text box. Change the text box label to From:.
  4. Click the Text Box tool in the Toolbar options box. (In Access 2007, click the Text Box control on the Design tab.)
  5. Click and drag to create the second unbound text box. Change the text box label to To:.
  6. Right-click the first text box and select Properties. Click the All tab and then click in the Name property box and type StartDate.
  7. Right-click the second text box and select Properties. Click the All tab and then click in the Name property box and type EndDate.
  8. Click the Command tool in the Toolbar Options box. (In Access 2007, click the Command control on the Design tab.)
  9. Click and drag in the form to locate the Command button. (Click Cancel to close the Command wizard, if necessary.)
  10. Right-click the Command tool and then click Properties.
  11. Click the All tab and then click in the Caption property box and type Print Report.
  12. Click the Event tab.
  13. Click the Build button in the On Click property box.
  14. Click Event Procedure.
  15. Enter the following code at the prompt, as shown in Figure A, and press Alt + Q:

    Dim ReportName
    

      ReportName = "Employees1"

      DoCmd.OpenReport _

      ReportName:=ReportName, _

      view:=acViewPreview, _

      WhereCondition:="[Hire Date] Between #" & _

      Me.StartDate & "# AND #" & _

      Me.EndDate & "#"

    Figure A

    custom button code

    To use this form to generate a report for all employees hired from 2001 to 2003, you would enter 1/1/2001 in the From box and 1/1/2003 in the To box (Figure B). Then, just press the Print Report button.

    Figure B

    print report


    Miss an Access tip?

    Check out the Microsoft Access archive and catch up on other Access tips.

    Help users increase productivity by automatically signing up for TechRepublic's free Microsoft Office Suite newsletter, featuring Word, Excel, and Access tips, delivered each Wednesday.

    0 comments