TheCronus
The Ruler of Titans
- Local time
- Today, 07:53
- 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
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