feedburner
Enter your email address:

Delivered by FeedBurner

feedburner count

Opening a Dialog Form When Printing a Report

Before printing a report, you normally would want to enter report parameters in a dialog box such as the following:



The dialog form will popup when you open the Payroll Register report shown below:


To do this, we just need to put a code in the Open event of the report to open the dialog form as follows:

Private Sub Report_Open(Cancel As Integer)
  DoCmd.OpenForm "frmReportCriteria", acNormal, , , _
    acFormEdit, acDialog, "rptPayrollRegisterPerPeriod"
  If Not IsLoaded("frmReportCriteria") Then
    Cancel = True
  End If
End Sub



In the Close event of the report, we’ll need to close the form:


Private Sub Report_Close()
  Forms![frmReportCriteria].Visible = True
  DoCmd.Close acForm, "frmReportCriteria"
End Sub


In the Print button of the form, we can enter the following code:


Private Sub btnPrint_Click()
On Error GoTo Err_btnPrint_Click

  Dim strDocName As String
  Dim strFilter As String

  ' OpenArgs contains the report name
  strDocName = Me.OpenArgs
  If fmeForEmployee = 1 Then  ' All employees
    strFilter = ""
  Else                        ' Or individual employees
    strFilter = "[EmployeeID] = " & EmployeeID & " AND "
  End If
  strFilter = strFilter & "[PayPeriodID] Between " _
    & FromPayPeriodID & " And " & ToPayPeriodID

  Reports.Item(strDocName).Filter = strFilter
  Reports.Item(strDocName).FilterOn = True
  Me.Visible = False

Exit_btnPrint_Click:
  Exit Sub

Err_btnPrint_Click:
  MsgBox Err.Description
  Resume Exit_btnPrint_Click
End Sub


The code gets the report name from the OpenArgs passed by the report when it opens the dialog form. It then set the Filter property of the report to show only the records we selected in the form.




2 comments:
gravatar
Anonymous said...
November 14, 2010 at 2:38 AM  

do u know how to implement 3nf in ms access
if u do plz kinly post that ......
or plz mail me to dragon9090@gmail.com

gravatar
Gabriel said...
June 2, 2013 at 9:37 AM  

I would like to get in touch with an Access export for few questions related to my database. I really appreciate if someone here can help me out (i can donate). Please contact me at the link above, thank you!

Post a Comment

Post a Comment