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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set textbox control source in Report_On_Open

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
US
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 = &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
 
For all who may want to know here is the way I was able to fo it

Private Sub Report_Open(Cancel As Integer)

Dim mydb As Database
Dim rst As Recordset
Dim ctr As Integer
Dim rpt As [Report_Bed Day Summary]
Dim lblObj As Label
Dim txtObj As TextBox


Set mydb = CurrentDb


Set rst = mydb.OpenRecordset(&quot;99999 Report - Beddays Summary&quot;)

For ctr = 1 To rst.Fields.Count - 1

Set lblObj = Me(&quot;lblMth&quot; & ctr)
Set txtObj = Me(&quot;text&quot; & ctr)

lblObj.Caption = rst.Fields(ctr).Name
txtObj.ControlSource = rst.Fields(ctr).Name

Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top