Solved

500 points awaits you...

Posted on 2004-04-23
26
551 Views
Last Modified: 2007-12-19
Still looking for help here...http:Q_20960384.html
If you have any recommendations, please post them.  
Thanx!
0
Comment
Question by:sirbounty
  • 15
  • 11
26 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
sirbounty,

I believe I can do this in pure VB, but I'm not comfortable enough working inside Outlook to pull it off.  If you're interested in this kind of appraoch, then let me know and I'll post some code.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Rock on! - if you can do it in VB all the better.  I haven't loaded .NET yet though (just sitting there making faces at me) - so VB6 would be preferred...
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
That's good because I'm not using .Net yet myself so VB6 is all I have to work with.

What is the format of the information inside the log files?  I need to know so I can parse the various pieces of informatio intot he proper places in the message.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
I'm not at work right now, so I'm going from memory...

The logs are in the format of employeeID.log (this is related to my other question).
I've got VB code that creates these logs based upon filenames found in this employees profile.
So the log would contain something similar to:

\\server\share\users\empID\file1
\\server\share\users\empID\file2
\\server\share\users\empID\file3

Obviously, there will be LFNs there, but if we could just pull all info from the log, that should do it.

Basically, the form note that I have, has basically the same 'header' text for each note...
Something like:

"We've discovered you're housing these files on your share. They should be deleted.
See the list below for details:"

More to it than that, but the end results should be, the header info, and the list of files beneath (which would all come from the log).  I'd also prefer that the From field be filled with a group mailbox, than my own (do-able?), as well as have another group on CC.  Subject is generally the same, but I think that's best left to being manual, since when I key in their name, if OL 'recognizes' the name and resolves it, I know they've been on the report in the past and I would need to adjust the subject line accordingly.

Thanx for your help on this!

Any other questions, let me know.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
sirbounty,

Here's one solution to the issue.  Below you'll find the contents of both the .frm and .vbp files.  Sending both of these to you rather than just the code saves the time of having to explain which references and controls are used in the project.  You should be able to cut and paste the contents of both files and recreate them at your end.

I dobut that you need it but I commented the code heavily to make it, hopefully, very easy to understand what I'm doing.  I used the Outlook Object Library to send the messages.  Of course that means when the messages are sent Outlook security steps in and does it's thing.  You can get around that by using the Redemption library which uses Enahanced MAPI and isn't subject to Outlook security.  I didn't use it here because I don't know how you feel about that.  If you want to use it, then it should be simple enough to substitute the necessary code.  The other pitfall of using Outllok is that the messages will be sent in your name, not the name of a group mailbox.  In your explanation of what you wanted you indicated that you don't want the messages sent in your name.  Sorry, but I'm not aware of any way around that when using Outlook.  

Briefly, here's how the program works.

1.  Opens the folder containing the log files.  Be sure and fix the path to the one you will be using.
2.  Loop through all the files in the folder.  I made the assumption that the folder will not contain anything except the log files we want to process.  If that's wrong, then the program will need more code to skip over the non log files.
3.  For each log file build an email message and store it in an array.
4.  Once all the log files have been processed, enable a command button to review the messages.
5.  Present a list of the constructed messages.
6.  When the user clicks on a message in the list display it onscreen and enable a button that'll allow the user to send the message.  The message contents are displayed in text boxes and a rich text box.  The user can make changes to the contents of any field before releasing the message.
7.  On clicking the Release Message button the message is sent via Outlook.

That's pretty much it.

I wrote a program somewhat similar to this a couple of years ago.  In my program I used a preformatted  HTML file as the basis for the message body.  It contained replaceable strings (e.g. [*User Name*]) that I used to insert data into the message body at runtime.  That allowed me to use fonts, font attributes, colors, and graphics to draw attention to certain things in the message body.

Let's talk about email again for a minute.  As I noted above I used Outlook in this code.  However, I'd recommend using SMTP instead.  I didn't use SMTP because I don't know if that's a viable option for you.  If it is, then switching to it will solve the two main problems associated with using Outlook.  With SMTP the messages can be addressed to come from any address and there'll also be no Outlook security issues.  That's the main reason I use it in any of my mail enabled programs.  Like switching to Redemption a switch to using SMTP would be fairly simple and straightforward.  

I hope this helps.  Let me know if there's anything else I can do.

--- Begin Frm File Contents

VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   5700
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   10260
   LinkTopic       =   "Form1"
   ScaleHeight     =   5700
   ScaleWidth      =   10260
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame2
      Caption         =   "Messages"
      Height          =   4815
      Left            =   0
      TabIndex        =   12
      Top             =   120
      Visible         =   0   'False
      Width           =   1815
      Begin VB.ListBox lstMessages
         Height          =   4350
         ItemData        =   "Form1.frx":0000
         Left            =   120
         List            =   "Form1.frx":0002
         TabIndex        =   13
         Top             =   240
         Width           =   1575
      End
   End
   Begin VB.Frame Frame1
      Caption         =   "Message [0000]"
      Height          =   4815
      Left            =   1920
      TabIndex        =   2
      Top             =   120
      Visible         =   0   'False
      Width           =   8175
      Begin VB.CommandButton cmdReleaseMessage
         Caption         =   "Release Message"
         Height          =   375
         Left            =   3600
         TabIndex        =   11
         Top             =   4320
         Width           =   1575
      End
      Begin VB.TextBox txtSubject
         Height          =   285
         Left            =   1080
         TabIndex        =   9
         Top             =   1320
         Width           =   6735
      End
      Begin VB.TextBox txtCC
         Height          =   285
         Left            =   1080
         TabIndex        =   8
         Top             =   840
         Width           =   6735
      End
      Begin VB.TextBox txtTo
         Height          =   285
         Left            =   1080
         TabIndex        =   7
         Top             =   360
         Width           =   6735
      End
      Begin RichTextLib.RichTextBox rtbMessage
         Height          =   2415
         Left            =   1080
         TabIndex        =   10
         Top             =   1800
         Width           =   6735
         _ExtentX        =   11880
         _ExtentY        =   4260
         _Version        =   393217
         Enabled         =   -1  'True
         TextRTF         =   $"Form1.frx":0004
      End
      Begin VB.Label Label4
         Alignment       =   1  'Right Justify
         Caption         =   "Message"
         Height          =   375
         Left            =   120
         TabIndex        =   6
         Top             =   1800
         Width           =   855
      End
      Begin VB.Label Label3
         Alignment       =   1  'Right Justify
         Caption         =   "Subject"
         Height          =   375
         Left            =   120
         TabIndex        =   5
         Top             =   1320
         Width           =   855
      End
      Begin VB.Label Label2
         Alignment       =   1  'Right Justify
         Caption         =   "CC"
         Height          =   375
         Left            =   120
         TabIndex        =   4
         Top             =   840
         Width           =   855
      End
      Begin VB.Label Label1
         Alignment       =   1  'Right Justify
         Caption         =   "To"
         Height          =   375
         Left            =   120
         TabIndex        =   3
         Top             =   360
         Width           =   855
      End
   End
   Begin VB.CommandButton cmdSendMessages
      Caption         =   "Send Messages"
      Height          =   495
      Left            =   1560
      TabIndex        =   1
      Top             =   5160
      Width           =   1335
   End
   Begin VB.CommandButton cmdProcessFiles
      Caption         =   "Process Files"
      Height          =   495
      Left            =   120
      TabIndex        =   0
      Top             =   5160
      Width           =   1335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1

Private Type MailMessage
    strTo As Variant
    strCC As Variant
    strSubject As Variant
    strBody As Variant
End Type

Dim arrMessages() As MailMessage
Dim intMessageCount
Dim olApp As New Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olMessage As Outlook.MailItem

Private Sub ProcessFiles(strPath As String)
    Dim objFSO As New FileSystemObject
    Dim objFolder As Folder
    Dim objTS As TextStream
    Dim strBuffer As String
    Dim File As File
   
    'Set the message count to 1
    intMessageCount = 1
    'Redim the array to a single element to make sure we start off with it empty
    ReDim arrMessages(intMessageCount)
    'Get the folder containing the log files
    Set objFolder = objFSO.GetFolder(strPath)
    'Loop through the files in the folder
    For Each File In objFolder.Files
        'Resize the array to hold another element
        ReDim Preserve arrMessages(intMessageCount)
        'Open the log file
        Set objTS = objFSO.OpenTextFile(File.Path, ForReading)
        With arrMessages(intMessageCount)
            'Start the message body off with our static text
            .strBody = "We've discovered you're housing these files on your share. They should be deleted.  " & _
                       "See the list below for details:" & vbCrLf & vbCrLf
            'Loop through the log file
            Do While Not objTS.AtEndOfStream
                'Read in a line from the log file
                strBuffer = objTS.ReadLine
                'Add it to the message body
                .strBody = .strBody & strBuffer & vbCrLf
            Loop
            'Parse the EmployeeID from the file name and set the To address
            .strTo = Left(File.Name, Len(File.Name) - 4)
            'Stick the addressee's name in the listbox too
            lstMessages.AddItem .strTo
            'Set the CC field
            .strCC = "someone@somewhere.com"
            'Set the message subject
            .strSubject = "SirBounty's Email Program"
        End With
        'Close the log file
        objTS.Close
        'Up the message count by 1
        intMessageCount = intMessageCount + 1
    Next
    Set objTS = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
