davman2002
Programmer
I want to know how I can set the value of a Label and a Text box in the report in the on open command. I have tried to do this but keep getting errors. Here is my code.
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database
Dim frm As Form_RUN_REPORTS
Dim frmStart As Date
Dim intMonth, intyear, intcounter, intyear As Integer
Dim strMonth, lblValue, txtValue As String
'Get referrence to current database
Set dbs = CurrentDb
Set frm = Forms(0)
'Set values = values listed in frm
frmStart = MonthValue(frm.txtStart_Month.Value)
intMonth = Month(frmStart)
intyear = Year(frmStart)
intcounter = 1
While intMonth <= 12 And intcounter <= 12
strMonth = MonthValue(intcounter)
lblValue = "Me.lblMth" & intMonth
txtValue = "Me.txtMth" & intMonth
lblValue.Caption = Left(strMonth, 3)
txtValue.Text = strMonth & "-" & stryear
If intMonth = 12 Then
intMonth = 1
intyear = intyear + 1
Else
intMonth = intMonth + 1
End If
intcounter = intcounter + 1
Wend
End Sub
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database
Dim frm As Form_RUN_REPORTS
Dim frmStart As Date
Dim intMonth, intyear, intcounter, intyear As Integer
Dim strMonth, lblValue, txtValue As String
'Get referrence to current database
Set dbs = CurrentDb
Set frm = Forms(0)
'Set values = values listed in frm
frmStart = MonthValue(frm.txtStart_Month.Value)
intMonth = Month(frmStart)
intyear = Year(frmStart)
intcounter = 1
While intMonth <= 12 And intcounter <= 12
strMonth = MonthValue(intcounter)
lblValue = "Me.lblMth" & intMonth
txtValue = "Me.txtMth" & intMonth
lblValue.Caption = Left(strMonth, 3)
txtValue.Text = strMonth & "-" & stryear
If intMonth = 12 Then
intMonth = 1
intyear = intyear + 1
Else
intMonth = intMonth + 1
End If
intcounter = intcounter + 1
Wend
End Sub