Error 2455

Error 2455

am 08.11.2007 14:41:36 von Jebusville

Why do I get this error when I run this code from a report's open event?

strSQL = "Select * from qsrptCaveat"
If Forms!fdlgPrint!chkInclude = False Then strSQL = strSQL & " Where
[Withdrawn] = 0"
Me.subCaveat.Report.RecordSource = strSQL

"subCaveat" is the object name (not the report name) of the sub-report on
the report. The error message is:

"You entered an expression that has an invalid reference to the property
Form/Report."

The report runs fine when I don't try to set its record source at runtime.

Many thanks.

Keith.

Re: Error 2455

am 08.11.2007 15:36:33 von Salad

Keith Wilby wrote:

> Why do I get this error when I run this code from a report's open event?
>
> strSQL = "Select * from qsrptCaveat"
> If Forms!fdlgPrint!chkInclude = False Then strSQL = strSQL & " Where
> [Withdrawn] = 0"
> Me.subCaveat.Report.RecordSource = strSQL
>
> "subCaveat" is the object name (not the report name) of the sub-report
> on the report. The error message is:
>
> "You entered an expression that has an invalid reference to the property
> Form/Report."
>
> The report runs fine when I don't try to set its record source at runtime.
>
> Many thanks.
>
> Keith.

It looks OK. If you break in the code, what happens if you did a
msgbox "Source is " & Me.subCaveat.Report.RecordSource
prior to setting the recordsource?

Maybe you can do the setting in the subreport instead of the main report.

Or perhaps you can use the same recordsource but set a filter on it from
the main report...depending on if you can access the subreport.

Re: Error 2455

am 08.11.2007 15:40:09 von Tom van Stiphout

On Thu, 8 Nov 2007 13:41:36 -0000, "Keith Wilby"
wrote:

Not really sure, but why don't you move this code to the subreport's
Report_Open event?

-Tom.



>Why do I get this error when I run this code from a report's open event?
>
>strSQL = "Select * from qsrptCaveat"
>If Forms!fdlgPrint!chkInclude = False Then strSQL = strSQL & " Where
>[Withdrawn] = 0"
>Me.subCaveat.Report.RecordSource = strSQL
>
>"subCaveat" is the object name (not the report name) of the sub-report on
>the report. The error message is:
>
>"You entered an expression that has an invalid reference to the property
>Form/Report."
>
>The report runs fine when I don't try to set its record source at runtime.
>
>Many thanks.
>
>Keith.

Re: Error 2455

am 08.11.2007 16:10:57 von Jebusville

"Tom van Stiphout" wrote in message
news:bt76j3ljcatr9ldk2hoef0rpjlnd8rv2pq@4ax.com...
> On Thu, 8 Nov 2007 13:41:36 -0000, "Keith Wilby"
> wrote:
>
> Not really sure, but why don't you move this code to the subreport's
> Report_Open event?
>

Hi Tom, that's where I originally put it:

Private Sub Report_Open(Cancel As Integer)

Dim strSQL As String

strSQL = "Select * from qsrptCaveat"
If Forms!fdlgPrint!chkInclude = False Then strSQL = strSQL & " Where
[Withdrawn] = 0"
Me.RecordSource = strSQL

End Sub

but I get error 2191, "You can't set the Record Source property in print
preview or after printing has started." Any clues?

Regards,
Keith.

Re: Error 2455

am 08.11.2007 16:21:28 von Jebusville

"Keith Wilby" wrote in message
news:47332348$1_1@glkas0286.greenlnk.net...

I think Access is throwing me a bum steer ... I only get that error if there
is one or more record in the sub with the "Withdrawn" flag set, regardless
of the status of the "Include Withdrawn" checkbox on the print dialog. Now
I'm really confused ...

Re: Error 2455

am 09.11.2007 02:19:40 von John Mishefske

Keith Wilby wrote:
> The report runs fine when I don't try to set its record source at runtime.

What if you add a Me.Requery after setting the record source?

--
'--------------------------
' John Mishefske
' UtterAccess Editor
' 2007 Microsoft Access MVP
'--------------------------

Re: Error 2455

am 09.11.2007 09:56:10 von Jebusville

"Keith Wilby" wrote in message
news:47332348$1_1@glkas0286.greenlnk.net...
>
> but I get error 2191, "You can't set the Record Source property in print
> preview or after printing has started." Any clues?
>

Here's the answer if anyone is interested:

I was getting this error when there was more than one record in the *main*
form and needed to suppress setting the *sub's* record source more than
once.