Results 1 to 5 of 5
  1. #1
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402

    how do I loop through a value list on form with vba reading all list entries

    Hi, I've been trying to put together a system that uses the file dialog boxto get a list of file names of pdf files, this file list is then used to create the list of attachments for outlook to use.

    so far i can create a list of names as a seperate part.

    I can sort of loop through only the selected items in the value list as a seperate part

    I can create the automatic email and add a single file attachment or by adding several lines of outlookapp.Attachments.Add "..." I can hard code the file names of lots of files by they allways will change.

    i have tried to incorporate the 2 options above but am having a hard time using the " with / end with loops i have.



    I hope you can understand what I am looking for, if not let me know what other details I can provide.

    [code below]

    this works fine...

    Private Sub Command40_Click() 'get file list
    Dim fDialog As Office.FileDialog
    Dim varFile As Variant
    Me.filelist.RowSource = ""
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    .Title = "Select One or More Files"
    If .Show = True Then
    For Each varFile In .SelectedItems
    Me.filelist.AddItem varFile
    Next
    Else
    End If
    End With
    End Sub

    this only sort of works to get all selected entries only...

    Private Sub Command39_Click()
    Dim sWhere As String ' Where condition
    Dim lst As ListBox ' multiselect list box
    Dim vItem As Variant ' items in listbox
    Dim iLen As Integer ' length of string.
    Dim swhare, t
    Set lst = Me!filelist
    For Each vItem In lst.ItemsSelected
    If Not IsNull(vItem) Then
    sWhere = sWhere & lst.ItemData(vItem)
    End If
    Next
    Set lst = Nothing
    End Sub


    this works ok...

    Dim t, db, rs, ttt, mail_to_list
    t = MsgBox("Do you need to send an Email to the preselected list?", vbYesNo, "Send E-Mail Option")
    If t = 6 Then
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Employees")
    rs.MoveFirst
    Do While Not rs.EOF
    If rs![Auto Receive Tracking Emails] = True Then
    ttt = rs![E-Mail Address]
    mail_to_list = mail_to_list + ttt & " ' ; '"
    End If
    rs.MoveNext
    Loop
    rs.Close
    Dim myOlApp As New Outlook.Application
    Dim myItem As Outlook.MailItem
    Dim myAttachments As Outlook.Attachments
    Set myItem = myOlApp.CreateItem(olmailItem)
    Set myAttachments = myItem.Attachments
    With myItem

    here is whare i nee to add all entries from the list

    ************
    .Attachments.Add "C:\Documents and Settings\test\My Documents\default.rdp"
    ************

    .To = mail_to_list
    .Subject = "Logistics Movement"
    .Body = "Please find attached report " & vbCrLf & vbCrLf & _
    .Display
    ' SendKeys "%{s}", True
    End With
    End If
    If t = 7 Then
    Exit Sub
    End If





    regards
    Trevor

  2. #2
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402

    Cool never mind i did it. answer below

    [QUOTE=trevor40;210886]Hi, I've been trying to put together a system that uses the file dialog boxto get a list of file names of pdf files, this file list is then used to create the list of attachments for outlook to use.

    so far i can create a list of names as a seperate part.

    I can sort of loop through only the selected items in the value list as a seperate part

    I can create the automatic email and add a single file attachment or by adding several lines of outlookapp.Attachments.Add "..." I can hard code the file names of lots of files by they allways will change.

    i have tried to incorporate the 2 options above but am having a hard time using the " with / end with loops i have.

    I hope you can understand what I am looking for, if not let me know what other details I can provide.

    [code below]

    this works fine...

    Private Sub Command40_Click() 'get file list
    Dim fDialog As Office.FileDialog
    Dim varFile As Variant
    Me.filelist.RowSource = ""
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    .Title = "Select One or More Files"
    If .Show = True Then
    For Each varFile In .SelectedItems
    Me.filelist.AddItem varFile
    Next
    Else
    End If
    End With
    End Sub

    this only sort of works to get all selected entries only...

    Private Sub Command39_Click()
    Dim sWhere As String ' Where condition
    Dim lst As ListBox ' multiselect list box
    Dim vItem As Variant ' items in listbox
    Dim iLen As Integer ' length of string.
    Dim swhare, t
    Set lst = Me!filelist
    For Each vItem In lst.ItemsSelected
    If Not IsNull(vItem) Then
    sWhere = sWhere & lst.ItemData(vItem)
    End If
    Next
    Set lst = Nothing
    End Sub


    this works ok...

    Dim t, db, rs, ttt, mail_to_list
    t = MsgBox("Do you need to send an Email to the preselected list?", vbYesNo, "Send E-Mail Option")
    If t = 6 Then
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Employees")
    rs.MoveFirst
    Do While Not rs.EOF
    If rs![Auto Receive Tracking Emails] = True Then
    ttt = rs![E-Mail Address]
    mail_to_list = mail_to_list + ttt & " ' ; '"
    End If
    rs.MoveNext
    Loop
    rs.Close
    Dim myOlApp As New Outlook.Application
    Dim myItem As Outlook.MailItem
    Dim myAttachments As Outlook.Attachments
    Set myItem = myOlApp.CreateItem(olmailItem)
    Set myAttachments = myItem.Attachments
    With myItem

    here is whare i nee to add all entries from the list

    ************
    .Attachments.Add "C:\Documents and Settings\test\My Documents\default.rdp"
    ************

    .To = mail_to_list
    .Subject = "Logistics Movement"
    .Body = "Please find attached report " & vbCrLf & vbCrLf & _
    .Display
    ' SendKeys "%{s}", True
    End With
    End If
    If t = 7 Then
    Exit Sub
    End If



    this worked ok.
    Dim sWhere As String ' Where condition
    Dim lst As ListBox ' multiselect list box
    Dim vItem As Variant ' items in listbox
    Dim iLen As Integer ' length of string.
    Dim swhare
    Dim X As Integer
    Dim t, db, rs, ttt, mail_to_list
    Dim Y As Integer
    Dim fDialog As Office.FileDialog
    Dim varFile As Variant
    Me.filelist.RowSource = ""
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    .Title = "Select One or More Files"
    If .Show = True Then
    For Each varFile In .SelectedItems
    Me.filelist.AddItem varFile
    Next
    Else
    End If
    End With
    X = Me.filelist.ListCount
    For Y = 0 To X - 1
    Me.filelist.Selected(Y) = True
    Next Y
    Set db = CurrentDb
    Set rs = db.OpenRecordset("Employees")
    rs.MoveFirst
    Do While Not rs.EOF
    If rs![Auto Receive Tracking Emails] = True Then
    ttt = rs![E-Mail Address]
    mail_to_list = mail_to_list + ttt & " ' ; '"
    End If
    rs.MoveNext
    Loop
    rs.Close
    Dim myOlApp As New Outlook.Application
    Dim myItem As Outlook.MailItem
    Dim myAttachments As Outlook.Attachments
    Set myItem = myOlApp.CreateItem(olmailItem)
    Set myAttachments = myItem.Attachments
    Set lst = Me!filelist
    With myItem
    For Each vItem In lst.ItemsSelected
    If Not IsNull(vItem) Then
    ttt = lst.ItemData(vItem)
    myItem.Attachments.Add ttt
    End If
    Next
    Set lst = Nothing
    myItem.To = mail_to_list
    myItem.Subject = "Logistics Movement"
    myItem.Body = "Please find attached report for an incomming consignment" & vbCrLf & vbCrLf & _
    "This report is for Consignment # " & Me.Consignment_Note_Number myItem.Display
    ' SendKeys "%{s}", True
    End With

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    So this is resolved?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    yes it is, now onto my next problem, can you format the font of text in the above body of the email ?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    AFAIK, only with HTML code tags.
    Last edited by June7; 02-05-2014 at 03:50 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2013, 07:07 AM
  2. Replies: 2
    Last Post: 09-24-2013, 11:38 AM
  3. Replies: 3
    Last Post: 03-22-2013, 11:59 AM
  4. List box doesn't allow Unique data entries
    By Delta223 in forum Forms
    Replies: 2
    Last Post: 01-24-2011, 07:24 PM
  5. Loop through a list of table names and compare
    By mikneus in forum Programming
    Replies: 1
    Last Post: 05-21-2010, 10:36 AM

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