Using Class Module Functions in a Query

  • Thread starter Thread starter Rob G
  • Start date Start date
R

Rob G

Hello All,

I consider myself on at least an intermediate level in Access and VBA
programming, but I am just beginning to explore creating class modules.

My question is, if I create a function in a class module can I use it in a
query? I tried and it didn't seem to work.

For example, I use a function in a query that returns a percentile. I tried
doing that, but I just get an 'Undefined Function' error message. I
understand why, I think.

Does it even make sense to use the function this way or are class modules
really for organizing in VBA code and nothing else?

Any enlightenment would be greatly appreciated.

Thanks.

-Rob
 
Rob,

Below is an example of a module that simply adds two fields together...

------------------------------------------------------
Option Compare Database
Option Explicit

Function TestAdd(F1, F2 As Long)

TestAdd = F1 + F2

End Function
------------------------------------------------------

In the "Field" section of your query you would type something like this...

TestAdd([Field1],[Field2])


This is a simple example but it should be enough to get you started.

Tom
 
Back
Top