How do I use a class property as criteria in an Access query?

  • Thread starter Thread starter Darrell
  • Start date Start date
D

Darrell

I have the option of referencing a control on a form for criteria in a query
which is the record source for a report, but would prefer to reference a
property of a class. This will be good practice for creating and using class
modules.

However, the query grid doesn't recognize the "class.property" and insists
on bracketing it ([Class].[Property]) and prompts for its value when the
query is run. Is there a way to do this?

Darrell
 
On Thu, 30 Oct 2008 21:44:01 -0700, Darrell

Not that I know of. You have to realize that a class is an abstract
entity, and it only becomes real when you have a variable of that
type:
dim x as MyGreatClass
select * from Customers where CustomerID=x.SomeProperty
No, that's not going to work.
But this is: you can use a public function in a standard module and
call it from a query:
select * from Customers where CustomerID=GetSomeProperty()
public function GetSomeProperty() as Integer
GetSomeProperty = x.SomeProperty
end function

I hope you get the idea.

-Tom.
Microsoft Access MVP
 
Tom said:
On Thu, 30 Oct 2008 21:44:01 -0700, Darrell

Not that I know of. You have to realize that a class is an abstract
entity, and it only becomes real when you have a variable of that
type:
dim x as MyGreatClass
select * from Customers where CustomerID=x.SomeProperty
No, that's not going to work.
But this is: you can use a public function in a standard module and
call it from a query:
select * from Customers where CustomerID=GetSomeProperty()
public function GetSomeProperty() as Integer
GetSomeProperty = x.SomeProperty
end function

I hope you get the idea.

-Tom.
Microsoft Access MVP

I have the option of referencing a control on a form for criteria in a query
which is the record source for a report, but would prefer to reference a
property of a class. This will be good practice for creating and using class
modules.

However, the query grid doesn't recognize the "class.property" and insists
on bracketing it ([Class].[Property]) and prompts for its value when the
query is run. Is there a way to do this?

Darrell

Tom, I went through the motions of replying to your post, but see now
that it apparently didn't "take."

I wanted to thank you very much since your concept was a major insight
for me. I had no idea you could call a function from a query, but it
worked beautifully. I did have a few additional challenges, but none
were related to the fundamental idea. In sum, it worked nicely. So,
thank you. I hope this makes it onto the group.

Darrell
 
Back
Top