turnerk200
Programmer
Hello, I am trying to create controls on a form from the items selected in a list box on a seperate form. At the moment, my code only reads the first item selected in the list box, then jumps out of the If...end if statement, I am sure it is obvious, I just cannot seem to work it out, have pasted the code below. Many thanks in advance to anybody who can help.
Code:
Public Sub CopySelected(byreffrm As Form)
Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer
Dim ctlLabel As Control, ctlText As Control
Set ctlSource = Forms!frmFieldCopy!lstSource
Set ctlDest = Forms!frmFieldCopy!lstDestination
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, _
intCurrentRow) & ""
'open form in design view
DoCmd.OpenForm "frmReport2", acDesign
' Create bound default-size text box in detail section.
Set ctlText = CreateControl("frmReport2", acTextBox, acDetail, "", strItems)
ctlText.Name = strItems
'strItems = ""
DoCmd.Restore
Me.Refresh
'Next intCurrentRow
End If
Next intCurrentRow
' Reset destination control's RowSource property.
ctlDest.RowSource = strItems