Print list box on a report

J

jeanulrich00

Hi

On a form named FrmMenu I have a multiple selected list box names
ListProjets

As I wanted to print selected items on a report I made a search in
this forum

I find out code that was given by Douglas J. Steele. So I copy the
code. Hers is my code

Private Sub Report_Open(Cancel As Integer)

Dim strProjets As String
Dim varSelected As Variant

For Each varSelected In Forms!FrmMenu!ListProjets.ItemSelected

strProjets = strProjets & Forms!FrmMenu!
ListProjets.ProjectDescription(varSelected) & ", "
Next varSelected

If Len(strProjets) > 0 Then
strProjets = Left$(strProjets, Len(strProjets) - 2)

End If

Me.Proj = strProjets

End Sub

FrmMenu is the form where the list box is situated
ListProjets is the name of the list box
Proj is the name of the text box on the report

Same thing happened to me as the one who previously received your
answer

the code stop on the line

For Each varSelected In Forms!FrmMenu!ListProjets.ItemSelected
(yellow when you debug) and the error is 438 or something like that.

When I try to open the report FrmMenu is open

Please I realy need help

thanks
 
K

Ken Sheridan

You are missing an 's'. It should be:

For Each varSelected In Forms!FrmMenu!ListProjets.ItemsSelected

Ken Sheridan
Stafford, England
 
J

jeanulrich00

You are missing an 's'.  It should be:

For Each varSelected In Forms!FrmMenu!ListProjets.ItemsSelected

Ken Sheridan
Stafford, England























- Show quoted text -

Sorry maybe I made the wrong reply

Anyway, thanks for the missing s

Now the code stop on the next line

strProjets = strProjets & Forms!FrmMenu!
ListProjets.ProjectDescription(varSelected) & ", "

and in this line ProjectDescription is one of the list box fields

Is that ok ? and where is the mistake ?

thanks for helping
 
K

Ken Sheridan

You can't refer to a column in a list box directly by name. You can however
use the list box's Column property to return the value from any column. This
property is zero based, so Column(0) is the first column, Column(1) the
second and so on (including any hidden columns). Lets assume for example
that ProjectDescription is the second column in the list box, the code to
refer to it would be:

strProjets = strProjets & Forms!FrmMenu!ListProjets.Column(1, varSelected) &
", "

The 1 here refers to the second column and varSelected the row for each item
selected.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top