Hi All,
I've setup a simple process in Outlook VBA when an email comes in it will grab the Sender, Subject, Body and received time from the email and dump it into a table (ITtbl) in Access. The problem I'm having is, I also want to attach the entire email in the access table.
I've setup an attachment field called "Attachment". The problem is I'm getting an "Object variable or with block variable not set" error on the
line.
I'm also thinking I don't have the correct syntax in my Insert line.
I've done some research but everything I've found is excel based based using the DAO recordset to add to the database.
Is what I'm trying to do even possible? Any help or push in the right direction would be greatly appreciated.
Code:
I've setup a simple process in Outlook VBA when an email comes in it will grab the Sender, Subject, Body and received time from the email and dump it into a table (ITtbl) in Access. The problem I'm having is, I also want to attach the entire email in the access table.
I've setup an attachment field called "Attachment". The problem is I'm getting an "Object variable or with block variable not set" error on the
Code:
Mattach = MyMail.attachments
I'm also thinking I don't have the correct syntax in my Insert line.
I've done some research but everything I've found is excel based based using the DAO recordset to add to the database.
Is what I'm trying to do even possible? Any help or push in the right direction would be greatly appreciated.
Code:
Code:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
'On Error Resume Next
'Mail Definitions
Dim MyMail As MailItem
Set MyMail = Application.Session.GetItemFromID(EntryIDCollection)
Dim MSub As String, MSender As String, MBody As String, Mtime As Date, Mattach As Attachment
MSub = MyMail.Subject
MSender = MyMail.Sender
MBody = MyMail.Body
Mtime = MyMail.ReceivedTime
Mattach = MyMail.attachments
If MyMail.Subject = "*Proof*" Then
'INSERT Query
Dim str As String
str = "INSERT INTO ITtbl ([From], [Subject], [Body], [Received], [Attachment]) VALUES (" & "'" & MSender & "'" & ", " & "'" & MSub & "'" & ", " & "'" & MBody & "'" & ", " & "'" & Mtime & "'" & ", " & Mattach & ")"
'Access Connection
Dim cnx As ADODB.Connection
Set cnx = New ADODB.Connection
cnx.Provider = "Microsoft.ACE.OLEDB.12.0"
cnx.ConnectionString = "\\data\Test Database\dbBE\CID_be.accdb"
cnx.Open
cnx.Execute str
Else
End If
End Sub