End Sub

Private Sub cmdProcessFiles_Click()
    'Run the process that reads the log files and builds the messages
    ProcessFiles "C:\LogFiles"
    'Enable the Send Messages button
    cmdSendMessages.Enabled = True
    'Disable the Process Files button
    cmdProcessFiles.Enabled = False
End Sub

Private Sub cmdReleaseMessage_Click()
    'Create a new message
    Set olMessage = olApp.CreateItem(olMailItem)
    'Set the To address
    olMessage.To = txtTo.Text
    'Set the CC address
    olMessage.CC = txtCC.Text
    'Set the subject
    olMessage.Subject = txtSubject.Text
    'Set the message body
    olMessage.Body = rtbMessage.Text
    'Send the message
    olMessage.Send
    Set olMessage = Nothing
    MsgBox "Message away!", vbOKOnly, "Information"
    'Remove the message we just sent from the listbox
    lstMessages.RemoveItem lstMessages.ListIndex
    'If this was the last message in the lsit
    If lstMessages.ListCount = 0 Then
        'Make the two frames invisible
        Frame2.Visible = False
        Frame1.Visible = False
        'Disable the Release Message button
        cmdReleaseMessage.Enabled = False
        'Enable the Process Files button
        cmdProcessFiles.Enabled = True
    End If
    If lstMessages.ListIndex = -1 Then
        cmdReleaseMessage.Enabled = False
    End If
End Sub

Private Sub cmdSendMessages_Click()
    'Disable the Send Messages button
    cmdSendMessages.Enabled = False
    'Make the two frames visible
    Frame2.Visible = True
    Frame1.Visible = True
    DoEvents
End Sub

Private Sub Form_Load()
    'Create an Outlook session and login to it
    Set olNS = olApp.GetNamespace("MAPI")
    olNS.Logon "Outlook"        'Replace "Outlook" with the name of your profile
    'Make sure the Send Messages button is disabled
    cmdSendMessages.Enabled = False
    'Make sure the Release Message button is disabled
    cmdReleaseMessage.Enabled = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'Logoff from Outlook and clean it up
    olNS.Logoff
    Set olNS = Nothing
    Set olApp = Nothing
End Sub

Private Sub lstMessages_Click()
    'Change the frame's caption to show the message we're working on
    Frame1.Caption = "Message [" & lstMessages.ListIndex + 1 & "]"
    'Load the data from the array into the form fields
    With arrMessages(lstMessages.ListIndex + 1)
        txtTo.Text = .strTo
        txtCC.Text = .strCC
        txtSubject.Text = .strSubject
        rtbMessage.Text = .strBody
    End With
    'Make sure the Release Message button is active
    cmdReleaseMessage.Enabled = True
End Sub

--- End Frm File Contents

