Trying to check for the absence of mail.

Not open for further replies.

Lucas Lichte

New Member
Outlook version
Outlook 2013 32 bit
Email Account
Office 365 Exchange
I'm trying to check for the absence of an email in a folder. I have a bot sending to this folder every 15 minutes. I want to check every 30 minutes to see if I've gotten an email in the last 30 minutes, and if I haven't, pop up a message box. The problem I'm running into is that I can't figure out how VBA for Outlook does Dates, and I can't find a reference.

The called Macro I'm trying to write is:

Sub Check_GWAAR()
Dim myOlItems As Object
Dim compareDate As Date
Dim sentDate As Date
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders("Test@GWAAR").Items
Set compareDate = DateAdd("m", -30, Now)
Set sentDate = myOlItems.Items(1).ReceivedTime
If sentDate < compareDate Then MsgBox ("Check the GWAAR Test VM!")
End Sub

It's telling me that the variables need to be set to objects. When I set them to objects, it tells me the Set statements don't evaluate to objects.


Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Try searching for something like VBA date format excel - there are a lot of samples for Excel and most date functions work the same. Even VB date stuff is the same. has a chart of codes.

This is months:
Set compareDate = DateAdd("m", -30, Now)

I think i would use

correction: you need to use decimals / fraction of a day when using time or now - 24 hours = 1.
if olItem.recievedtime > now - .03 then
msgbox "It didn't arrive"
end if

Maybe like this: (i did not test it)

Public Sub CheckMail()
  Dim objNS As NameSpace
  Dim objFolder As MAPIFolder
  Dim olItem As MailItem, olItems As Items
  Set objNS = GetNamespace("MAPI")
  Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
  Set olItems = objFolder.Items
  olItems.Sort "ReceivedTime", True
  Set olItem = olItems.Item(1)
'do whatever
  If olItem.ReceivedTime < Now - 0.02 Then
  MsgBox olItem.subject & " It didn't arrive"
  End If
End Sub

What are you using as a timer? You can run it when a reminder fires:
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Outlook 2016 Outlook crashes when trying to print certain emails Using Outlook 5
M outlook 365 trying to finish my sentences Using Outlook 2
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
X I have met my waterloo trying to resolve embedded graphics problem with outlook 2007 and now 2016 Using Outlook 1
O The page that you are trying to access cannot be loaded. Using Outlook 0
C Trying to populate an appointment ComboBox from Excel Outlook VBA and Custom Forms 2
T Outlook "A program is trying to access Outlook" Using Outlook 3
S SendFromAccount - Problem trying to test existing value in open email Outlook VBA and Custom Forms 2
N Error 0x80090326 when trying to setup IMAP account on Using accounts in Outlook 1
KURTiS MAXiMUS Trying to appactivate ERP window Outlook VBA and Custom Forms 16
R Trying to extract information between two symbols from outlook subject Using Outlook 2
Danie Lawson Trying to recover calendar Using Outlook 4
L Trying to open contacts pst. file in outlook 365 Using Outlook 3
M trying to disable junk email filter. completely. Using Outlook 4
D Trying to repair Outlook rules Using Outlook 5
S Outlook 2010 trying to default Data file to calendar Using Outlook 6
C Trying to move my Business Contact Manager ver. 2003 to BCM ver. 2010 Using Outlook 3
R Trying to sync my Outlook email on iphone Using Outlook 1
A outlook trying to keep sending Using Outlook 1
P Trying to add subject and name to an email using VB Code Using Outlook 3
B Trying to get old emails from a not working computer but having trouble. Using Outlook 6
P Outlook works, but freezes when trying to use calender v2007 (vista prof) Using Outlook 1
K A program is trying to send an e-mail message on your behalf... Using Outlook 1
P Trying to get 'Calendar Name' to appear like 'Subject' and 'Location' in event Using Outlook 0
S Trying to have a prompt to ask for text to be added to subject before sending. Using Outlook 3
A Trying to connect to exchange Exchange Server Administration 3
K Wont send or recieve now with new server keeps asking for password when trying Using Outlook 1
D Outlook "Trying to Connect" Exchange Server Administration 1
P Word experienced and error trying to open the file Using Outlook 2
S Trying to install BCM 2010 x64, getting error BCM (Business Contact Manager) 8
D Outlook 2003 - A program is trying to access e-mail addresses Outlook VBA and Custom Forms 5
S Trying to create a UPS from Outlook VBA and Custom Forms 2
T Trying to start Outlook from VBA or VBS not working. Outlook VBA and Custom Forms 4
S how to disable security message in save attachments macro "A programis trying to access e-mail addre Outlook VBA and Custom Forms 5
A Error: 3033 when trying to OpenDatabase using DAO Outlook VBA and Custom Forms 3
U Recovered PST file "Cannot move item" error when trying to move e- Using Outlook 6
D Error trying to connect to database on the server BCM (Business Contact Manager) 1
D Trying to reconnect BCM databases in Outlook 2003 BCM (Business Contact Manager) 1
D Spell check Outlook VBA and Custom Forms 3
L Spell-check dictionary confusion Using Outlook 0
S How to export urls from email to excel and check the status of the url ? Using Outlook 5
N Private check box in table view Using Outlook 0
S Outlook to check for specific text Outlook VBA and Custom Forms 3
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
A Check for words in subject header before sending email Outlook VBA and Custom Forms 4
R Using "check for duplicates" for existing contacts Using Outlook 2
P Suppress dialog box on email check error? Using Outlook 5
Potty Ash MS Outlook 2010 custom form - validation or formula to request user to check a checkbox Outlook VBA and Custom Forms 16

Similar threads