reading emails from Outlook to SQL Linked Tables

rocky09

Registered User.
Local time
Today, 09:35
Joined
Nov 21, 2012
Messages
51
Hi All,

I have a Issue System where user can open tickets and input their comments in it. The tables are SQL linked tables.

I am trying to implement auto fetch emails by adding a Button. Basically, it will goes to a particular folder "Working" in Outlook and get all the emails which are not marked as "Copied".

Here is the code.
Code:
Public Sub myinbox()
Dim TempRst As DAO.Recordset
Dim Rst As DAO.Recordset
Dim Olapp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object

Dim db As DAO.Database
Dim dealer As Integer
Dim Olfolder As Outlook.MAPIFolder
Dim kr As String

'MsgBox "It will take some time. So, Hang On!"

Set db = CurrentDb

Set Olapp = CreateObject("Outlook.Application")
Set Inbox = Olapp.GetNamespace("Mapi").GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A03003683A021347CC54C82688B880BB383EC000000B95F710000")



'
Set InboxItems = Inbox.Items
Set TempRst = CurrentDb.OpenRecordset("working") ' Table

For Each Mailobject In InboxItems
    'If Mailobject.UnRead Then
    If Mailobject.Categories <> "Copied" Then
   
    With TempRst
   
      
        .AddNew
      
        !Title = Mailobject.Subject
       ' !From = Mailobject.SenderName
       ' !To = Mailobject.To
       ' !Body = Mailobject.Body
        !OpenedDate = Mailobject.ReceivedTime
        '!email = Mailobject.SenderEmailAddress
        !OpenedBy = "Group1"
        !Priority = "(2) Normal"
        !Status = "Pending"
        .Update
        Mailobject.Categories = "Copied"
        Mailobject.Save
        Mailobject.UnRead = False
               
   
    End With

End If
Next

Set Olapp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing

MsgBox "Emails updated successfully"

End Sub
The above code is working fine with the Local tables (which i tested Locally without linking to SQL). But, when I am trying to run the same code with the Linked SQL tables. I am getting error at this line.

Error : "Object variable or with block not set"

Code:
Set TempRst = CurrentDb.OpenRecordset("working")
Can any one help me?

Office Versions Using: 2007 and 2010
 

Users who are viewing this thread

Back
Top Bottom