Report code not recognizing a report control

  • Thread starter J_Goddard via AccessMonster.com
  • Start date
J

J_Goddard via AccessMonster.com

Hi All -

I am sure this is a case of overlooking the obvious. I am trying to adjust a
form's header when the report is generated to more accurately reflect the
report's content. Until now, I have never had a problem. The report is
opened from a form VB module with:

DoCmd.OpenReport "Diagram CORCAS Prtvar", acViewPreview

In the On Format event of the report header, I have this code (for debugging
purposes):

Debug.Print "List of controls"
Debug.Print "================"
Dim ctl As Control
For Each ctl In Me.Controls
Debug.Print ctl.Name, ctl.ControlType
Next

MsgBox "Current form/report is " & Me.Name
MsgBox "Stage number is " & Me![Stage Number]

The (edited) output from the For Each ctl loop looks like this:

List of controls
================
<<Snipped>>
dataset_id 109
Stage Number 109 << Note this one
kp1 109
kp2 109
<<snipped>>

and it get all the right control names and types.

MsgBox "Current form/report is " & Me.Name displays the correct name

However, this code line:

MsgBox "Stage number is " & Me![Stage Number] produces:

Error 2424, "The expression you entered has a field, control or property name
that PC-CODAP can't find"

This doesn't make sense - the debugging loop shows the [Stage Number] control
is there, so why can I not reference it? This problem applies to all the
other controls too - not just [stage number].

Any ideas??

Thanks

John
 
B

Bob Quintal

Hi All -

I am sure this is a case of overlooking the obvious. I am trying
to adjust a form's header when the report is generated to more
accurately reflect the report's content. Until now, I have never
had a problem. The report is opened from a form VB module with:

DoCmd.OpenReport "Diagram CORCAS Prtvar", acViewPreview

In the On Format event of the report header, I have this code (for
debugging purposes):

Debug.Print "List of controls"
Debug.Print "================"
Dim ctl As Control
For Each ctl In Me.Controls
Debug.Print ctl.Name, ctl.ControlType
Next

MsgBox "Current form/report is " & Me.Name
MsgBox "Stage number is " & Me![Stage Number]

The (edited) output from the For Each ctl loop looks like this:

List of controls
================
<<Snipped>>
dataset_id 109
Stage Number 109 << Note this one
kp1 109
kp2 109
<<snipped>>

and it get all the right control names and types.

MsgBox "Current form/report is " & Me.Name displays the correct
name

However, this code line:

MsgBox "Stage number is " & Me![Stage Number] produces:

Error 2424, "The expression you entered has a field, control or
property name that PC-CODAP can't find"

This doesn't make sense - the debugging loop shows the [Stage
Number] control is there, so why can I not reference it? This
problem applies to all the other controls too - not just [stage
number].

Any ideas??

Thanks

John
1) Try putting some delimiters around the debug.print to see if
there are some leading or trailing spaces...
Debug.Print "/" & ctl.Name & "/", ctl.ControlType

2) is it possible that [Stage number] is some esoteric control like
a section footer?
 
J

J_Goddard via AccessMonster.com

Thanks for the suggestions -

But like I said, I overlooked the obvious. Buried in the code for the report
was a line which changed the RecordSource for the report ( probably from a
cut-and-paste ), so Access wasn't complaining about the Report fields - it
was the Controlsource.

Once I took the offending code out, I was able to get going again.

Thanks

John


Bob said:
[quoted text clipped - 51 lines]

1) Try putting some delimiters around the debug.print to see if
there are some leading or trailing spaces...
Debug.Print "/" & ctl.Name & "/", ctl.ControlType

2) is it possible that [Stage number] is some esoteric control like
a section footer?
 

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