Criteria with user defined function

B

BJC

If I create a user defined function that finds a specific date,
can I use that function as the criteria for a date field in a query.


Regards
BJC
 
B

BJC

Thanks John for you help.
The function runs, but it's not passing the date into the criteria.
I'm obviously doing something worng in the function.
Following is the function with a breif description of
what I'm trying to do.

Public Function PreviousYTD() As Date
LY = DatePart("yyyy", Now()) 'Gets the Year of the current date
LY = LY - 1 'Makes the current year become the previous year
m = DatePart("m", Now()) 'Gets the current month
d = DatePart("d", Now()) 'Gets the current day
LastYTD = d & "/" & m & "/" & LY 'Recombines the current D&M for LAST
YEAR
LastYTD = CDate(LastYTD)

Beep
End Function

I put the beep in just to confirm that the
function infact runs, which it does.
But I'm not getting any results from the function.
How do I get the LastYTD variable passed to the
criteria of the query.
Following are the reasons for this function.
I have a table consisting of Ticket Sales for Last Year.
I'm creating a report for Sales this year and want to
compare the sales To Date for this year to all the sales
that were made up to the current Month/Day Last Year.
In other words all last years records up to July 16 2002.
Obviously the table contains records for Last Year
beyond July 16(or the current date). I want ot eliminate them.
I'm sure this isnt' as clear as it can be.
Let me know if you need more info to offer some more
help, if your so inclined.

Thanks in advance.
Brad
 
D

Dan Artuso

Hi,
You have to set the Function to the value you want returned:
PreviousYTD = CDate(LastYTD)

Are you not declaring any of your variables?
 

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