Updating Year in Code

arunakumari02

Registered User.
Local time
Today, 15:26
Joined
Jun 2, 2008
Messages
91
I have a form with months Jan --- Dec.

When click on the scroll bar the months should be moved and the year should be updated.

For Example:

Year(2008)
Jan Feb .............Dec

When I click on scroll bar it

Year(2009)
Feb Mar April ......Dec Jan

The year should be updated once the month reaches January.

Code:

My code does not updated year. Any hints?


Private Function ScrollHorizontal(intMoveMonth As Integer)

txtYear1 = Format(CDate("1/1/" & Year(Date)), "yyyy")


txtMonth1 = DateAdd("m", intMoveMonth, CDate("1/1/" & txtYear1))
Debug.Print "txtMonth1"; txtMonth1

For intMonth = 2 To 12
Forms("frmxx")("txtMonth" & (intMonth)) = DateAdd("m", intMonth - 1, txtMonth1)

Next

End Function
 
you must be doing something wrong with the dateadd. make sure all your variables are being filled. heres a quick example that works

Code:
Private Sub button1_Click()
Dim newdate As String
newdate = DateAdd("m", 1, Me.Text1.Value)

Me.Text1.Value = newdate
Me.Text1.Requery
End Sub
this is for a form with a button and textbox
 
That did not help.

As I move scroll bar the month should be moved when the Jan comes again the year should be updated. (check the first post)

Moving month works but I not knowing how to update the year.

Moving months code is posted. (works)


txtYear1 = Format(CDate("1/1/" & Year(Date)), "yyyy")
Debug.Print "txtYear1" & txtYear1


txtMonth1 = DateAdd("m", intMonthToMove, CDate("1/1/" & txtYear1))
Debug.Print "txtMonth1"; txtMonth1

For intMonth = 2 To 12
Forms("frmxx")("txtMonth" & (intMonth)) = DateAdd("m", intMonth - 1, txtMonth1)
Debug.Print "txtMonth" & intMonth

Next

Any help is appreciated.
 
I have to update year after 12 clicks (i.e after moving 12 months) on the scrollbar?

Any help really appreciated.
 
its not working because your splitting the date up into months and years. for the date add to work in the way that you want (as far as is know) it has to be in this format (mm/dd/yyyy). if you want to split the numbers up on your form, on the onclick event concat all the fields into the above mentioned format. then run the code i gave you. then split it back up and update the fields.
 

Users who are viewing this thread

Back
Top Bottom