Confusing Situations Related With Reports

TheCronus

The Ruler of Titans
Local time
Today, 09:48
Joined
Dec 11, 2004
Messages
6
Hi,
The below code has comments. And my problems are mentioned there. I will appreciate any comment or solution. Thx.

'This command button is placed on a form and is used to open a report. The report is named as PEOPLE_REPORT.

Private Sub SHOW_PEOPLE_REPORT_Click()
On Error GoTo Err_SHOW_PEOPLE_REPORT_Click
Dim myReport As Report

'Set myReport = Reports!PEOPLE_REPORT
'When I try to assign my report to the object variable, I encounter the below error message.
'The report name 'PEOPLE_REPORT' you entered is misspelled or refers to a report that isn't open or doesn't exist.

'Then I thought that if I used the name of the report as displayed in Project view, I might overcome the problem. And my next trial assignment is below.

'Set myReport = Reports!Report_PEOPLE_REPORT

'Again the same error.
'The report name 'Report_PEOPLE_REPORT' you entered is misspelled or refers to a report that isn't open or doesn't exist.

'Finally I used the below assignment, Msgboxes and report are displayed.

Set myReport = Report_PEOPLE_REPORT

MsgBox "myReport.Caption: " & myReport.Caption

MsgBox "myReport.RecordSource: " & myReport.RecordSource


'After I have overcome the assignment problem, I tried to change the Record Source property in order to assign a dynamically created SQL string. Originally, report uses the PEOPLE table as the Record Source.

'myReport.RecordSource = "SELECT OID, PERSON FROM PEOPLE WHERE PERSON = 'Mike'"

'When the above part is uncommented, I have the below error message.
'You can't set the Record Source property in print preview or after printing has started.


'However, there is such a situation that the original MDB and MDE files are functioning OK, before modification. And in the original file, the previous coder had also used "Set myReport = Reports!PEOPLE_REPORT" and "'myReport.RecordSource = "SELECT OID, PERSON FROM PEOPLE WHERE PERSON = 'Mike'" statements. I just modified the SQL string, I saved the code. And when I open and press the related command button, I have the below situations and error messages.

Dim stDocName As String

stDocName = "PEOPLE_REPORT"
DoCmd.OpenReport stDocName, acViewPreview

Exit_SHOW_PEOPLE_REPORT_Click:
Exit Sub

Err_SHOW_PEOPLE_REPORT_Click:
MsgBox Err.Description
Resume Exit_SHOW_PEOPLE_REPORT_Click

End Sub
 
Ok, I will try what you have suggested. But what I really wonder is that, the original code runs well and as I mentioned before, the previous coder also manipulated the record source in the command click event. How can this run then? Or might I have missed some part when examining the code?

Thx for your interest.
 
Thx

I have done so and it worked. But I have following questions in mind;

1- Does the query used as the record source of report run when I open in design view?

2- Does this way (opening the report temporarily) effect the performance of the application?

3- Might it create a bottleneck at some point?
 

Users who are viewing this thread

Back
Top Bottom