Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Value of Report Label in Report on load event

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
US
I need to know how to set the value of a reports label and text box through VBA. I am using the on_load event procedure and my current non-working code is:

While intMonth <= 12

lblValue = &quot;Me.lblMth&quot; & intMonth
txtValue = &quot;Me.txtMth&quot; & intMonth

lblValue.Caption = Left(strMonth, 3)
txtValue.Text = strMonth & &quot;-&quot; & strYear

intMonth = intMonth + 1
Wend



 
need more information
what is the value of strMonth and strYear
you say it is not working what is the result
 
strMonth and strYear change every time the process loops. generally something like (March - 2002) My goal is to set the control source of the text boxes to = the value of the columns listed in the query. Since the query columns (like March - 2002) change based on the data that is processed, it is necessary to have to report source values change with the query.
 
the result I get is an error that says invalid qualiferand it points to lblValue. I have this set as a string. If I set it to a Label then I get an error on
lblValue = &quot;Me.lblMth&quot; & intMonth here is the complete code that I have

Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database
Dim frm As Form_RUN_REPORTS
Dim intMonth As Integer
Dim intYear As Integer
Dim intCounter As Integer
Dim strYear As Integer
Dim lblValue As String
Dim 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 = &quot;Me.lblMth&quot; & intMonth
txtValue = &quot;Me.txtMth&quot; & intMonth

lblValue.Caption = Left(strMonth, 3)
txtValue.Text = strMonth & &quot;-&quot; & strYear

If intMonth = 12 Then
intMonth = 1
intYear = intYear + 1
Else
intMonth = intMonth + 1
End If

intCounter = intCounter + 1
Wend

End Sub
 
if your query field names are jan-2002 feb-2002 ect.
name your text boxes text0, text1,
and try this

dim mydb as database
dim rst as recordset
set mydb=currentdb
set rst=mydb.openrecordset(&quot;queryname&quot;)
for co = 1 to rst.field.count
me.controls(&quot;text&quot;& co-1)= rst.field(co).name
next co

i did not test this excet code but i ame looping true the controls and the filds name

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top