Question re date

  • Thread starter Thread starter Kitty
  • Start date Start 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!
 
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
 
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
 
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.)
 
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!
 
Have to let you debug that, Kitty.

Perhaps it has a different name?
 
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
 
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.
 
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]
 
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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top