| Public Function CopyLBToTB(lstControl As Object, _ txtControl As Object, Optional Separator As String = " ", _ Optional Append As Boolean = False) As Boolean 'Purpose: Copies contents of a List Box, Combo Box, or 'other control with a similar interface to a text box, 'rich text box, or any control that supports a text 'property 'PARAMETERS: lstControl: The Source List Box 'txtControl: The Destination Text Box 'Separator (Optional): The character to 'separate the items within the text box. 'Use vbcrlf here if you want each item on 'a separate line 'Append (Optional) If true, lstControl items will 'be appended to existing text in txtControl 'RETURNS: True if successful, false othwerwise Dim vTest As Variant Dim lCtr As Long, lCount As Long Dim sContents As String On Error GoTo ErrorHandler vTest = lstControl.ListCount vTest = lstControl.ListIndex If vTest <> -1 Then vTest = lstControl.List(0) vTest = txtControl.Text lCount = lstControl.ListCount - 1 For lCtr = 0 To lCount sContents = sContents & lstControl.List(lCtr) If lCtr < lCount Then sContents = sContents & Separator Next txtControl.Text = IIf(Append, _ txtControl.Text & Separator & sContents, sContents) CopyLBToTB = True ErrorHandler: End Function |
Copy List Control Contents to Text Control |
Express News India | Freelance ecommerce web development India