469,645 Members | 1,514 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Month function

In my code, i tried to use month function but it returned an type
mismatch error. Pls help. Thanks.

Dim mymonth As Integer
mymonth = Month([Date_req]) * [date_req] is a date type
Rgds,
Daniel
Nov 12 '05 #1
2 2584
da*******@time.net.my (Daniel Tan) wrote in
news:6a**************************@posting.google.c om:
Dim mymonth As Integer
mymonth = Month([Date_req]) * [date_req] is a date type


Assuming that Date_req is a field in a recordset, the code will fail when
it is Null. Either use the NZ function, or trap it properly

With rst
If IsNull(!Date_req) Then
MsgBox "There is no date"
MyMonth = -1

Else
MyMonth = Month(!Date_req)

End If

End With

HTH
Tim F
Nov 12 '05 #2
what is the value of date_req ?
I just put a field on a form, defaulted it to date() and put your code
in the 'exit' event and it works fine

the 'format' of this field is 'medium date'

if you add 'Debug.Print CLng(date_req)', what value do you get in the
debug (ctl-g) window ?

I get 37987 for a date of 1/1/4

da*******@time.net.my (Daniel Tan) wrote in message news:<6a**************************@posting.google. com>...
In my code, i tried to use month function but it returned an type
mismatch error. Pls help. Thanks.

Dim mymonth As Integer
mymonth = Month([Date_req]) * [date_req] is a date type
Rgds,
Daniel

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by James Fortune | last post: by
18 posts views Thread by PC Datasheet | last post: by
4 posts views Thread by laredotornado | last post: by
10 posts views Thread by Jim | last post: by
3 posts views Thread by ats | last post: by
6 posts views Thread by Nkhosinathie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.