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 contents of emails by adding a Button.
Basically, it will goes to a particular folder "Pendings" in Outlook and get all the emails which are not marked as "Copied".
Here is the code.
Public Sub myinbox()
Dim TempRst 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 Olfolder As Outlook.MAPIFolder
'MsgBox "It will take some time. So, Hang On!"
Set db = CurrentDb
Set Olapp = CreateObject("Outlook.Application")
Set Inbox = Olapp.GetNamespace("Mapi").GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A03003683A021347CC54C82688B880BB383EC000000B95F710000") ' working folder ID
'
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 this error:
Error : "Object variable or with block not set"
at this line:
Set TempRst = CurrentDb.OpenRecordset("working")
Set TempRst = db.OpenRecordset("working")but that probably won't make a difference.Set TempRst = db.OpenRecordset("SELECT * FROM working", dbOpenDynaset)still produce the error