Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Location
    Lake City, Forida
    Posts
    5

    Creating a string from all records in a table

    I use the following code to build a string from items selected in a listbox by the user:


    __________________________________________________ _______
    Private Sub SendEmail_Click()

    Dim varItem As Variant
    Dim strTO As String

    For Each varItem In Me.lstTO.ItemsSelected
    strTO = strTO & ",'" & Me.lstTO.ItemData(varItem) _
    & "'"
    Next varItem

    End Sub
    __________________________________________________ _______

    I would like however, to avoid having the user select the items but rather, build the string automatically from the table or at least have the code use all the items in the listbox, which are the same items in the table since I'm populating the listbox from the table. Any ideas?

  2. #2
    StepUP is offline Advanced Beginner
    Windows 7 64bit Access 2000
    Join Date
    Dec 2005
    Posts
    99
    Code:
    For varItem = 0 To Me.lstTO.ListCount - 1
        strTO = strTO & ",'" & Me.lstTO.ItemData(varItem) & "'" 
    Next varItem

  3. #3
    Join Date
    Aug 2006
    Location
    Lake City, Forida
    Posts
    5
    It worked like a charm. It was so simple I'm almost embarrassed.

    Thanks JohnF.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 10-23-2008, 12:08 AM
  2. Creating top values with two records
    By avesamuel in forum Queries
    Replies: 0
    Last Post: 10-15-2007, 10:45 PM
  3. Delete all records in a table?
    By bob646 in forum Access
    Replies: 1
    Last Post: 05-20-2007, 11:41 PM
  4. Replies: 1
    Last Post: 12-06-2006, 05:32 PM
  5. Replies: 1
    Last Post: 03-17-2006, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums