In this database, I have fields like
Report #, Customer #, CA Resp, Defect Code etc....
You will be doing yourself a huge favor in the future if you avoid using
special characters, including # signs and spaces, in anything that you assign
a name to in Access. Here is a KB article that talks about this:
Special characters that you must avoid when you work with Access databases
http://support.microsoft.com/?id=826763
.... and only ONE record.
So the query named "qryClosure" returns only one record, correct?
This query is linked to the report called rptCloseout....
What do you mean by "linked to the report"? Are you saying that this query
serves as the Record Source for your report? If so, then what you need to do
should be very easy. (The term "query linked to a report" really has no
meaning--at least to me it does not).
...and Report # from qryClosure is in this report.
Okay, so I am thinking that qryClosure does indeed serve as the record
source for your report. It certainly sounds that way to me. Try the following
VBA code in the report's Activate event procedure:
Private Sub Report_Activate()
On Error GoTo ProcError
' The caption is used for the Snapshot filename (caption.snp)
Me.Caption = "Report No. " & [Report #]
DoCmd.Maximize '<---Optional. Use DoCmd.Restore in Report_Close()
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in Report_Activate event procedure..."
Resume ExitProc
End Sub
Private Sub Report_Close()
On Error GoTo ProcError
DoCmd.Restore
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in Report_Close event procedure..."
Resume ExitProc
End Sub
Private Sub Report_NoData(Cancel As Integer)
On Error GoTo ProcError
MsgBox "There is no data available for this report.", _
vbInformation, "Your title goes here."
Cancel = True
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in NoData event procedure..."
Resume ExitProc
End Sub
You will need to have the [Report #] field in a bound text box (ie. the
control source of the text box is the Report # field) on the report. You can
set the visible property to No, if you don't want to display it. If you add
the optional NoData event procedure, as indicated above, you will need to
trap for Error 2501 in the click event procedure for the command button that
you are using to open the report. In addition, in order for this to work, you
will need to first open the report in normal preview mode, and then use the
DoCmd.SendObject method. Here is an example, which includes trapping for
error 2501. I declared a string variable and set it to your report name, so
that you only need to change it in one place:
Dim strReport As String
strReport = "rptCloseOut"
You could also rewrite the code slightly, so that it accepted the name of
the report as a parameter:
Option Compare Database
Option Explicit
Private Sub cmdSendReport_Click()
On Error GoTo ProcError
Dim strReport As String
strReport = "rptCloseOut"
' If this is a bound form (ie. includes a recordsource)
If Me.Dirty = True Then
Me.Dirty = False
End If
' Open report in preview
' DoCmd.OpenReport strReport, View:=acViewPreview
' or...
' Open report in preview, filtered for one record using the optional
' WhereCondition argument with the primary key:
DoCmd.OpenReport strReport, View:=acViewPreview, _
WhereCondition:="pkRequestID =" & Me.pkRequestID
' Email as SNP closure report
DoCmd.SendObject acReport, strReport, _
OutputFormat:="SnapshotFormat(*.snp)", _
Subject:="Closure Report - Concern Number", _
MessageText:="Please see attached closure report", _
EditMessage:=True
' Optional
DoCmd.Close acReport, strReport
ExitProc:
Exit Sub
ProcError:
Select Case Err.Number
Case 2501 'No Data, so trap for this error and ignore it.
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure cmdSendReport_Click..."
End Select
Resume ExitProc
End Sub
I hope this helps!
Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________