Setting Recordsource in report

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
 
A

Allen Browne

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
 
V

Vikki

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.




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top