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

The Day() function

Status
Not open for further replies.

MichaelintheUK

Programmer
May 24, 2003
88
GB
I am confused by the inconsistency of the Day function in MS Access - I have a module where I need to get
the Year(myDate),
the Month(myDate) and
the Day(myDate) with myDate being a date variable.

The month and year work fine - however the day gives a type 13 error. I am working around it by getting the "dd" format of myDate e.g.

myDay = format(myDate,"dd").

However what can account for this inconsistency?

Thanks

Michael
 
format returns a string
day returns an integer

if you dimensions myDay as a string you get
myDay = some integer
thus type mismatch
 
The problem is with the duse of the Day function not working on a date variable

debug.? day(mydate)

result type 13 error
 
and what about
?myDate
and
?vartype(myDate)
 
Thanks for the reply

The date is taken from a combo box and placed in a date variable e.g.

dim myDate as Date
dim myday as Integer

myDate= CDate(cmbDate)
myDay = Day(myDate)

The use of the Year() and Month() functions work fine, only Day() gives the type 13 error.

Examples from the immediate window
___________________________________________
? mydate
04/04/2002
? day(mydate) **no value** instead message box with type 13 error

? month(mydate)
4
? year(mydate)
2002
? vartype(mydate)
7
_____________________________________________

I wonder if there is some kind of glitch or corruption in the particular application.

Thanks
 
compact and repair and compile your code.
Looks like a glitch because with a variable type of 7 (date) the day function should work.
try
?day(now)
and if you get an error try in a new database in the immediate window.
 
Hello MajP

Thanks for your tips.

I have compacted/repaired the mdb several times.

I am doing maintenance work on someone else's application that is about 5 or 6 years old.

The day function works on other forms in the same application. I need to dig deep into the application (quite a big one) - I find it best to avoid obvious fieldnames such as name, date, description etc.

Thanks

Michael
 
Don't you have any object named Day in your form ?
What about VBA.Day(mydate) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top