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

Generating a form from the selected items in a list box

Status
Not open for further replies.

turnerk200

Programmer
Mar 9, 2004
20
0
0
AU
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top