I have another problem with my form.
On it, I have a command button to "print preview" a report. I would like this report to use only the current information on the active form.
Currently, it will show all the records, starting with the first one on the list. Here is the code behind that button:
Private Sub PreviewReport_Click()
On Error GoTo Err_PreviewReport_Click
Dim stDocName As String
stDocName = "All Tenants Info Sorted by Unit No"
DoCmd.OpenReport stDocName, acPreview
Exit_PreviewReport_Click:
Exit Sub
Err_PreviewReport_Click:
MsgBox Err.Description
Resume Exit_PreviewReport_Click
End Sub
The name of the report (as shown above) is "All Tenants Info Sorted by Unit No"
What command should be added to show (or print) the current active record that is shown on my form.
Thank you for helping a beginner,
Alain
Douglas J. Steele - 30 Nov 2006 17:30 GMT
You need pass a Where condition with your OpenReport method. Something like:
Private Sub PreviewReport_Click()
On Error GoTo Err_PreviewReport_Click
Dim stDocName As String
Dim stCond As String
stDocName = "All Tenants Info Sorted by Unit No"
stCond = "TenantId = " & Me.txtTenant
DoCmd.OpenReport stDocName, acPreview, , stCond
Exit_PreviewReport_Click:
Exit Sub
Err_PreviewReport_Click:
MsgBox Err.Description
Resume Exit_PreviewReport_Click
End Sub
Replace TenantId and Me.txtTenant with the appropriate names. If TenantId is
text, that would need to be
stCond = "TenantId = '" & Me.txtTenant & "'"

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
I have another problem with my form.
On it, I have a command button to "print preview" a report. I would like
this report to use only the current information on the active form.
Currently, it will show all the records, starting with the first one on the
list. Here is the code behind that button:
Private Sub PreviewReport_Click()
On Error GoTo Err_PreviewReport_Click
Dim stDocName As String
stDocName = "All Tenants Info Sorted by Unit No"
DoCmd.OpenReport stDocName, acPreview
Exit_PreviewReport_Click:
Exit Sub
Err_PreviewReport_Click:
MsgBox Err.Description
Resume Exit_PreviewReport_Click
End Sub
The name of the report (as shown above) is "All Tenants Info Sorted by Unit
No"
What command should be added to show (or print) the current active record
that is shown on my form.
Thank you for helping a beginner,
Alain
Alain - 30 Nov 2006 22:46 GMT
Thank you very much for the help.
This worked flawlessly and exactly as I wanted. I much appreciate the fact
that you are sharing your knowledge with the Access community at large.
Alain
> You need pass a Where condition with your OpenReport method. Something
> like:
[quoted text clipped - 54 lines]
> Thank you for helping a beginner,
> Alain
fredg - 30 Nov 2006 17:33 GMT
> I have another problem with my form.
> On it, I have a command button to "print preview" a report. I would like this report to use only the current information on the active form.
[quoted text clipped - 23 lines]
> Thank you for helping a beginner,
> Alain
Your table should have a unique prime key field.
In my example it is named [RecordID].
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]
The above assumes a [RecordID] field that is a Number Datatype.
If, however, [RecordID] is Text Datatype, then use:
DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"
as the Where clause.
For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change ReportName and [RecordID] to whatever the actual table and
field name is that you are using.
See VBA Help files for:
Where Clause + Restrict data to a subset of records'

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Alain - 30 Nov 2006 22:48 GMT
Fred,
Thank you for the quick response. The solution passed by Doug worked
well.
Yours is very similar and would achieve the same results.
Thanks again for your time in providing a response.
Alain
>> I have another problem with my form.
>> On it, I have a command button to "print preview" a report. I would like
[quoted text clipped - 52 lines]
> See VBA Help files for:
> Where Clause + Restrict data to a subset of records'