get month 1/2007 after 12/2006

A

anil

hi all
I am using this functioin in my module

' looks the maximum/last date when the sampling schedule for
wastewater was generated
rst.Seek "=", DMax("Adate", "tbllog", "[sampletakenforID] = 2 ")
MsgBox "Latest Date found = '" & DMax("Adate", "tbllog",
"[sampletakenforID] = 2 ") & "' ." & vbCrLf & " " & vbCrLf & "You
already have generated the Sites for this Month."

If Month(Forms!frmww!SelectMonth) = Month(DMax("Adate", "tbllog",
"[sampletakenforID] = 2 ")) + 1 Then
' Confirms if user wants to generate the sampling schedule for next
month

now when i selects for january ,It gives message that select 13 in
month ( in form).
Can you please help so that i caould get month 1/2007 or january after
december.

thanks
anil
 
D

Douglas J. Steele

The Month function is simply returning a number between 1 and 12, and Access
has no idea that when it adds 1 to that number, it should "wrap around" to
1, rather than 13.

Try:

If Month(Forms!frmww!SelectMonth) = Month(DateAdd("m", 1, DMax("Adate",
"tbllog",
"[sampletakenforID] = 2 "))) Then

or

If Month(Forms!frmww!SelectMonth) = (Month(DMax("Adate", "tbllog",
"[sampletakenforID] = 2 ")) + 1 Mod 12) Then
 
A

anil

thanks Douglas
First Method worked.
I tried the same method yesterday but was giving error.
must be wrong time of day or any small error.
Thanks for your time and help
anil said:
The Month function is simply returning a number between 1 and 12, and Access
has no idea that when it adds 1 to that number, it should "wrap around" to
1, rather than 13.

Try:

If Month(Forms!frmww!SelectMonth) = Month(DateAdd("m", 1, DMax("Adate",
"tbllog",
"[sampletakenforID] = 2 "))) Then

or

If Month(Forms!frmww!SelectMonth) = (Month(DMax("Adate", "tbllog",
"[sampletakenforID] = 2 ")) + 1 Mod 12) Then


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


anil said:
hi all
I am using this functioin in my module

' looks the maximum/last date when the sampling schedule for
wastewater was generated
rst.Seek "=", DMax("Adate", "tbllog", "[sampletakenforID] = 2 ")
MsgBox "Latest Date found = '" & DMax("Adate", "tbllog",
"[sampletakenforID] = 2 ") & "' ." & vbCrLf & " " & vbCrLf & "You
already have generated the Sites for this Month."

If Month(Forms!frmww!SelectMonth) = Month(DMax("Adate", "tbllog",
"[sampletakenforID] = 2 ")) + 1 Then
' Confirms if user wants to generate the sampling schedule for next
month

now when i selects for january ,It gives message that select 13 in
month ( in form).
Can you please help so that i caould get month 1/2007 or january after
december.

thanks
anil
 

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

Top