•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,528 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,741 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 2373 | Replies: 6 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Please help..
I am trying to create an outlook script that will parse the subject line of emails coming from a particular source and organize them, by the ticket number present in the subject line. However, VB is sucking the life out of me on the error below
I am getting a Compile Error: Object Required on the line
Dim subjectLine as String
Set subjectLine = Item.Subject.
If I take the same MailItem (Item) object and pass the Subject property to the MsgBox()
it works...So I am beat on this one bad.
Please view the complete script below...Any and all the help will be greatly appreciated.
I am trying to create an outlook script that will parse the subject line of emails coming from a particular source and organize them, by the ticket number present in the subject line. However, VB is sucking the life out of me on the error below
I am getting a Compile Error: Object Required on the line
Dim subjectLine as String
Set subjectLine = Item.Subject.
If I take the same MailItem (Item) object and pass the Subject property to the MsgBox()
it works...So I am beat on this one bad.
Please view the complete script below...Any and all the help will be greatly appreciated.
Sub CustomMailMessageRule(Item As Outlook.MailItem)
Const folderInbox = 6
Const ticketsFldName = "tickets"
Const nutrioFldName = "nutrio"
Dim objFolder As Outlook.Folder
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(folderInbox)
Dim ticketsFolder As Outlook.Folder
Dim nutrioFolder As Outlook.Folder
ticketsFolder = objFolder.Folder(ticketsFldName)
If (ticketsFolder Is Nothing) Then
ticketsFolder = objFolder.Folders.Add(ticketsFldName)
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
ElseIf (nutrioFolder Is Nothing) Then
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
End If
Dim subjectLine As String
Set subjectLine = Item.Subject
Set begIndexHash = InStr(0, "#", subjectLine)
Set endIndexColon = InStr(0, ":", subjectLine)
Dim ticketNumber As String
If (begIndexHash = 0 Or endIndexColon = 0) Then
Return
Else
Set ticketNumber = Mid$(subjectLine, begIndexHash + 1, (endIndexColon - begIndexHash) - 1)
End If
Set ticketNewFolder = nutrioFolder.Folders.Add(ticketNumber)
Item.Move (ticketNewFolder)
End Sub•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
I found a bug, which has not solved the problem but just wanted to update the code
[code] Sub CustomMailMessageRule(Item As Outlook.MailItem)
Const folderInbox = 6
Dim objFolder As Outlook.Folder
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(folderInbox)
Dim ticketsFolder As Outlook.Folder
Dim nutrioFolder As Outlook.Folder
ticketsFolder = objFolder.Folders("tickets")
If (ticketsFolder Is Nothing) Then
ticketsFolder = objFolder.Folders.Add(ticketsFldName)
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
ElseIf (ticketsFolder.Folders("nutrio") Is Nothing) Then
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
End If
Dim subjectLine As String
Set subjectLine = Item.Subject
Set begIndexHash = InStr(0, "#", subjectLine)
Set endIndexColon = InStr(0, ":", subjectLine)
Dim ticketNumber As String
If (begIndexHash = 0 Or endIndexColon = 0) Then
Return
Else
Set ticketNumber = Mid$(subjectLine, begIndexHash + 1, (endIndexColon - begIndexHash) - 1)
End If
Set ticketNewFolder = nutrioFolder.Folders.Add(ticketNumber)
Item.Move (ticketNewFolder)
End Sub
[\code]
[code] Sub CustomMailMessageRule(Item As Outlook.MailItem)
Const folderInbox = 6
Dim objFolder As Outlook.Folder
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(folderInbox)
Dim ticketsFolder As Outlook.Folder
Dim nutrioFolder As Outlook.Folder
ticketsFolder = objFolder.Folders("tickets")
If (ticketsFolder Is Nothing) Then
ticketsFolder = objFolder.Folders.Add(ticketsFldName)
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
ElseIf (ticketsFolder.Folders("nutrio") Is Nothing) Then
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
End If
Dim subjectLine As String
Set subjectLine = Item.Subject
Set begIndexHash = InStr(0, "#", subjectLine)
Set endIndexColon = InStr(0, ":", subjectLine)
Dim ticketNumber As String
If (begIndexHash = 0 Or endIndexColon = 0) Then
Return
Else
Set ticketNumber = Mid$(subjectLine, begIndexHash + 1, (endIndexColon - begIndexHash) - 1)
End If
Set ticketNewFolder = nutrioFolder.Folders.Add(ticketNumber)
Item.Move (ticketNewFolder)
End Sub
[\code]
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks for the reply....I was just about to post that solution myself...was trying different approaches
But now I am getting another wierd error...maybe you can help with this
I am getting Run Time Error:
"The operation Failed: An object could not be found" on
ticketsFolder = objFolder.Folders(ticketsFldName)
All help will be greatly appreciated
Sub CustomMailMessageRule()
Const folderInbox = 6
Const ticketsFldName = "tickets"
Const nutrioFldName = "nutrio"
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(folderInbox)
Dim ticketsFolder As Outlook.MAPIFolder
Dim nutrioFolder As Outlook.MAPIFolder
ticketsFolder = objFolder.Folders(ticketsFldName)
If (ticketsFolder Is Nothing) Then
ticketsFolder = objFolder.Folders.Add(ticketsFldName)
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
ElseIf (ticketsFolder.Folders(nutrioFldName) Is Nothing) Then
nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
End If
Dim subjectLine As String
subjectLine = Item.Subject
Dim begIndexHash As Integer
Dim endIndexColon As Integer
begIndexHash = InStr(0, "#", subjectLine)
endIndexColon = InStr(0, ":", subjectLine)
Dim ticketNumber As String
If (begIndexHash = 0 Or endIndexColon = 0) Then
Return
Else
ticketNumber = Mid$(subjectLine, begIndexHash + 1, (endIndexColon - begIndexHash) - 1)
End If
Dim ticketNewFolder As Outlook.MAPIFolder
ticketNewFolder = nutrioFolder.Folders.Add(ticketNumber)
Item.Move (ticketNewFolder)
End SubBut now I am getting another wierd error...maybe you can help with this
I am getting Run Time Error:
"The operation Failed: An object could not be found" on
ticketsFolder = objFolder.Folders(ticketsFldName)
All help will be greatly appreciated
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks for your help...Here is the final script that works...
Sub CustomMailMessageRule(Item As Outlook.MailItem)
On Error GoTo PROBLEM
Const folderInbox = 6
Const ticketsFldName = "tickets"
Const nutrioFldName = "nutrio"
Dim objFolder As Outlook.Folder
Dim ticketsFolder As Outlook.Folder
Dim nutrioFolder As Outlook.Folder
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(folderInbox)
Set ticketsFolder = Nothing
Set nutrioFolder = Nothing
Set ticketsFolder = objFolder.Folders(ticketsFldName)
If (ticketsFolder Is Nothing) Then
Set ticketsFolder = objFolder.Folders.Add(ticketsFldName)
Set nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
Else
Set nutrioFolder = ticketsFolder.Folders(nutrioFldName)
If (nutrioFolder Is Nothing) Then
Set nutrioFolder = ticketsFolder.Folders.Add(nutrioFldName)
End If
End If
Dim subjectLine As String
Dim begIndexHas As Integer
Dim endIndexColon As Integer
Dim ticketNumber As String
subjectLine = Item.Subject
begIndexHash = InStr(subjectLine, "#")
endIndexColon = InStr(begIndexHash, subjectLine, ":")
If (begIndexHash = 0 Or endIndexColon = 0) Then
Exit Sub
Else
ticketNumber = Mid$(subjectLine, begIndexHash + 1, (endIndexColon - begIndexHash - 1))
End If
Dim ticketNewFolder As Outlook.Folder
Set ticketNewFolder = Nothing
Set ticketNewFolder = nutrioFolder.Folders(ticketNumber)
If (ticketNewFolder Is Nothing) Then
Set ticketNewFolder = nutrioFolder.Folders.Add(ticketNumber)
End If
Item.Move ticketNewFolder
PROBLEM:
If (Err.Number = 424) Then
MsgBox (Err.Description & Err.Number)
End If
Resume Next
End Sub![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- runtime error 91 object variable or With block variable not set (Visual Basic 4 / 5 / 6)
- javascript - object required error (JavaScript / DHTML / AJAX)
- VB6 - Outlook Email set up - Error 424: Object required (Visual Basic 4 / 5 / 6)
- Error 424-object required (Visual Basic 4 / 5 / 6)
- compile error (C++)
- compile error (C)
- VB6 RTE '424' Object required. (Visual Basic 4 / 5 / 6)
- PLEASE help with project - compile error (C++)
- Runtime Error 424 object required (was: Please Help!) (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Flex Grid,Data Report
- Next Thread: help with select statement


Linear Mode