Printing Report from Current Form

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I have a form named Employee and a query named Employee
Data. A report named Employee History based on the query
should display the current record displayed on the
Employee form. I want to print this report from a command
button on the Employee form.

My code includes the following:

Dim strDocName As String
strDocName = "Employee History"
DoCmd.OpenReport strDocName, acPreview, "Employee Data"

My report doesn't display the current record but instead
all the employee history reports for 100 persons.

How can I have the report preview only the current record
dsiplayed on the form.
 
Bill said:
I have a form named Employee and a query named Employee
Data. A report named Employee History based on the query
should display the current record displayed on the
Employee form. I want to print this report from a command
button on the Employee form.

My code includes the following:

Dim strDocName As String
strDocName = "Employee History"
DoCmd.OpenReport strDocName, acPreview, "Employee Data"

My report doesn't display the current record but instead
all the employee history reports for 100 persons.

Don't use the OpenReport's Filter argument. Instead use the
WhereCondition arguement:

DoCmd.OpenReport strDocName, acPreview, , _
"EmployeeIDfield = " & EmployeeIDtextbox
 
Assuming you have a primary key field in the Employee Data query named
[EmployeeID], you could modify your code

Dim strDocName As String
Dim strWhere as String
strWhere = "[EmployeeID] = " & Me.txtEmployeeID
strDocName = "Employee History"
DoCmd.OpenReport strDocName, acPreview, , strWhere

If your EmployeeID field is text rather than numeric, change the one line
above to:
strWhere = "[EmployeeID] = """ & Me.txtEmployeeID & """"
 
Back
Top