Preview report for current record only??

G

Guest

Hi team… I’m a new user, muddling my way through setting up a Staff Database
with everyone’s wonderful help. My next project is to add a button to my
‘Staff Details’ form which will preview the report ‘Employee Fact Sheet’ for
only the employee whose details are currently being viewed. Eg. If I were
viewing the form for Joe Bloggs and updating some data, I want to then be
able to click on a button to show / preview only Joe's fact sheet report and
from there print this one page report if needed.

In my attempts to achieve this, I have “successfully†added a button which
will run the Employee Fact Sheet report but which shows all employee’s
records, not just the one person. Not sure how to progress from here.

The ‘Employee Fact Sheet’ and the ‘Staff Details’ form both pull information
from a table ‘Current Employees’, and all have a primary key of “EmployeeIDâ€.

Help! ;o)
 
D

Douglas J. Steele

Presumably the code associated with your button uses DoCmd.OpenReport. In
fact, if you used the wizard to generate it, it's probably something like:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String

stDocName = "Employee Fact Sheet"
DoCmd.OpenReport stDocName, acPreview

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

The complete syntax for the OpenReport method is

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

If you can create an appropriate wherecondition, that will limit what's
displayed on your report:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "Employee Fact Sheet"
stWhere = "Employee = " & Me.txtEmployee
DoCmd.OpenReport stDocName, acPreview, , stWhere

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

This assumes that there's a field named Employee in the recordset on which
the report is based, and that there's a text box named txtEmployee on your
Staff Details form. You'll likely have to play around with setting stWhere
appropriately...
 
G

Guest

Thanks for the reply Doug. I used the wizard to set up the button which does
half the job I want done... unfortunately pretty much most of what you wrote
has gone way over my head... not that clever!

Could you give me the "how to..." for dummies version?

Many thanks!

Douglas J. Steele said:
Presumably the code associated with your button uses DoCmd.OpenReport. In
fact, if you used the wizard to generate it, it's probably something like:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String

stDocName = "Employee Fact Sheet"
DoCmd.OpenReport stDocName, acPreview

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

The complete syntax for the OpenReport method is

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

If you can create an appropriate wherecondition, that will limit what's
displayed on your report:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "Employee Fact Sheet"
stWhere = "Employee = " & Me.txtEmployee
DoCmd.OpenReport stDocName, acPreview, , stWhere

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

This assumes that there's a field named Employee in the recordset on which
the report is based, and that there's a text box named txtEmployee on your
Staff Details form. You'll likely have to play around with setting stWhere
appropriately...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Suzy said:
Hi team. I'm a new user, muddling my way through setting up a Staff
Database
with everyone's wonderful help. My next project is to add a button to my
'Staff Details' form which will preview the report 'Employee Fact Sheet'
for
only the employee whose details are currently being viewed. Eg. If I were
viewing the form for Joe Bloggs and updating some data, I want to then be
able to click on a button to show / preview only Joe's fact sheet report
and
from there print this one page report if needed.

In my attempts to achieve this, I have "successfully" added a button which
will run the Employee Fact Sheet report but which shows all employee's
records, not just the one person. Not sure how to progress from here.

The 'Employee Fact Sheet' and the 'Staff Details' form both pull
information
from a table 'Current Employees', and all have a primary key of
"EmployeeID".

Help! ;o)
 
D

Douglas J. Steele

The wherecondition is like the WHERE clause in a query, but without the word
WHERE. You specify particular field(s), and what value(s) you want for those
fields.

Take a look in the Help file: it might do a better job than me.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Suzy said:
Thanks for the reply Doug. I used the wizard to set up the button which
does
half the job I want done... unfortunately pretty much most of what you
wrote
has gone way over my head... not that clever!

Could you give me the "how to..." for dummies version?

Many thanks!

Douglas J. Steele said:
Presumably the code associated with your button uses DoCmd.OpenReport. In
fact, if you used the wizard to generate it, it's probably something
like:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String

stDocName = "Employee Fact Sheet"
DoCmd.OpenReport stDocName, acPreview

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

The complete syntax for the OpenReport method is

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

If you can create an appropriate wherecondition, that will limit what's
displayed on your report:

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim stDocName As String
Dim stWhere As String

stDocName = "Employee Fact Sheet"
stWhere = "Employee = " & Me.txtEmployee
DoCmd.OpenReport stDocName, acPreview, , stWhere

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

This assumes that there's a field named Employee in the recordset on
which
the report is based, and that there's a text box named txtEmployee on
your
Staff Details form. You'll likely have to play around with setting
stWhere
appropriately...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Suzy said:
Hi team. I'm a new user, muddling my way through setting up a Staff
Database
with everyone's wonderful help. My next project is to add a button to
my
'Staff Details' form which will preview the report 'Employee Fact
Sheet'
for
only the employee whose details are currently being viewed. Eg. If I
were
viewing the form for Joe Bloggs and updating some data, I want to then
be
able to click on a button to show / preview only Joe's fact sheet
report
and
from there print this one page report if needed.

In my attempts to achieve this, I have "successfully" added a button
which
will run the Employee Fact Sheet report but which shows all employee's
records, not just the one person. Not sure how to progress from here.

The 'Employee Fact Sheet' and the 'Staff Details' form both pull
information
from a table 'Current Employees', and all have a primary key of
"EmployeeID".

Help! ;o)
 

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