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

Email contents of listview? 1

Status
Not open for further replies.

Rob7412

Technical User
Jan 26, 2006
31
US
any simple way of clicking a button and having the app bring up my default email handler and pasting the contents of a listview on my form called lv1

Thanks in advance.
 
Rob:

I hope this helps.

Code:
Private Sub Command1_Click()
SendEMail
End Sub

Private Sub Form_Load()
Dim itmX As ListItem
Dim i As Integer
For i = 0 To 5
Set itmX = LV1.ListItems. _
      Add(, , "Hello" & i)
Next

End Sub

Public Sub SendEMail()

    Dim strIniPath, strLine As String
    Dim FSO, txtFile1
        
    Set myOlApp = CreateObject("Outlook.Application")
    Set myitem = myOlApp.CreateItem(olMailItem)
    
    Dim i As Integer, s As String
    For i = 1 To LV1.ListItems.Count ' - 1
    s = s & LV1.ListItems(i) & vbCrLf
    Next
        myitem.Body = s
    ''
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    ''this will add recipients from a text file
    strIniPath = App.Path & "\Address.txt"
    If FSO.fileexists(strIniPath) Then
        Set txtFile1 = FSO.OpenTextFile(strIniPath, 1, False)
        On Error GoTo ExitErr
        
        Do While Not txtFile1.AtEndOfStream
        
            strLine = txtFile1.readline
            myitem.Recipients.Add (strLine)
            
        Loop
        
    End If
ExitErr:

''if you use a text file to add recipients, uncomment the next line
    'txtFile1.Close
    myitem.Display
    ''if you want to autosend, replace "Display" with "Send"
    
            
End Sub

Very basic, but you should get the idea.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Thanks I went out of town and just now am returning to the normal life. This worked like a champ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top