vba - Items.restrict method to look for items that are sent today -


i'm trying write code download weekly assignments (attachments) , save folder.

i got code goes through every item , downloads attachments goes latest earliest date. need latest 1 earlier attachments overwrite later ones.

i added restrict method items sent today still goes through whole inbox.

sub downloadattachment()  dim ns namespace dim inbox mapifolder dim item object dim myitems items dim atmt attachment dim filename string dim integer dim sfilter string   'setting variable inbox. set ns = getnamespace("mapi") set inbox = ns.getdefaultfolder(olfolderinbox) **sfilter = "[receivedtime]>=""&date()12:00am&""" set myitems = inbox.items.restrict(sfilter)**  = 0  'error handling. on error goto downloadattachment_err  'if no attachments, msgbox displays. if inbox.items.count = 0     msgbox "there no messages in inbox.", vbinformation, _             "nothing found"     exit sub end if  'goes through each item in inbox attachments. each item in inbox.items     each atmt in item.attachments     if right(atmt.filename, 3) = "txt"         filename = "c:\losscontroldbases\pendingworkdownload\" & atmt.filename         atmt.saveasfile filename         = + 1     end if     next atmt next item  'if attachments found, displays message. if > 0     msgbox "i found " & & " attached files." _     & vbcrlf & "i have saved them c:\losscontroldbases\pendingworkdownload." _     & vbcrlf & "have nice day!"  else     msgbox "i didn't find attached files in mail." end if  'clearing memory. downloadattachment_exit:     set atmt = nothing     set item = nothing     set ns = nothing     exit sub  'error handling code. downloadattachment_err:     msgbox " unexpected error has occured."  end sub 

your code references "date" string literal value. use

filter = "[receivedtime]>= '" & cstr(date()) & " 12:00am' " 

Comments