Printing Report from Current Form

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.
 
M

Marshall Barton

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
 
D

Duane Hookom

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 & """"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top