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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function undefined

Status
Not open for further replies.
Aug 3, 2004
13
US
Any ideas as to why access is giving me the error that this function is undefined? It's entered as you see below and is compiled without errors.
---------------------BEGIN CODE
Option Explicit
Function Getwkdate()
Dim currentdate As String
currentdate = Getwkdate
Select Case currentdate
Case "Sunday" ' Sunday
Getwkdate = "" & Date - Weekday(Date) + 1
Case "Monday" ' Monday
Getwkdate = "" & Date - Weekday(Date) + 2
Case "Tuesday"
Getwkdate = "" & Date - Weekday(Date) + 3
Case "Wednesday"
Getwkdate = "" & Date - Weekday(Date) + 4
Case "Thurday"
Getwkdate = "" & Date - Weekday(Date) + 5
Case "Friday"
Getwkdate = "" & Date - Weekday(Date) + 6
Case "Saturday"
Getwkdate = "" & Date - Weekday(Date) + 7
End Select
End Function
---------------------------END CODE

A little background. I am attemtping to extrapolate the date based on a day name. I have a form designed to print a set of reports for any day of the week. You select the day from the combo box and it calls a report based on a query that selects data with the day selected in the combo box as it's criteria.

Example:

myday has it's criteria set to form_name!combo_box

wkdaydate: getwkdate([myday])

It looks simple enough, the function compiles with no errors but Access tells me it's undefined.
 
Typo: You have:
Code:
Function Getwkdate()
and
Code:
wkdaydate: getwkdate([myday])
[code]
The [b]g[/b]etwkdate is not capitalized

That is problem # 1

Next, you also are using it in 2 ways, the function as shown for your module does not take a value, but you are trying to give it a value in your example..

Stephen         [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
The actual query has it capitalized, I generally use the builder and point it to the function through that, less chance of typos. As for the passing a string, I have tried the code
Function Getwkdate(currentdate)

As well as

Function Getwkdate()
Dim currentdate As String

And both methods return the function as being undefined.
 
Your problem is in this statement
Code:
currentdate = Getwkdate
It should be...
Code:
currentdate = Format(Date, "dddd")


Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
I think that what you want can be more easily done using a formula like this
Code:
Function Getwkdate() As Date
   Getwkdate = Int(Date / 7) * 7
End Function
You can "adjust" the "start on" day by +/- inc...
Code:
Function Getwkdate() As Date
  inc = -1
  Getwkdate = Int((Date + inc) / 7) * 7
End Function


Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
My new code looks as follows

------------BEGIN CODE
Option Compare Database
Option Explicit
Public Function Getwkdate(ByVal currentdate As String) As String
Dim returndate As String
currentdate = Format(Date, "dddd")
Getwkdate = currentdate
Select Case currentdate
Case "Sunday"
returndate = "" & Date - Weekday(Date) + 1
Case "Monday"
returndate = "" & Date - Weekday(Date) + 2
Case "Tuesday"
returndate = "" & Date - Weekday(Date) + 3
Case "Wednesday"
returndate = "" & Date - Weekday(Date) + 4
Case "Thurday"
returndate = "" & Date - Weekday(Date) + 5
Case "Friday"
returndate = "" & Date - Weekday(Date) + 6
Case "Saturday"
returndate = "" & Date - Weekday(Date) + 7
End Select
Getwkdate = returndate
End Function
------------------END CODE

And is still giving me undefined function error.
 
How are you USING the function when you get the error?

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
Thanks for the effort Skip, I tried your code as well and still get undefined function error.
 
AGAIN...

How are you USING the function when you get the error?

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
Here's the SQL from my Query. The tables routesbyday and routesbydriver each contain one half of our route table. Each day the routes change so I merge the two halves based on the day. As you can see I'm using it to represent a value in a query. This example is from the version I tried with your code, I have been using Getwkdate([drivers_days_tbl.day]) AS Myday

SELECT Drivers_Days_TBL.cdrivno, Drivers_Days_TBL.cname, Drivers_Days_TBL.Day, routesbyday!route & routebydriver!route AS route, Getwkdate() AS Myday
FROM (Drivers_Days_TBL LEFT JOIN RoutesByDay ON Drivers_Days_TBL.Day = RoutesByDay.Day) LEFT JOIN RouteByDriver ON Drivers_Days_TBL.cdrivno = RouteByDriver.Driver
WITH OWNERACCESS OPTION;
 
I disagree with your last code posting. I used this function in a query with success. However, I question the VALUE that it is returning.
Code:
Public Function Getwkdate() As String
         Dim returndate As String, currentdate As String
         currentdate = Format(Date, "dddd")
         Select Case currentdate
         Case "Sunday"
            returndate = "" & Date - Weekday(Date) + 1
         Case "Monday"
            returndate = "" & Date - Weekday(Date) + 2
         Case "Tuesday"
            returndate = "" & Date - Weekday(Date) + 3
         Case "Wednesday"
           returndate = "" & Date - Weekday(Date) + 4
        Case "Thurday"
           returndate = "" & Date - Weekday(Date) + 5
        Case "Friday"
           returndate = "" & Date - Weekday(Date) + 6
        Case "Saturday"
           returndate = "" & Date - Weekday(Date) + 7
       End Select
       Getwkdate = returndate
   End Function


Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
I'm not positive it will return the correct value, I haven't been able to get that far.
 
Based on the CURRENT DATE, what VALUE are you trying to return?

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
Currentdate is a bit of a misnomer I suppose. I culled it from some code I found elsewhere and never bothered to change it. What I am looking to get is, if the user selects Monday from the combo_box the query returns Mondays date, same for tues, weds, etc.
 
Got it working, with a tweak or two and DUH, had to add some references in my tools.

Code follows

Option Compare Database
Option Explicit
Public Function Getwkdate(currentdate As String) As Date

Select Case currentdate
Case "Sunday" ' Sunday
Getwkdate = Date - Weekday(Date) + 1
Case "Monday" ' Monday
Getwkdate = Date - Weekday(Date) + 2
Case "Tuesday"
Getwkdate = Date - Weekday(Date) + 3
Case "Wednesday"
Getwkdate = Date - Weekday(Date) + 4
Case "Thursday"
Getwkdate = Date - Weekday(Date) + 5
Case "Friday"
Getwkdate = Date - Weekday(Date) + 6
Case "Saturday"
Getwkdate = Date - Weekday(Date) + 7
End Select
End Function
 
Pass your combobox string in the function
Code:
Function Getwkdate(dow As String) As String
   Select Case dow
      Case "Sunday"
         Getwkdate = "" & Date - Weekday(Date) + 1
      Case "Monday"
         Getwkdate = "" & Date - Weekday(Date) + 2
      Case "Tuesday"
         Getwkdate = "" & Date - Weekday(Date) + 3
      Case "Wednesday"
         Getwkdate = "" & Date - Weekday(Date) + 4
      Case "Thurday"
         Getwkdate = "" & Date - Weekday(Date) + 5
      Case "Friday"
         Getwkdate = "" & Date - Weekday(Date) + 6
      Case "Saturday"
         Getwkdate = "" & Date - Weekday(Date) + 7
   End Select
End Function


Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
also...

Make sure that your FUNCTION is in a MODULE and not in the Form Code window.

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top