Hi,
Need Help
i am trying to read emails from outlook for today and updating the access table based on specific keyword. however it just updates the first record and does not look for any other email. also it just goes not Elseif section of code even if there is first keyword is present in email
table has ID | StaffName | staffemail | availibility Fields.
(email addresses not present in attached file)
Need Help
i am trying to read emails from outlook for today and updating the access table based on specific keyword. however it just updates the first record and does not look for any other email. also it just goes not Elseif section of code even if there is first keyword is present in email
table has ID | StaffName | staffemail | availibility Fields.
Code:
Public Sub avilibility_status()
Dim outlookApp
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim myTasks
Dim sir() As String
'Set outlookApp = New Outlook.Application
Set outlookApp = CreateObject("Outlook.Application")
Set olNs = outlookApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myTasks = Fldr.Items
For Each olMail In myTasks
If olMail.ReceivedTime >= Date And (InStr(1, olMail.Body, "Yes", vbTextCompare) > 0) Then
'olMail.Display
Me.av_status = "Available"
Me.txtsender = olMail.SenderEmailAddress
DoCmd.SetWarnings False
DoCmd.RunSQL "update table1 set availibility = '" & Me.av_status & "' where staffemail = '" & Me.txtsender & "'"
MsgBox "updated"
DoCmd.SetWarnings True
ElseIf olMail.ReceivedTime >= Date And (InStr(1, olMail.Body, "No", vbTextCompare) > 0) Then
'olMail.Display
Me.av_status = "Not Available"
Me.txtsender = olMail.SenderEmailAddress
DoCmd.SetWarnings False
DoCmd.RunSQL "update table1 set availibility = '" & Me.av_status & "' where staffemail = '" & Me.txtsender & "'"
MsgBox "updated"
DoCmd.SetWarnings True
Exit For
End If
Next
End Sub
(email addresses not present in attached file)