Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function arguments problem in a Query

Status
Not open for further replies.

Gavroche00

Technical User
Feb 4, 2004
49
US
Hi folks,

Don't know what I am missing. I have a function in a module that calculates the last sunday (i.e. if today is Tuesday the 6th, it will return Sunday the 4th).

I am now trying to apply this function into a query. I have a field called inputdate that writes the date of the entry in the table. So when I write NewDate:getlastSunday([inputdate]) I get the following error message:

Wrong number of arguments used with function in query expression 'getlastSunday([inputdate])'. Anyone knows why?

Thank you
 
Can you post the getlastSunday function?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You should be able to use the following to get the date for the last Sunday using todays date:

Code:
DateAdd("d", ((DatePart("w", Date()) - 1) * -1) , Date())

Give it a try.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Here is the function:

Function Getlastsunday()
Dim dDate As Date
dDate = Date
Do Until Format(dDate, "dddd") = "Sunday"
dDate = dDate - 1
Loop
Getlastsunday = dDate

Is my syntax incorect in the way I call the function with the argument in the query?

I noticed that the brackets are put around the field name 'inputdate' that I want it or not.

Thank you for help in resolving this.

David
 
The error is in the function declaration. You ControlSource calls the function sending the parameter [inputdate], but the function does not allow for a parameter.

Function Getlastsunday(InputDate as Variant)

or, since it does not appear that the function needs the parameter, remove the arguement from the Controlsource.

=getlastSunday()

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thank you, Thank you. I got it to work thanks to your help.

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top