--- Begin Vbp File Contents

Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\System32\stdole2.tlb#OLE Automation
Reference=*\G{420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#..\..\..\..\WINDOWS\system32\scrrun.dll#Microsoft Scripting Runtime
Reference=*\G{00062FFF-0000-0000-C000-000000000046}#9.2#0#..\..\..\..\Program Files\Microsoft Office\OFFICE11\msoutl.olb#Microsoft Outlook 11.0 Object Library
Object={3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0; RICHTX32.OCX
Form=Form1.frm
Startup="Form1"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="BlueDevilFan"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1

---End Vbp File Contents
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
>>The other pitfall of using Outllok is that the messages will be sent in your name, not the name of a group mailbox.  In your explanation of what you wanted you indicated that you don't want the messages sent in your name.  Sorry, but I'm not aware of any way around that when using Outlook.  <<
All I do is display the From field and enter the group name there.
But in the form I developed, I had it auto-populated...
If I can't this working, I can always create a seperate profile just for this purpose - not a big deal.

>>2.  Loop through all the files in the folder.  I made the assumption that the folder will not contain anything except the log files we want to process.  If that's wrong, then the program will need more code to skip over the non log files.<<

Not a problem - I think they're all contained within this one folder and that's all that's there...

Nice job here.  I hope you don't mind, but I won't be able to implement it until earliest Thursday  - latest would be the following Monday...
I'm doing a lot of remote server upgrades and will be working from home most of the week.

Thanx very much for this.  I really do appreciate your time and effort! :D
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Thanks.  Thursday, next Monday, whenever.  It's not a problem for me.  The goal is to answer the question or at least to give ideas that'll be useful.  I just hope it's helpful.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Very helpful indeed.
I just didn't want you to think I left you hanging on this one... :)  Thanx again.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Hmm - how do I get this into my project? :$
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Block and copy the first section of code, that of the FRM file.  Use Notepad and create a file called Something.Frm, replacing Something with whatever name you want to use.  Now, paste the code you copied into the file.  Save it.  Come back to EE and block and copy the second section of code, that of the VBP file.  Again using Notepad, create another file.  Call this one Something.Vbp, substituting the name you gave the first file in place of Something.  The names of the two files have to be the same.  Now you should be able to open the Vbp file in VB6.  This'll give you my project and form file.  That'll allow you to test the concept.  If you need to ingerate the code I wrote with your own pre-existing code, then it'll be necessary to cut and paste code between projects.  If you do that, then don't forget to include the necessary references.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Finally got a chance to look at this (sasser has been causing havoc at my office :(

I get the following when I run this:
Line 23: Property ItemData in lstMessages had an invalid file reference.
Line 25: Property List in lstMessages had an invalid file reference.
Line 78: Property TextRTF in rtbMessage had an invalid value.

I'll see if I can find the cause though...
Thanx for all your help on this!
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Missing the reference - aha!
Don't stray too far though - I may need some follow up help later. :D
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Just posting my orignial question here, since I'm going to have the other one removed...
================================
I have a list of log files created in the format of
username.log

This log contains a listing of data I need to send to this user.  It might contain only one line, it might contain 15.

All of my log files are stored in one folder (although I have a few that are groupname.log instead - which I will have to handle manually).

I've designed a form to send an email to this username's email account.
In my form, I have a specific text header/paragraph.
I also have a group mailbox in the From field, and another group mailbox in the CC field.

I'd like to run a script/vba/macro - that would
(1) open the form
(2) populate the To field with the username from the filename (username.log)
(3) pull everything out of username.log and append it to the bottom of my message
(4) NOT automatically send though.  I'd like to review and click send manually
===========================
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 67

Author Comment

by:sirbounty
Comment Utility
BDF - it bombs here when I 'release' the message:
    Set olMessage = olApp.CreateItem(olMailItem)
Did I miss a ref somewhere?
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
That's a bit perplexing.  Let's see if we can figure out what's going on here.  First, a couple of questions.  

1.  What OS are you running this on?
2.  What version of Outlook is on the system you're testing this on?
3.  Check the references.  Is there a reference to the Microsoft Outlook Object Library?  If so, what version?

Debugging.  Please set a breakpoint on the line it's bombing on.  Add a watch on olApp.  Before stepping over the instruction causing the problem check olApp and see if it's instantiated.  Also, what error do you get when it bombs?
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Bdv - no need, I'll open a new question on it and just link back to this one - keep an eye out though, alright?
Thanx...

Btw, to answer the above:
1) XP Pro
2) XP (2002)
3) MS OL 10.0 object library

I'll complete the debugging steps in the new post.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Alright.  I don't mind working through it though.  I feel like it's only half a solution since it doesn't work on your setup.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Okay, FINALLY getting to trying this in a real-life situation...
I haven't audited since April, so I'm trying to send out June's reports...
The program works, but there are a couple of items that I'd like to 'fix'...

The first one, most importantly is that when the first note is sent (and this works fine) - it removes that first item from the list, but doesn't seem to clear the txtTo.txt (not a problem, I just set it to ""), and am able to process the next item in the list, however:

a) the .strbody doesn't get reset...  It's still showing the strbody from the first user and while most of this is just my formatted warning message, I don't want Jim to think he's being audited for Paul's game files...  How do I either clear out strbody altogether and recreate it with Jim's logged files, or at least clear out the last lines of strbody, which will all be preceeded with either \\ or "\\

b) You said above: "I wrote a program somewhat similar to this a couple of years ago.  In my program I used a preformatted  HTML file as the basis for the message body.  It contained replaceable strings (e.g. [*User Name*]) that I used to insert data into the message body at runtime.  That allowed me to use fonts, font attributes, colors, and graphics to draw attention to certain things in the message body."  
This is exactly what I'd like...I want the first 3 lines (which read basically "Warning - do not delete this - must read!" and the last lines (the logged files) to be in red.  Not too concerned about fonts, but that would certainly be a bonus.

I have a new question on this and will post it here shortly - the points are yours if you can solve this (and I'll certainly bump it to 500, it's 300 now).  I wish I could give you 2000 points for this, it's really saving me a LOT of time...

I'm curious what your program was for - something similiar in your environment?  

I've actually migrated a portion of my code over from DOS batch files to VB - but back then the batch files only did about 20% of my work - now I have a lot of VB code that automates about 60% of it - and for picture viewing, I have a control array that displays about 300 thumbnails at a time, where different events trigger if the picture is to be ignored or audited...it's really pretty sweet. :D

Thanx again sir!
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Here's the new question on it - although, it's explained better in my post above...

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21074679.html
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Glad I was able to help out.  I posted my response to part (b) of your question above in the new question.  As to the problem you described in part(a) of your post, I see the problem and know the cause.  What I'm not sure about is how best to fix it.  The problem is with the array.  After sending a message I dispose of the corresponding listbox item but don't have a way of loosing the matching array.  I hadn't noticed this until you pointed it out.  I guess when I was testing this code before I posted it I always ran through the names in reverse order, that is from the bottom of the list up instead of top down.  If you click on the values in reverse order you don't run into a problem.  It's only when you go top down.  Since VB doesn't allow for deleting an array element except for the one at the end of the array, there's no simple way to dispose of the the element at the top of the list.  Let me look into switching to a collection in place of the array and see if I can fix it that way.  I'm pretty sure I can.  I'll post an update as soon quick as I can.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Don't waste your time then - if it's as simple as going bottom - up, I don't have any problems with that...
I sincerely appreciate your providing me the code in the first place...Wish I could return the favor!
Thanx - I'll check it out tomorrow afternoon. :)
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
You shouldn't have to go in one specific direction and I should have caught that problem when before I posted the code.  I've figured out a way to do it with a collection instead.  I'll make the changes, test it out, and post it tomorrow sometime.  No problem.  I've read your profile and seen how many certifications you have and the areas you have them in.  Very impressive!  Sooner or later I'll have a question that you'll probably answer.  Besides which I enjoy solving problems.  Keeps the mind agile.

Cheers.
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
Haha -no kidding....my wife is finally understanding why I enjoy this site so much - my real job has gotten a bit to predictable and I like to keep my mind sharp as well - not to mention I really enjoy helping out... : )
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Good morning.  Here's the revised program that'll allow you to select the items in the list in any order.  To accomplish that I replaced the array I used in the original code with a collection.  That allows me to delete the collection item that corresponds to the list item that was clicked.  I made a couple of other changes but they're all cosmetic.  You can copy the code below and paste it over the previous code.  This time I tested more thoroughly, going top to bottom, bottom to top, and from the middle out.  It worked for me no matter what direction I went.

Option Base 1   'Because I hate Base 0 arrays
Dim colMessages As New Collection, _
    olApp As New Outlook.Application, _
    olNS As Outlook.NameSpace, _
    olMessage As Outlook.MailItem

