Well I couldn't do any more testing from home, as the app is in Access 2010 format and I only have Access 2007 at home! ( I used a special Access 2010 only Nav Control )
However I have decided that I didn't want to go down the bound route anyway. I spent a lot of time a few years back refactoring all the apps to run via late bindings due to the mixed MS Office environment and so using bound objects isn't a feasible option. Though I have made progress coming at it from a different angle!
I have some test code I've been playing with and I now have the email sent , then retrieve it from the sentitems collection, then save it. It corectly saves as .msg and can be opened again in Outlook from the hard drive, including all attachments.
Now I know before you pick holes in the following code, it's rough and I need to tidy it up, I also need to work out the best way to check not just the drafts folder in case they didn't click send (which it does already), but also monitor the outbox (for emails that may take a while to actually send) without ending in an infinate loop while also not having to pause the app too often.
I am going to refactor it into the EmailWrapper class as it's currently just a button click event and will probably add a 'Save' method to the EmailWrapper passing in the file name and path (and include a delete method). I also want to add a progress indicator so the user can see what's going on!
Here's what I currently have
Code:
Private Sub Command0_Click()
On Error Resume Next
Dim oEmail As New EmailWrapper
Dim oApp As Object
Dim oItem As Object
oEmail.Subject = "test email - Ref(12345)"
oEmail.addRecip ("me@mydomain.com")
oEmail.Body = "this is an email body"
oEmail.DispEmail = True
oEmail.Send
' don't forget to implement progress window and add progress information
If vbYes = MsgBox("Are you happy?", vbYesNo) Then
Set oApp = CreateObject("Outlook.Application")
Sleep 3000
Set oItem = oApp.GetNamespace("MAPI").GetItemFromID(oEmail.EntryID)
If Not oItem Is Nothing Then
If vbYes = MsgBox("You haven't sent the email, do you wish to send the email?", vbYesNo) Then
oItem.Send
Sleep 3000
Else
oItem.Delete
MsgBox "Email has been deleted"
End If
Else
Do While oItem.Subject <> oEmail.Subject
Sleep 3000
Set oItem = oApp.GetNamespace("MAPI").GetDefaultFolder(5).Items.GetLast
Loop
oItem.SaveAs "h:\Test.msg", 3
MsgBox "Email Saved"
End If
End If
Set oEmail = Nothing
Set oApp = Nothing
Set oItem = Nothing
End Sub
So far it seems to work and does what I need, and at least it isn't a 'bound to Outlook version xxxx' solution!
If you have any pointers or suggestions they would be appreciated.
Regards,
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Dance Music Downloads