Setting Recordsource in report

  • Thread starter Thread starter Vikki
  • Start date Start date
V

Vikki

Hi!
I've designed a form that allows you to set the
recordsource of a report based on criteria that you select
in combo boxes on the form.

I have set 'specreport' as the report as below but when I
come to changing the record source of the report I get a
C++ error- abnormal program termination!
Can anyone help!!?

dim scecreport as Report

Set specreport = Report_Summary_report

specreport.RecordSource = wherestring
 
Several issues.

1. You may have more success using:
DoCmd.OpenReport "Summary_report", acViewPreview, , wherestring
If you want to use your approach try:
Dim specreport As New Report

2. Assigning the RecordSource of the report after you open it is not likely
to work.
Instead:
- Save the report without any RecordSource.
- Assign the SQL statement to a global string variable before opening the
report.
- Use the Open event of the report to read the string, and assign it to the
RecordSource property.

3. If you reassign the RecordSource of a form or report, be *very* careful
that fields do not disappear or change data type. Access only evaluates the
presence of the field and its data type when you originally open. It the new
RecordSource lacks the field, it can crash. Or if Access thought the field
was a number, but it turns out to be text, it can also crash. This is
especially important with calculated fields, where the data type is not
defined in the table. JET is notorious for getting it wrong, so it is best
to typecast in the query as described in article:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html
 
Thanks Allen, that's ace.;)
-----Original Message-----
Several issues.

1. You may have more success using:
DoCmd.OpenReport "Summary_report", acViewPreview, , wherestring
If you want to use your approach try:
Dim specreport As New Report

2. Assigning the RecordSource of the report after you open it is not likely
to work.
Instead:
- Save the report without any RecordSource.
- Assign the SQL statement to a global string variable before opening the
report.
- Use the Open event of the report to read the string, and assign it to the
RecordSource property.

3. If you reassign the RecordSource of a form or report, be *very* careful
that fields do not disappear or change data type. Access only evaluates the
presence of the field and its data type when you originally open. It the new
RecordSource lacks the field, it can crash. Or if Access thought the field
was a number, but it turns out to be text, it can also crash. This is
especially important with calculated fields, where the data type is not
defined in the table. JET is notorious for getting it wrong, so it is best
to typecast in the query as described in article:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 
Back
Top