troubleshooting Question

Testing for lock status of an Outlook MSG file

Avatar of pauldonson
pauldonson asked on
Microsoft Access
4 Comments1 Solution707 ViewsLast Modified:
I have the attached code which creates an email (using Redemption) then prompts the user to make changes to it so that my application can save it into the database.

I normally use the function FileLocked (see below for definition) but for some reason it doesn't acknowledge that the MSG file is open. Can anyone suggest a way of completing the test correctly or another way of creating an email, allowing the user to edit and send it using Outlook and then for the database to save the message that was sent.

Thanks.

(FileLocked:)
Function FileLocked(strFilename As String) As Boolean
   On Error Resume Next
   Open strFilename For Binary Access Read Write Lock Read Write As #1
   Close #1

   If Err.Number <> 0 Then
      FileLocked = True
      Err.Clear
   End If
End Function
Dim objOutlook As Object
Dim objMessage As Object
Dim oItem
Dim strFilename As String
 
Set objOutlook = CreateObject("Outlook.Application")
Set objMessage = CreateObject("Redemption.SafeMailItem")
Set oItem = objOutlook.createitem(0)
 
With objMessage
    .Item = oItem
    .Recipients.Add "pdonson@prospecit.co.uk"
    .Subject = "Test email"
    .HTMLBody = "HTML Body - what does it look like"
End With
 
strFilename = "C:\Testmessage.msg"
objMessage.SaveAs strFilename
 
objMessage.display
 
Do
    MsgBox "Please make any changes to the email, close it (saving changes) then click OK."
Loop Until FileLocked(strFilename) = False
 
objMessage.send
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros