Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Appending Time to Subject as Messages come in.

0 views
Skip to first unread message

MS News

unread,
Jan 7, 2003, 9:44:55 AM1/7/03
to

I can't get this to work...i want to modify the subject to the form "(old
subject), (current time)" for every message recieved!
It all seems to work fine but it does not update the subject!
It is called at the right time and the message box DOES display what I want
to change to subject to...Just does not update the subject.. Is there an
UpdateData() like in C++ or somthing I am missing?

Private Sub Application_NewMail()
Dim oApp As Outlook.Application
Dim oFoldMail As Object
Dim oItem As Outlook.MailItem
Dim oNameSp As Outlook.NameSpace
Dim strSubject As String

'Open or attach to Outlook
Set oApp = New Outlook.Application
Set oNameSp = oApp.GetNamespace("MAPI")

'Attach to the appropriate folders
Set oFoldMail = oNameSp.GetDefaultFolder(6) '6=Inbox

Set oItem = oFoldMail.Items.Item(1)
strSubject = oItem.Subject

'This message box works, it displays the subject with the time appended
MsgBox "The name returned is:" & strSubject + " ,Time: " + CStr(Now())

'However, this does not set the subject of the message?
oItem.Subject = strSubject + " ,Time: " + CStr(Date)

Set oApp = Nothing
Set oFoldMail = Nothing
Set oItem = Nothing
Set oNameSp = Nothing
End Sub

Ken Slovak - [MVP - Outlook]

unread,
Jan 7, 2003, 11:06:37 AM1/7/03
to
Have you tried using oItem.Save?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm


"MS News" <jo...@suite224.net> wrote in message
news:#dofm1ltCHA.1628@TK2MSFTNGP10...

Joel Prine

unread,
Jan 7, 2003, 11:55:51 AM1/7/03
to
IT WORKS!!! Thanks a ton!


"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:evbAzemtCHA.2600@TK2MSFTNGP11...

Joel Prine

unread,
Jan 7, 2003, 12:54:31 PM1/7/03
to
Thanks every one for getting me this far!
Here is my final code snipit for anyone with the same problem

'this subprocedure appends the current date to every subject
(must be put in ThisOutlookSession)

Private Sub Application_NewMail()
Dim oApp As Outlook.Application
Dim oFoldMail As Object
Dim oItem As Outlook.MailItem
Dim oNameSp As Outlook.NameSpace
Dim strSubject As String

Dim strSubjectLen As Integer

'Open or attach to Outlook
Set oApp = New Outlook.Application
Set oNameSp = oApp.GetNamespace("MAPI")

'Attach to the appropriate folders
Set oFoldMail = oNameSp.GetDefaultFolder(6) '6=Inbox

'Get First Mail Message
Set oItem = oFoldMail.Items.Item(1)

'Get Subject From The Message
strSubject = oItem.Subject

'This message box works, it displays the subject with the time appended

'MsgBox "The subject returned is:" & strSubject + " " +
Right(CStr(oItem.ReceivedTime), 11)
If InStr(strSubject, "(peg)") > 0 Then
'if has time already, strips it off
strSubject = Left(strSubject, (Len(strSubject) - 18))

'Sets the subject as "(subject) + (time)"
oItem.Subject = strSubject + Mid(Right(CStr(oItem.ReceivedTime),
11), 1, 2) + "_" + Mid(Right(CStr(oItem.ReceivedTime), 11), 4, 2) + "_" +
Mid(Right(CStr(oItem.ReceivedTime), 11), 7, 2) + "_" +
Right(Right(CStr(oItem.ReceivedTime), 11), 2) + "(peg)"
Else

'Sets the subject as "(subject) + (time)"
oItem.Subject = strSubject + " " +
Mid(Right(CStr(oItem.ReceivedTime), 11), 1, 2) + "_" +
Mid(Right(CStr(oItem.ReceivedTime), 11), 4, 2) + "_" +
Mid(Right(CStr(oItem.ReceivedTime), 11), 7, 2) + "_" +
Right(Right(CStr(oItem.ReceivedTime), 11), 2) + "(peg)"
End If

'Saves and updates the Message
oItem.Save

'Finalizes Everything


Set oApp = Nothing
Set oFoldMail = Nothing
Set oItem = Nothing
Set oNameSp = Nothing
End Sub

"MS News" <jo...@suite224.net> wrote in message
news:#dofm1ltCHA.1628@TK2MSFTNGP10...

0 new messages