Question re date

K

Kitty

i hv a button called "Last Month" and 2 text box called "fm" and "to"

can i set that when i click the Last Month button, the value of the "fm"
text box then change to the first day of last month and the value of the
"to" text box then change to the last day of last month??

thx in advance!
 
A

Allen Browne

The Day() function returns the day of the month.
If you subtract that from the month, you get the last of the previous month.

Me.to = Date - Day(Date)
Me.fm = Me.to - Day(Me.to) + 1
 
K

Kitty

thx~
one more question.. i get the first day of the current month by using the
formula: Date - Day(Date)+1
if i wanna show the last day of the current month.. how can i set??
and also how to set the next month?? thx
 
A

Allen Browne

Last of this month:
DateSerial(Year(Date()), Month(Date()) + 1, 0)

First of next month:
DateSerial(Year(Date()), Month(Date()) + 1, 1)

(Note that Access is capable of sorting out the 13th month and the zeroth
day.)
 
K

Kitty

thx again~
i try the following code on two files, one has no problem however another
one dun work and a msg box popup when i click the NM button: error 438,
object dun support this property or method.

Private Sub NM_Click()
Me.Fm.Value = DateSerial(Year(Date), Month(Date) + 1, 1)
Me.To.Value = DateSerial(Year(Date), Month(Date) + 2, 0)
End Sub

do u know what's the problem?? pls help me to solve that~ thx so much!
 
K

Kitty

i found that i cant use the function of Year(Date) in my code..

if i change my code like the following, then it works..
so strange that cant use Year(Date) on my code..
do u hv any idea??

Private Sub NM_Click()
Me.Fm.Value = DateSerial(2005, Month(Date) + 1, 1)
Me.To.Value = DateSerial(2005, Month(Date) + 2, 0)
End Sub
 
A

Allen Browne

There is a conflicting name somewhere.

Could be a field name or control name on your form.
Could be another function or sub or object or variable with that name.

Check that your code compiles okay (Compile on Debug menu, from code
window).

It would be good to find and solve it, but one way to work around the
problem might be to use:
VBA.Year(
instead of just:
Year(
to disambiguate what you want.
 
J

John Vinson

i found that i cant use the function of Year(Date) in my code..

In addition to Allen's suggestions, check your references:

This appears to be the very common References bug. Open any
module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.

John W. Vinson[MVP]
 
J

John Vinson

as i'm using chinese version.. are u talking about the attached pic?? where
should i check?

Yes. The third unchecked checkbox - Microsoft DAO 3.6 Object Library.

John W. Vinson[MVP]
 
Top