Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • Last Modified:

Using Outlook and VBA to automate an email application, having trouble cycling through Inbox...

Hello,
I have written some VBA that is triggered when an email comes into the Inbox (outlook 2000).  The VBA connects to a DB, finds some information, then responds to the email with that information.  That email is then moved to a different folder in Outlook. Then, I have query that checks the Inbox to see if there are more emails.  if there is one, a variable grabs the top record (the first email in the Inbox), and assigns it to an Object variable.  

The problem:

olInboxItems_ItemAdd(ByVal Item As Object)

seems to not want to let me call it again and pass the next email to it.  I am trying to figure out how to get the VBA to cycle through the emails of there are more in the inbox.  

This is where I query the inbox, assign the next email to the variable, and pass it through... all i keep getting is "Object required" Error no matter what i try:
(Dims)
objNS2 is a Namespace
myFolder is a MAPIFolder
tempItem is an Object

----****other code****----
Set objNS2 = Application.GetNamespace("MAPI")
Set myFolder = objNS2.GetDefaultFolder(olFolderInbox)

'assign the next email to tempItem
Set tempItem = myFolder.Items(1)

'pass tempItem to the original function to start the process again with a new email
olInboxItems_ItemAdd (tempItem)
----****other code****----

I AM DESPERATE!!!!!!  Can you help?

Thank you SOOOOOOOOOOO much for your help!

Eric

PS... the few times it accepted something, it simply used the original email and never picked up the new one... then after two more lines, it crashed. hope this doesnt confuse!
0
ajet7
Asked:
ajet7
1 Solution
 
rjcpjcCommented:
This function fires once for every email received. You should be using the intrinsic Item object. You shouldn't need to run the code multiple times as the code should run once for every email that's received.  The function isn't designed to be called from itself.

That benig said, VBA code in Outlook isn't a 100% guarantee either :-/
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now