Outlook COM: MailItem.Restict(Filter) HELP Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
alex10superman
Posts: 2
Joined: 20 Feb 2019, 12:55

Outlook COM: MailItem.Restict(Filter) HELP

21 Mar 2019, 12:26

Hello All,

I'd like some help figuring out why my restrict filter is not working. Here is a sample of my code that works:

Code: Select all

 outlook := ComObjActive("Outlook.Application")
 outlooknamespace := outlook.GetNameSpace("MAPI")
 inboxfolder := outlooknamespace.GetDefaultFolder(6)
 currentmessage := inboxfolder.Items.Restrict("[Unread] = True").GetLast()
 clipboard := currentmessage.senderemailaddress
    msgbox % clipboard
That works as expected. However, if i move the Filter to a variable, with this code:

Code: Select all

Filter := """[Unread] = True"""
 
 outlook := ComObjActive("Outlook.Application")
 outlooknamespace := outlook.GetNameSpace("MAPI")
 inboxfolder := outlooknamespace.GetDefaultFolder(6)
 currentmessage := inboxfolder.Items.Restrict(Filter).GetLast()
 clipboard := currentmessage.senderemailaddress
    msgbox % clipboard


it fails with error message:

Error: 0x80041200
Source: Microsoft Outlook
Description: Condition is not valid
etc. etc.
----> currentmessage := inboxfolder.items.Restrict(Filter).GetLast()


I am planning a more specific and complex filter with variables in it, which would make it ideal to set aside into its own "Filter" variable, but i can't seem to make it work.

I am running Win10 x64 v1809 and AHK 1.1.30.01. Also Outlook 2016.
Any suggestions and help would be greatly appreciated.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: Outlook COM: MailItem.Restict(Filter) HELP  Topic is solved

21 Mar 2019, 14:38

Code: Select all

Filter :=	"[Unread] = True"	; <~~~ no literal quotes
 
 outlook :=	ComObjActive("Outlook.Application")
 , outlooknamespace :=	outlook.GetNameSpace("MAPI")
 , inboxfolder :=	outlooknamespace.GetDefaultFolder(6)
 , currentmessage :=	inboxfolder.Items.Restrict(Filter).GetLast()
 , clipboard :=	currentmessage.senderemailaddress
msgbox %	clipboard
:?:
alex10superman
Posts: 2
Joined: 20 Feb 2019, 12:55

Re: Outlook COM: MailItem.Restict(Filter) HELP

21 Mar 2019, 16:46

sinkfaze wrote:
21 Mar 2019, 14:38

Code: Select all

Filter :=	"[Unread] = True"	; <~~~ no literal quotes
 
 outlook :=	ComObjActive("Outlook.Application")
 , outlooknamespace :=	outlook.GetNameSpace("MAPI")
 , inboxfolder :=	outlooknamespace.GetDefaultFolder(6)
 , currentmessage :=	inboxfolder.Items.Restrict(Filter).GetLast()
 , clipboard :=	currentmessage.senderemailaddress
msgbox %	clipboard
:?:

:crazy: I spent way to much time on this and then ended up being something simple, thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google Adsense [Bot], yuu453 and 291 guests