Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Nov 2006
    Location
    Cockeysville, Maryland, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multi-Select Listbox -> Multiple Word Documents (XP, 2003)

    Hello again, Woody's.

    First off, thanks again to Hans for squaring me away on the merge information, as that part of my DB is working wonderfully. Here's my next, and I think last, hurdle.

    I've got a multi-select listbox (lstMultiPrint) that I want to be able to use to print a selected letter (selected elsewhere on the form in lstLetters) for multiple points of contact that are displayed in lstMultiPrint. For instance, Clients A, B, and C should all get Letter B. I want to select Letter B from lstLetters, select Clients A, B, & C from lstMultiPrint, and click the command button (cmdMultiPrint) and be done with it.

    After a bit of searching, I came up with the following code to get ahold of the multiple selected items in the listbox:

    <code> Dim varItem As Variant
    Dim strWhere As String

    For Each varItem In Me.lstMultiPrint.ItemsSelected
    strWhere = strWhere & ", '" & Me.lstMultiPrint.ItemData(varItem) & "'"
    Next
    If Not strWhere = "" Then
    strWhere = Mid(strWhere, 3)
    strWhere = "grade in (" & strWhere & ")"
    End If</code>

    That code appears to store all of the selected clients as "strWhere". Is that correct? I'm not really sure where to go from here. I have that code, and my letter creation code, but I'm not positive where, and how, the two should be joined. I think I need Word to create multiple documents from my template, and merge the data for each of the individual records at the same time.

    I've also seen quite a few people suggest using subforms, as opposed to a multi-select listbox. If this is the way to go, can someone please advise me how to proceed that way as well?

    If anyone needs me to provide anymore information, please just ask.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Multi-Select Listbox -> Multiple Word Documents (XP, 2003)

    In your previous thread you weren't using mail merge in the 'official' sense of the term, you were using Automation to populate a Word document from Access. Are you still using Automation, or have you switched to real mail merge?

  3. #3
    New Lounger
    Join Date
    Nov 2006
    Location
    Cockeysville, Maryland, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multi-Select Listbox -> Multiple Word Documents (XP, 2003)

    My apologies. I used the word merge, but am still using automation.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Multi-Select Listbox -> Multiple Word Documents (XP, 2003)

    You could have a command button with code like this:

    Private Sub cmdLetter_Click()
    Dim varItem As Variant
    Dim strRecipient As String
    If Me.lstLetters.ListIndex = -1 Then
    MsgBox "Please select a letter!", vbExclamation
    Me.lstLetters.SetFocus
    Exit Sub
    End If
    If Me.lstMultiPrint.ItemsSelected.Count = 0 Then
    MsgBox "Please select one or more recipients!", vbExclamation
    Me.lstMultiPrint.SetFocus
    Exit Sub
    End If
    For Each varItem In Me.lstMultiPrint.ItemsSelected
    strRecipient = Me.lstMultiPrint.ItemData(varItem)
    ' code to create letter for this recipient goes here
    ' or is called from here
    Next varItem
    End Sub

    You'll have to replace the comment lines with the appropriate code, where strRecipient can be used as the name of the recipient.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •