function as criteria for a query

tebule

Registered User.
Local time
Today, 16:26
Joined
Oct 8, 2008
Messages
38
I have created a query and in the criteria I entered a function name:
=GetDate.

The code for get date is as follows:
Function GetDate()
Dim dtedteEntered As Date
Dim checking As String
dtedteEntered = Forms!frmMain.PeriodStartDate.Value
GetDate = "#" & dtedteEntered & "#"
End Function

When I run the query and type in the date it runs fine, but using this code it is returning nothing. I have seen this done before, but I am at a loss as to how to recreate it. Any ideas?
 
What is the purpose of the function, all you need in the criteria is
Forms!frmMain!PeriodStartDate

Brian
 
Talked with my friend and now it works...

Here is the code:

Function GetDate() As Date
Dim dtedteEntered As Date
dtedteEntered = Forms!frmMain.PeriodStartDate.Value
GetDate = dtedteEntered
End Function


I missed defining the return veriable....:rolleyes:
 
Hi Brian,
Yup that would have worked, but I wanted to use it one multiple boxes and didn't want to hard code it. Thanks so much for the help!
Thanks,
Bre
 
What is the purpose of the function, all you need in the criteria is
Forms!frmMain!PeriodStartDate

Brian
Some prefer to write reams of code to do the simplest things in Access;)
 
If you are going to use the function then why not just

Function GetDate() As Date
GetDate = Forms!frmMain.PeriodStartDate.Value
End Function

Brian
 
tebule

in the query you have to say

=GetDate() 'with the brackets, to retrieve the vlaue from the function, I think
 

Users who are viewing this thread

Back
Top Bottom