Private Sub ProcessFiles(strPath As String)
    Dim objFSO As New FileSystemObject, _
        objFolder As Folder, _
        objTS As TextStream, _
        strBuffer As String, _
        File As File, _
        arrItemData(4) As Variant
   
    'Get the folder containing the log files
    Set objFolder = objFSO.GetFolder(strPath)
    'Loop through the files in the folder
    For Each File In objFolder.Files
        'Open the log file
        Set objTS = objFSO.OpenTextFile(File.Path, ForReading)
        'Start the message body off with our static text
        arrItemData(4) = "We've discovered you're housing these files on your share. They should be deleted.  " & _
                         "See the list below for details:" & vbCrLf & vbCrLf
        'Loop through the log file
        Do While Not objTS.AtEndOfStream
            'Read in a line from the log file
            strBuffer = objTS.ReadLine
            'Add it to the message body
            arrItemData(4) = arrItemData(4) & strBuffer & vbCrLf
        Loop
        'Parse the EmployeeID from the file name and set the To address
        arrItemData(1) = Left(File.Name, Len(File.Name) - 4)
        'Stick the addressee's name in the listbox too
        lstMessages.AddItem arrItemData(1)
        'Set the CC field
        arrItemData(2) = "someone@somewhere.com"
        'Set the message subject
        arrItemData(3) = "SirBounty's Email Program"
        'Close the log file
        objTS.Close
        'Add the current item to the collection
        colMessages.Add arrItemData
    Next
    'Clean up the objects used in this procedure
    Set objTS = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
End Sub

Private Sub cmdProcessFiles_Click()
    'Run the process that reads the log files and builds the messages
    ProcessFiles "C:\LogFiles"
    'Enable the Send Messages button
    cmdSendMessages.Enabled = True
    'Disable the Process Files button
    cmdProcessFiles.Enabled = False
End Sub

Private Sub cmdReleaseMessage_Click()
    Dim intPointer As Integer
    intPointer = lstMessages.ListIndex + 1
    'Create a new message
    Set olMessage = olApp.CreateItem(olMailItem)
    'Set the To address
    olMessage.To = txtTo.Text
    'Set the CC address
    olMessage.CC = txtCC.Text
    'Set the subject
    olMessage.Subject = txtSubject.Text
    'Set the message body
    olMessage.Body = rtbMessage.Text
    'Send the message
    olMessage.Send
    Set olMessage = Nothing
    MsgBox "Message away!", vbOKOnly, "Information"
    'Remove the message we just sent from the collection and the listbox
    colMessages.Remove intPointer
    lstMessages.RemoveItem intPointer - 1
    'If this was the last message in the lsit
    If lstMessages.ListCount = 0 Then
        'Make the two frames invisible
        Frame2.Visible = False
        Frame1.Visible = False
        'Disable the Release Message button
        cmdReleaseMessage.Enabled = False
        'Enable the Process Files button
        cmdProcessFiles.Enabled = True
    End If
    'If there is no item selected in the listbox
    If lstMessages.ListIndex = -1 Then
        'Disable the message release button
        cmdReleaseMessage.Enabled = False
    End If
End Sub

Private Sub cmdSendMessages_Click()
    'Disable the Send Messages button
    cmdSendMessages.Enabled = False
    'Make the two frames visible
    Frame2.Visible = True
    Frame1.Visible = True
    'Give the OS a chance to do something
    DoEvents
End Sub

Private Sub Form_Load()
    'Create an Outlook session and login to it
    Set olNS = olApp.GetNamespace("MAPI")
    olNS.Logon "Outlook"        'Replace "Outlook" with the name of your profile
    'Make sure the Send Messages button is disabled
    cmdSendMessages.Enabled = False
    'Make sure the Release Message button is disabled
    cmdReleaseMessage.Enabled = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'Logoff from Outlook and clean it up
    olNS.Logoff
    Set olNS = Nothing
    Set olApp = Nothing
End Sub

Private Sub lstMessages_Click()
    Dim intPointer As Integer
    'Get a pointer to the clicked on item
    intPointer = lstMessages.ListIndex + 1
    'Change the frame's caption to show the message we're working on
    Frame1.Caption = "Message [" & intPointer & "]"
    'Load the data from the corresponding collection item into the form fields
    txtTo.Text = colMessages(intPointer)(1)
    txtCC.Text = colMessages(intPointer)(2)
    txtSubject.Text = colMessages(intPointer)(3)
    rtbMessage.Text = colMessages(intPointer)(4)
    'Make sure the Release Message button is active
    cmdReleaseMessage.Enabled = True
End Sub
0
 
LVL 67

Author Comment

by:sirbounty
Comment Utility
BlueDevilFan - I've strayed away from this older code in trying to streamline several aspects of the process.
I've opened a new question (http:Q_21529162.html) in an effort to reuse the process here of generating an html message (using cdo)...is it possible?  Would you mind assisting 'again'? :^ )

Thanx!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Hi, sirbounty.  

I'll be glad to.  Having a look now.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now