retrieve data from e-mails to tables  
Author Message
CreativeImages





PostPosted: Visual Basic for Applications (VBA), retrieve data from e-mails to tables Top

I want to retrieve data from e-mails, and append the data to different Access tables. The email format is constant; but I have no idea how to progress in this matter.

I realize that I need to point at or read an e-mail, select that e-mail, start a script (visual basic for applications) to select the field data, and append a specific table or a selected table.

I am using Outlook for e-mails, and Access for my database. Basically, it would be best to have an Outlook add-in that is user customizable to select e-mails first, then to select e-mail data to be appended to selected tables in Access.

What are your suggestions to resolving or completing this task Thank you.


Microsoft ISV Community Center Forums1  
 
 
duck thing





PostPosted: Visual Basic for Applications (VBA), retrieve data from e-mails to tables Top

Here's a simple example that should give you the basics you're looking for.

Private olApp As Outlook.Application
Private db As DAO.Database

Public Sub DoMyRoutine()
Dim olMailItem As Outlook.MailItem, rs As DAO.Recordset, CopyFields As Collection
Dim tstr As Variant

Set olApp = Outlook.Application
Set db = OpenDatabase("C:\TEMP\temp.mdb")
Set rs = db.OpenRecordset("data")

Set CopyFields = GetFieldCopyInfo()
If CopyFields.Count = 0 Then
MsgBox "User cancelled operation or no fields selected."
Exit Sub
End If

With rs
For Each olMailItem In olApp.ActiveExplorer.Selection
.AddNew
For Each tstr In CopyFields
If tstr = "DateSent" Then !DateSent = olMailItem.SentOn
If tstr = "SenderName" Then !SenderName = olMailItem.SenderName
If tstr = "SenderEmail" Then !SenderEmail = olMailItem.SenderEmailAddress
Next tstr
.Update
Next olMailItem
End With
End Sub


Private Function GetFieldCopyInfo() As Collection
Dim tcoll As New Collection

Load UserForm1
With UserForm1
.Show vbModal
If .cbDateSent Then tcoll.Add "DateSent"
If .cbSenderName Then tcoll.Add "SenderName"
If .cbSenderEmail Then tcoll.Add "SenderEmail"
End With
Unload UserForm1

Set GetFieldCopyInfo = tcoll
End Function

You'll need to create a form with the appropriate checkboxes and an "OK" button. I've also assumed you're using DAO to interface with a Jet DB. Hope this helps.



 
 
Malleswar





PostPosted: Visual Basic for Applications (VBA), retrieve data from e-mails to tables Top

Hi,

I have same type of requirement. But I need it with C#. I am facing few problems at

Load UserForm1

and few others.

Can any please give me this code in C# or provide any link to retrieve the selected mail list

Thanks in Advance,