Hello All,
I am hoping someone can help me with a problem in VBA, I am pretty sure its an easy solution but my knowledge is limited with VBA, I am a bit of a newbie.
I have a calender table which contains every date for a year (April to April) and the corresponding week number.
I am coding a button to scroll through these week numbers to display that specific week in a form below, so far it works fine!
Private Sub Command76_Click()
On Error GoTo Err_Command76_Click
Dim week As String
Dim lastweek As String
lastweek = DMax("[WeekNo]", "tblCalendar")
week = Me.txtWeekNo
If week = lastweek Then
Me.txtWeekNo = "1"
DoCmd.Requery
cboName.Locked = False
DoCmd.GoToRecord , , acFirst
Else
week = Me.txtWeekNo + 1
Me.txtWeekNo = week
DoCmd.Requery
cboName.Locked = False
DoCmd.GoToRecord , , acFirst
End If
Exit_Command76_Click:
Exit Sub
Err_Command76_Click:
MsgBox Err.Description
Resume Exit_Command76_Click
'Me.txtWeekNo = Null
End Sub
My problem is thus:
Because the dates run April to April the actually last week number is 13. I need to use a bit of code which looks at the last date (31/03/2011) and gives me the week that date corresponds too so I can stop the user going past this week number. I am pretty sure its a Dmax but I am not sure how to go about it. Any help would be appreciated.
Regards,
John (Finchy) Finch
I am hoping someone can help me with a problem in VBA, I am pretty sure its an easy solution but my knowledge is limited with VBA, I am a bit of a newbie.
I have a calender table which contains every date for a year (April to April) and the corresponding week number.
I am coding a button to scroll through these week numbers to display that specific week in a form below, so far it works fine!
Private Sub Command76_Click()
On Error GoTo Err_Command76_Click
Dim week As String
Dim lastweek As String
lastweek = DMax("[WeekNo]", "tblCalendar")
week = Me.txtWeekNo
If week = lastweek Then
Me.txtWeekNo = "1"
DoCmd.Requery
cboName.Locked = False
DoCmd.GoToRecord , , acFirst
Else
week = Me.txtWeekNo + 1
Me.txtWeekNo = week
DoCmd.Requery
cboName.Locked = False
DoCmd.GoToRecord , , acFirst
End If
Exit_Command76_Click:
Exit Sub
Err_Command76_Click:
MsgBox Err.Description
Resume Exit_Command76_Click
'Me.txtWeekNo = Null
End Sub
My problem is thus:
Because the dates run April to April the actually last week number is 13. I need to use a bit of code which looks at the last date (31/03/2011) and gives me the week that date corresponds too so I can stop the user going past this week number. I am pretty sure its a Dmax but I am not sure how to go about it. Any help would be appreciated.
Regards,
John (Finchy) Finch