Class module properties in queries

R

Rick

I'm trying to create a class module with properties so that I can use the
properties throughout my Access application. Specifically, I'm trying to use
them in queries. However, I find that class module properties don't work in
queries. (seems wierd since this Access is a database app!) Does anyone
know a solution to enable using properties in queries. I prefer them to
lengthy verbose Form controls and variables that have limited scope. I can
store the data in a table and do a DLookup in queries, but would be
interested to see a better method, if available.

Thanks,
Rick
 
D

Dirk Goldgar

Rick said:
I'm trying to create a class module with properties so that I can use the
properties throughout my Access application. Specifically, I'm trying to
use
them in queries. However, I find that class module properties don't work
in
queries. (seems wierd since this Access is a database app!) Does anyone
know a solution to enable using properties in queries. I prefer them to
lengthy verbose Form controls and variables that have limited scope. I
can
store the data in a table and do a DLookup in queries, but would be
interested to see a better method, if available.


Use a standard module, not a class module. A class module has to be
instantiated, and any reference to the properties has to be qualified by a
reference to the instance of the class. But a standard module doesn't have
to be instantiated, and a public property defined in a standard module can
be referred to from queries with no need for any qualification. I've done
this many times.
 
R

rick

I put the properties in a standard module, but my queries still don't
recognize the properties. They are recognized elsewhere.
 
R

rick

Ok... A property is named PriorFromDate in the standard module with a Get
property as follows:

Dim m_PriorFromDate
Dim m_PriorToDate
Dim m_CurrentFromDate
Dim m_CurrentToDate

Public Property Get PriorFromDate() As Date
PriorFromDate = m_PriorFromDate
End Property

I changed my reference in my query from PriorFromDate to PriorFromDate() and
it works. Is that how you do it?

Thanks.
 
D

Dirk Goldgar

rick said:
Ok... A property is named PriorFromDate in the standard module with a Get
property as follows:

Dim m_PriorFromDate
Dim m_PriorToDate
Dim m_CurrentFromDate
Dim m_CurrentToDate

Public Property Get PriorFromDate() As Date
PriorFromDate = m_PriorFromDate
End Property

I changed my reference in my query from PriorFromDate to PriorFromDate()
and
it works. Is that how you do it?


Yes. It has to have the parentheses so that it will be recognized as a
function and the query processor will call VBA to evaluate it. Sorry I
didn't mention that.
 
M

mcescher

Yes.  It has to have the parentheses so that it will be recognized as a
function and the query processor will call VBA to evaluate it.  Sorry I
didn't mention that.

So, how does that differ from a standard function?

Public Function PriorFromDate() As Date
PriorFromDate = m_PriorFromDate
End Function

Thanks for the clarification.
Chris M.
 
R

rick

Not much. It pretty much renders the properties useless. Actually, I
currently use a function in my queries.
 
D

Dirk Goldgar

mcescher said:
So, how does that differ from a standard function?


From the point of view of retrieving the value from a query, not at all.
Used internally by VBA code, a property has the advantage that you can write
it as well as read it (assuming you implement a Property Let/Set procedure).
It gives you a simple handle on a piece of information while allowing you to
write code to be executed when that datum is written or read.
 

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