Using a class module for field recordsource

R

Randy K.

I have created several class modules that retrieve data from a variety of
external database tables. These are populated when user selected various
criteria on a main form. I now need to run a report that will be unbound
and then use the data previously retrieved. How do I set the recordsource
of the fields to stop getting #Name?'s???

TIA,
Randy K.
 
M

Marshall Barton

Randy said:
I have created several class modules that retrieve data from a variety of
external database tables. These are populated when user selected various
criteria on a main form. I now need to run a report that will be unbound
and then use the data previously retrieved. How do I set the recordsource
of the fields to stop getting #Name?'s???


If you have an unbound report, then the control's control
source property will be blank. You will have to use code to
fill in the values.
 
R

Randy K.

I realize they are blank to start, but would like to populate the
recordsource properties directly on the report instead of in code if
possible. For example, I have other reports where I want to use a global
varible as the recordsource so I have a function to return the value and use
"=getGlobalVariableName()" as the field's recordsource. Is this possible
using class modules as the data storage containers??

TIA,
Randy
 
M

Marshall Barton

Randy said:
I realize they are blank to start, but would like to populate the
recordsource properties directly on the report instead of in code if
possible. For example, I have other reports where I want to use a global
varible as the recordsource so I have a function to return the value and use
"=getGlobalVariableName()" as the field's recordsource. Is this possible
using class modules as the data storage containers??

I think this might be an interesting approach, but you're
starting to confuse me. I'm pretty sure you're using
"record source" for a control when you really mean "control
source". Assuming that's right, then I think you might be
able to call public functions from control source
expressions in an unbound report (since control source
expressions are not aware of classes, the functions have to
be in a standard module). If you can't, what's to keep you
from using the detail section's Format event to call the
class's properties/methods directly from the event's VBA?
Since I've never heard of anyone trying to do this before, I
suggest that you put together a simple report and try it out
to see if it works or if there are some tricky pitfalls. If
I can find some serious thinking time, I'll try to set up a
test scenario over the weekend and see for myself what
happens.

Since I can't think of a way for the report to tell the
class what/when a different record needs to be processed,
this might only work for a single "record" report.

Well, I might have to take that back in some(?) cases.
Since an unbound report can have no groups, there will be no
group headers/footers/KeepTogether/etc to mess up the
sequential processing of your "records", you probably can
use Me.NextRecord = False to tell the report that you want
to process more data and call a method in your class to move
from one "record" to the next. I'm not 100% sure if
CanGrow/CanShrink/KeepTogether will cause retreats in this
kind of situation so watch out if you use those properties.

If you do get this to work, or even if not, I'd be
interested to know how it comes out and what the issues
were.
--
Marsh
MVP [MS Access]


 
Top