By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

Get a Function call from a query

P: 6
I have a function wrote in a module that will return fiscal month of our calendar as following.

Function getDueMonth(DueDate As Date)

Dim DueMonth As Integer
Set fd = New clsFiscalDate
fd.SetDate = DueDate
DueMonth = fd.MonthNumber
'Debug.Print DueMonth
End Function

The print value is correct by using Debug.

I want to use this function in one of my queries but it seems it is not correctly called. No record shows using this query although some records exist. Could anyone give me hints to do this.

My query is as following
"SELECT Grade.studentName, Grade.score FROM Grade WHERE Grade.dueMonth = getDueMonth(Now());
Dec 27 '06 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,646
I have a function wrote in a module that will return fiscal month of our calendar as following.

Function getDueMonth(DueDate As Date)

Dim DueMonth As Integer
Set fd = New clsFiscalDate
fd.SetDate = DueDate
DueMonth = fd.MonthNumber
'Debug.Print DueMonth
End Function

The print value is correct by using Debug.

I want to use this function in one of my queries but it seems it is not correctly called. No record shows using this query although some records exist. Could anyone give me hints to do this.

My query is as following
"SELECT Grade.studentName, Grade.score FROM Grade WHERE Grade.dueMonth = getDueMonth(Now());
Hi. You have not set a return type or value for your function:
Expand|Select|Wrap|Line Numbers
  1. Function getDueMonth(DueDate As Date) As Integer
  2.  
  3.     Dim DueMonth As Integer
  4.     Set fd = New clsFiscalDate
  5.     fd.SetDate = DueDate
  6.     DueMonth = fd.MonthNumber
  7. 'Debug.Print DueMonth
  8.    getDueMonth = DueMonth
  9. End Function
Dec 27 '06 #2

P: 6
Hi. You have not set a return type or value for your function:
Expand|Select|Wrap|Line Numbers
  1. Function getDueMonth(DueDate As Date) As Integer
  2.  
  3.     Dim DueMonth As Integer
  4.     Set fd = New clsFiscalDate
  5.     fd.SetDate = DueDate
  6.     DueMonth = fd.MonthNumber
  7. 'Debug.Print DueMonth
  8.    getDueMonth = DueMonth
  9. End Function
Thank you very much. I know how to write a function to return a value now.
Dec 27 '06 #3

100+
P: 1,646
Thank you very much. I know how to write a function to return a value now.
You are very welcome
Dec 27 '06 #4

NeoPa
Expert Mod 15k+
P: 31,186
Leucine,
I strongly recommend that you declare ALL the variables you use.
Not doing so will lead you into hard to find errors.
In the VBA window select Tools / Options and check 'Require Variable Declaration' on the Editor tab.
This will then insist that all variables you use are defined first. This has so many benefits! It is only not mandatory because M$ want to encourage all types of newbies to be able to start using VBA. The problems it causes are not M$'s responsibility it seems...
Dec 30 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.