Printing reports and forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

1. I would like to click a command button and view a form in print preview.
I have tried different things, but get "Type Mismatch" errors, or other
errors. But at least I can view specific data, eg: Id to Id.

2. I tried to get reports to filter Id to Id, and can't do that, but can
have it print in print preview.

Is there a way to do both 1 and 2?

Any help is appreciated. Thanks
Connie
 
Hi, Connie.
1. I would like to click a command button and view a form in print preview.
I have tried different things, but get "Type Mismatch" errors, or other
errors. But at least I can view specific data, eg: Id to Id.

I'm not positive I understand what you mean by "ID to ID." Perhaps it's a
view of sequential records sorted according to the primary key? If so, then
to view a form in print preview, try the following:

Private Sub OpenFrmBtn_Click()

On Error GoTo ErrHandler

DoCmd.OpenForm "frmName", acPreview

Exit Sub

ErrHandler:

MsgBox "Error in OpenFrmBtn_Click( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub
2. I tried to get reports to filter Id to Id, and can't do that, but can
have it print in print preview.

I'm not sure I understand what "filtering a report ID to ID" is supposed to
look like. Reports will sequentially print all the records in the report's
RecordSource Property (or just display the records during print preview
mode). Please explain what you'd like to change about this behavior and
whether you'd like to view this report in print preview mode (as the form
above) or print the report from print preview (as you've already succeeded
at).

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Thanks Gunny
I have the form to opening in print preview, thanks.

For my second request here is the scenario:
I am in a data entry form and have accessed a client record, say this client
is Id 100. From the form, I want to click on a command button and have the
report open to that client's information. That's what I meant by Id to
Id...sorry for not being more clear.
Thanks
Connie
 
Hi, Connie.
From the form, I want to click on a command button and have the
report open to that client's information.

If the report and the form have the same table as the Record Source (and
hence the same primary key), then try the following:

Private Sub OpenRptBtn_Click()

On Error GoTo ErrHandler

DoCmd.OpenReport "rptMyReport", acViewPreview, , "ID = " & Me!txtID.Value

Exit Sub

ErrHandler:

MsgBox "Error in OpenRptBtn_Click( ) in " & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

.... where rptMyReport is the name of the report, ID is the primary key, and
txtID is the name of the text box holding this value.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Excellent!! Thanks. Works just great. When there is no data in the
client's sub form, and I click the command button to run the report, an error
message pops up. I expect this but it's a pretty ugly sucker. is there a
way that I can change the message to say: "there is no data to display"?

Thanks again
Connie
 
Hi, Connie.
is there a
way that I can change the message to say: "there is no data to display"?

Yes. You need to do two things. Change your button's error handling code
to handle the possible cancellation of the report:

Private Sub OpenRptBtn_Click()

On Error GoTo ErrHandler

DoCmd.OpenReport "rptMyReport", acViewPreview, , "ID = " & Me!txtID.Value

Exit Sub

ErrHandler:

If (Err.Number <> 2501) Then ' Report not cancelled.
MsgBox "Error in OpenRptBtn_Click( ) in " & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
End If

Err.Clear

End Sub

Next, in your report's OnNoData( ) event, place the following code in the
report's module, save and compile the code:

Private Sub Report_NoData(Cancel As Integer)

On Error GoTo ErrHandler

MsgBox "There is no data to display."
Cancel = True

Exit Sub

ErrHandler:

MsgBox "Error in Report_NoData( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Back
Top