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

Month function

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.