Printing, Previewing and Saving Reports

dodie

New member
Local time
Today, 17:56
Joined
Oct 19, 2009
Messages
9
Hi Everyone,

I have a report called 'Training Schedule' and I have a 3 buttons called 'Print Training Schedule', 'Preview Training Schedule' and 'Save Training Schedule'. I would like it if when I pressed these buttons they would do this action but only do it for the current record selected on the form.

If you can suggest ways of doing this it would be excellent.
 
Take a look at the "DoCmd.OpenReport" method. One of the options when using this method is to provide a Where statement in the call to the method. This will apply the filter to your report.

To Preview your report use something like:

DoCmd.OpenReport "ReportName", acViewPreview, , "FieldName= '" & Me.NameOfControl & "'"

The statement above assumes that the value in the control on your form is a text value. If it is some other type of value you will need to modify the statement to refer to the type used. Also, of course, change "ReportName" to the name of the report you want to preview, "FieldName" to the name of the data field you want to use to filter the report on and "NameOfControl" to the actual name of the control on your form that holds the value to be used as the filter for the report.
 
Hi Mr. B,

Thank you for your reply. I have tried this like so

DoCmd.OpenReport "Training Schedule", acViewPreview, , "IDTag= '" & Me.ID & "'

And have placed it in the OnClick Event of the button, but I am unsure if I have to replace any other code? This is the code on my 'Preview Training Schedule' button at the moment:

Private Sub Preview_Click()
On Error GoTo Preview_Click_Err

DoCmd.OpenReport "Training Schedule", acViewPreview, , "ID= '" & Me.ID & "'"
Dim stDocName As String
stDocName = "Training Schedule"
DoCmd.OpenReport stDocName, acPreview, , "[ID]=[Forms]![Students]![ID]"

Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
MsgBox Err.Description
Resume Exit_Preview_Click


Preview_Click_Exit:
Exit Sub

Preview_Click_Err:
MsgBox Error$
Resume Preview_Click_Exit

End Sub

Please advise what changes need to be made. Your help is greatly appreciated.
 
In your current code you are attempting to open the report twice.

Try the code as follows:
Code:
[COLOR=#0000ff]Private Sub Preview_Click()
'On Error GoTo Preview_Click_Err
[/COLOR]
[COLOR=#0000ff]DoCmd.OpenReport "Training Schedule", acViewPreview, , "ID= '" & Me.ID & "'"[/COLOR]
[COLOR=#0000ff][/COLOR] 
[COLOR=#0000ff]Preview_Click_Exit:
Exit Sub
Preview_Click_Err:
MsgBox Error$
Resume Preview_Click_Exit[/COLOR]

[COLOR=blue]End Sub[/COLOR]

Please note that I have commented out the "On Error" line at this point. This was done so that you can actaully see when you have an error and where the error is occuring. When your code is working as desired you can simply remove the single quote at the beginning of the line and your error checking code will again work.
 
Thanks again Mr. B,

I have entered this code exactly as you have said to but I get:

Run-time Error '3464'
Data type mismatch in criteria expression.

When I press debug it takes me into VB and highlights the following in yellow:

DoCmd.OpenReport "Training Schedule", acViewPreview, , "ID= '" & Me.ID & "'"

Thankyou for your answers.
 
Oops. Sorry about that. I should have noticed that you had it a little wrong. Try this:

DoCmd.OpenReport "Training Schedule", acViewPreview, , "ID= " & Me.ID & ""
You did not need the single quotes before the reference to the control on your form.
 
Thanks Mr. B!

It's all working perfectly now! Thank you so much for your help!
 
Gald to help!

Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom