beruken
May 24th, 2001, 09:30 AM
I am trying to set the Label Caption consisting of 12 labels (not an array)Named LABEL1 - LABEL12 on an access 2000 form. I would like to set the caption for those 12 labels base on the current month and year. I determined how to evaluate the caption value, but can't figure out how to set LABEL(i) since Access VBA thinks this is a function. Also Access doesn't prompt to create a control array when cutting and pasting a current Label control. Example code below.
Private Sub Form_Load()
Dim curMonth As Date
Dim curYear As Date
Dim strMonthYear As String
Dim remainMonths As Integer
Dim i As Integer
'Dim Label(1 To 12) As Label
curMonth = Month(Date)
curYear = Year(Date)
For i = curMonth To 12
strMonthYear = MonthName(i, True) & curYear
Label(i).Caption = strMonthYear
Next
' Determine how many months in the following year
If curMonth > 1 Then
remainMonths = (curMonth - 1)
For i = 1 To remainMonths
strMonthYear = ((MonthName(i, True)) & " " & (curYear + 1))
Label(i).Caption = strMonthYear
Next
End If
End Sub
Thanks, KEn
Private Sub Form_Load()
Dim curMonth As Date
Dim curYear As Date
Dim strMonthYear As String
Dim remainMonths As Integer
Dim i As Integer
'Dim Label(1 To 12) As Label
curMonth = Month(Date)
curYear = Year(Date)
For i = curMonth To 12
strMonthYear = MonthName(i, True) & curYear
Label(i).Caption = strMonthYear
Next
' Determine how many months in the following year
If curMonth > 1 Then
remainMonths = (curMonth - 1)
For i = 1 To remainMonths
strMonthYear = ((MonthName(i, True)) & " " & (curYear + 1))
Label(i).Caption = strMonthYear
Next
End If
End Sub
Thanks, KEn