Only two possibilities occur to me:
1) Text80 isn't actually a text box: it's some other type of control
(such
as a label)
2) [Forms]![frmUnder50KItemsTrackingParms]![BudgetType] isn't a valid
reference
Try:
Private Sub Report_Open(Cancel As Integer)
Dim strOutput As String
Dim strYears As String
Dim varSelected As Variant
With Forms!frmUnder50KItemsTrackingParms!FiscalYear
For Each varSelected In .ItemsSelected
strYears = strYears & .ItemData(varSelected) & ", "
Next varSelected
End With
If Len(strYears) > 0 Then
strYears = Left$(strYears, Len(strYears) - 2)
End If
strOutput = "FY " & strYears & " Under50K " & _
[Forms]![frmUnder50KItemsTrackingParms]![BudgetType] & _
" Capital Projects"
Me.Text80 = strOutput
End Sub
If the line strOutput = ... now raises the error, then the problem is
likely
the reference to [Forms]![frmUnder50KItemsTrackingParms]![BudgetType].
If the line Me.Text80 = strOuput now raises the error, then the problem
is
with the Text80 control.
I've reformatted the code above so that it shouldn't word-wrap. (I also
added back the ", " which you seem to have dropped.)
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Ally said:
Yes Douglas. That's the single line highlighted in yellow after I click
the
debug button. My completed code is following:
Private Sub Report_Open(Cancel As Integer)
Dim strYears As String
Dim varSelected As Variant
For Each varSelected In
Forms!frmUnder50KItemsTrackingParms!FiscalYear.ItemsSelected
strYears = strYears &
Forms!frmUnder50KItemsTrackingParms!FiscalYear.ItemData(varSelected)
Next varSelected
If Len(strYears) > 0 Then
strYears = Left$(strYears, Len(strYears) - 2)
End If
Me.Text80 = "FY " & strYears & " Under50K " &
[Forms]![frmUnder50KItemsTrackingParms]![BudgetType] & " Capital
Projects"
End Sub
Would you please advise?
Thanks a lot!
Ally
:
Yes, Text80 should be unbound.
Is that a single line of code you're showing? (it should be) Is the
quote
there at the beginning? (it shouldn't be)
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Douglas,
I still did not make it working. The error message is " You cannot
assign
a
value to this object. " The cursor stays at the line :
"Me.Text80 = "FY " & strYears & " Under50K " &
[Forms]![frmUnder50KItemsTrackingParms]![BudgetType] & " Capital
Projects"
Please help! BTW, I have a empty text control named Text80 (Unbound)
in
the
report. Is this right?
Thanks,
Ally
Okay, this may be the error to which you were referring elsethread.
Sorry, that was my typo. It should be
For Each varSelected In
Forms!frmUnder50KItemsTrackingParms!FiscalYear.ItemsSelected
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Douglas,
I replace "MyTextbox" in the code with "Text80", which is the
name
of
the
text control in the report. Currently the text box control is
empty,
which
has no expression on the report. Is this right?
After placing the suggested code as following in the code:
Me.Text80 = "FY " & strYears & " Under50K " &
[Forms]![frmUnder50KItemsTrackingParms]![BudgetType] & " Capital
Projects"
I have the Run-Time error "438" saying Object doesn't support
this
property
or method. The cursor stays on the follwing line after clicking
Debug:
For Each varSelected In
Forms!frmUnder50KItemsTrackingParms!FiscalYear
Also, I set the MultiSlect property of the FiscalYear list box in
the
form
as Extended because I do need to choose multiple Fiscal year
sometimes.
Please advise.
Thanks,
Ally
:
Has the list box been set to allow MultiSelect? If so, then yes,
it
works
differently than a combo box. You won't be able to simply refer
to
it:
you'll need VBA to loop through its ItemsSelected collection,
concatenating
all of the selected items and then putting that concatenated
list
on
the
report.
Something like this should do it:
Private Sub Report_Open(Cancel As Integer)
Dim strYears As String
Dim varSelected As Variant
For Each varSelected In Forms!frmForm1!FiscalYear
strYears = strYears &
Forms!frmForm1!FiscalYear.ItemData(varSelected)
&
", "
Next varSelected
If Len(strYears) > 0 Then
strYears = Left$(strYears, Len(strYears) - 2)
End If
Me.MyTextBox = strYears
End Sub
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
I have two controls in a form: a list box named "FiscalYear"
and a
comb
box
named "BudgetType". I need to print two controls on a report.
I
used
the
follwing in the text control on the report:
=Forms!frmForm1!BudgetType and
=Forms!frmForm1!FiscalYear
However, when it works for budget type control but not Fiscal
year.
I did put " Print Forms!frmForm1!FiscalYear" to Immediate
Window,
but I
get
Null in the immediate window. I think that's why I could not
print
out
on
the
report for what I chosed for FiscalYear from the form. but
don't
know
why....Do comb box and list box work different on the report
when
you
are
trying to print out the control? Does anyone know how?
Thanks a lot!
Ally