PDA

View Full Version : Setting Values for Report



esilva002
09-27-2010, 08:01 AM
Hi,

I have a report that I set values for on runtime. These values fome from a public variable that I set on the previous form. I have done this two different ways and recieve two different errors.

Procedure 1:


Dim BegDate As Date
Dim EndDate As Date
Dim NumberofDays As Integer
Dim ctr As Integer
BegDate = Me.cboYear.Value & "-" & Me.cboMonth.Value & "-" & "01"
EndDate = DateSerial(Year(BegDate), Month(BegDate) + 1, 0)
NumberofDays = DateDiff("d", BegDate, EndDate) + 1
Do Until ctr = NumberofDays
pArray1(ctr) = DateAdd("d", ctr, BegDate)
DoCmd.OpenReport "rptJudicialCalendarBLANK1", acViewPreview
With Reports!rptJudicialCalendarBLANK1
.txtInfo.Text = "SCHEDULED COURT ROOM TIME FOR " & pArray1(ctr)
.txtFooter.Text = pArray1(ctr)
End With
DoCmd.Close acReport, "rptJudicialCalendarBLANK1", acSaveYes
DoCmd.OpenReport "rptJudicialCalendarBLANK1", acViewNormal
ctr = ctr + 1
Loop


Procedure 1 finds the begining and ending of the selected month. Then finds the number of days in that month. Then I build my array with the first date, second date, and so on. Then open my report and set values using the with command. Close it and then print out the report all within a loop. So within September I should have 30 printouts of the same report, the only difference is the date.

THE PROBLEM WITH PROCEDURE 1:
When I set the .txtInfo.Text within my With Statement I get the Run-time error '2185': You can't reference a property or method for a control unless the control has the focus.

Procedure 2:


Dim BegDate As Date
Dim EndDate As Date
Dim NumberofDays As Integer
Dim ctr As Integer
BegDate = Me.cboYear.Value & "-" & Me.cboMonth.Value & "-" & "01"
EndDate = DateSerial(Year(BegDate), Month(BegDate) + 1, 0)
NumberofDays = DateDiff("d", BegDate, EndDate) + 1
Do Until ctr = NumberofDays
pArray1(ctr) = DateAdd("d", ctr, BegDate)
DoCmd.OpenReport "rptJudicialCalendarBLANK1", acViewNormal, , , , pArray1(ctr)
ctr = ctr + 1
Loop


Procudure 2 finds the number of days same as procudure 1 but this time I push the array value through the report.

The report code looks like this:


Private Sub Report_Activate()
If Not IsNull(Me.OpenArgs) Then
Me.txtInfo = "SCHEDULED COURT ROOM TIME FOR " & Me.OpenArgs
Me.txtFooter = Me.OpenArgs
End If
End Sub

Private Sub Report_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.txtInfo.Value = "SCHEDULED COURT ROOM TIME FOR " & Me.OpenArgs
Me.txtFooter.Value = Me.OpenArgs
End If
End Sub


I have the same code in Report_Open and Report_Activate. I found code on the internet that said to push values through the Report_Activate event. But I found that through debugging that Report_Activate isn't even getting hit. So, I tossed that same code in the Report_Open event.

THE PROBLEM WITH PROCEDURE 2:
In my Reprt_Open when I try and assign Me.txtInfo.Value to the variable. It gives me the Run-time error '2448' You can't assign a value to the object.

Please Help!

HiTechCoach
09-27-2010, 08:59 AM
In the code:



With Reports!rptJudicialCalendarBLANK1
.txtInfo.Text = "SCHEDULED COURT ROOM TIME FOR " & pArray1(ctr)
.txtFooter.Text = pArray1(ctr)
End With

remove the .Text


Try:


With Reports!rptJudicialCalendarBLANK1
.txtInfo = "SCHEDULED COURT ROOM TIME FOR " & pArray1(ctr)
.txtFooter = pArray1(ctr)
End With

esilva002
09-27-2010, 09:15 AM
It now prints out but does not display the date values needed. Do you think this is because I open it in preview mode, then set the values, then close the report, and open it again?

HiTechCoach
09-27-2010, 09:40 AM
It now prints out but does not display the date values needed. Do you think this is because I open it in preview mode, then set the values, then close the report, and open it again?

Why are you closing it after you set the values?

Unless you set the values into Labels in design mode and then save the report, it will not save the data form the print preview. To use a text box, you will have to set the control source.

esilva002
09-27-2010, 10:07 AM
Yea thats what I thought. so I changed the code to look like this and it works perfectly. thanks!



Dim BegDate As Date
Dim EndDate As Date
Dim NumberofDays As Integer
Dim ctr1, ctr2 As Integer
ctr1 = 1
ctr2 = 0
BegDate = Me.cboYear.Value & "-" & Me.cboMonth.Value & "-" & "01"
EndDate = DateSerial(Year(BegDate), Month(BegDate) + 1, 0)
NumberofDays = DateDiff("d", BegDate, EndDate) + 1
Do Until ctr2 = NumberofDays
pArray1(ctr1) = DateAdd("d", ctr2, BegDate)
'DoCmd.OpenReport "rptJudicialCalendarBLANK1", acViewNormal, , , , pArray1(ctr)
DoCmd.OpenReport "rptJudicialCalendarBLANK1", acViewPreview
With Reports!rptJudicialCalendarBLANK1
.txtInfo = "SCHEDULED COURT ROOM TIME FOR " & pArray1(ctr1)
.txtFooter = pArray1(ctr1)
End With
DoCmd.OpenReport "rptJudicialCalendarBLANK1", acViewNormal
DoCmd.Close acReport, "rptJudicialCalendarBLANK1", acSaveYes
ctr1 = ctr1 + 1
ctr2 = ctr2 + 1
Loop

HiTechCoach
09-27-2010, 10:47 AM
You're welcome.

Glad we could assist.