Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    I set up an application where the user inputs information which is then merged with a word document and attached to an email. When we gave this to our users, we found that it works most of the time, except when they have Word as the editor for their messages(ToolsOptionsMail format ).

    We found an MS workaround that figures out if the "WordMail" is active or not. My problem is what to do if it is. I could display what to do in a big message box, but we think it would be better if we could use some code to unselect the box before doing the word document, then re-select the box once the email message has been sent. Is this possible? <img src=/S/help.gif border=0 alt=help width=23 height=15>
    Carpy Diem, it&#39;s .

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    Hi Peggy -

    Unfortunately, I believe you have to actually exit from Outlook and then restart it for the Word Mail option to really be turned on or off. So I don't think you can do it in the manner you are suggesting.

    On the other hand we do something fairly similar with a couple of applications where we generate email messages on the fly in Access and then give the user the option of sending it, modifying it or cancelling it altogether and haven't run into problems with Word Mail. What sort of errors are you getting? You may be able to use the Outlook object model to work around the problem, though your combination would probably be better if it were all Office2k.
    Wendell

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    I'm getting that ever-so-helpful #4605 - "The Add Method or property is not available because the current selection is not in the main document window", followed by the little window with the "0" and OK.

    What I have right now is a tacky message box but I'm trying to figure out what to do if the user doesn't unclick Outlook and clicks the OK button on my message box. I don't want to go into an infinite loop here. So when you're talking about the Outlook object model, is that something like the VBA behind Access? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

    Peggy
    Carpy Diem, it&#39;s .

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    OK - so what method are you using to initiate the email, and does it involve code? If it involves code, would you mind posting the relevant bits here so we can see how you are initiating the process.

    Unfortunately, the error handling in this situation gets really messy - the standard stuff you get is totally indecipherable.
    Wendell

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    Around here, when most people say "object model," they mean "the parts MS meant for you to be able to program directly." The Outlook object model is rather limited compared with the other applications. Access is somewhat different because it has maintained a separate macro language, so it probably has the most programming options of the three. To catch a glimpse of the object model, call up the object browser (F2) and limit the view to the objects and properties of Outlook.

  6. #6
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    Wendell, you wanted the relevant code so here goes.

    First of all, the dims:
    Option Compare Database
    Option Explicit
    .......

    Dim DBS As DATABASE
    Dim objDocs As Object
    Dim objWord As Object
    Dim Prps As Object
    Dim rst As Recordset
    Dim blnSaveNameFail As Boolean
    .........................
    everything not here is dim'd as a string, integer or date
    Private Sub Close_Click()
    Dim okcncl
    Dim nonomsg
    Dim boolWordMail As Boolean
    Dim badmsg As String
    Dim mailmsg As String
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdSaveRecord
    okcncl = msgbox("Are you sure you want to save and send this work order?", vbYesNoCancel, "Work Order")
    Select Case okcncl
    Case vbYes
    fOKToClose = True
    boolWordMail = False

    On Error Resume Next
    Set objWord = GetObject(, "Word.Application")
    If Err.number = 0 Then
    boolWordMail = isWordMail(objWord)
    Else
    'Word is not running; creating a word object
    Set objWord = CreateObject("Word.Application")
    Err.Clear
    End If
    .........................
    here's where I'm putting the message before it gets any further and errors out
    ..............................................
    If boolWordMail Then
    badmsg = "Please uncheck the 'Use Microsoft Word to edit e-mail messages' box in Outlook by going to "
    badmsg = badmsg & "Outlook and selecting Tools/Options/Mail Format before you click the OK button to continue"
    mailmsg = msgbox(badmsg, vbOKCancel + vbExclamation)
    Select Case mailmsg
    Case vbOK
    boolWordMail = True
    Set objWord = CreateObject("word.application")
    Case vbCancel
    msgbox "Please try again"
    Exit Sub
    End Select
    Else
    End If
    .................................
    here is a bunch of code that checks to make sure that there's data to send, and a template to load it to
    it then merges the data to the document
    .................................................. .....
    Now it saves the document and closed MS Word

    objWord.ActiveDocument.SaveAs strSaveNamePath
    objWord.ActiveDocument.Close
    objWord.Quit
    Set objWord = Nothing
    .................................................. ..
    now it creates a temporary document to be used as an attachment to the email
    then it makes sure that a required field is not blank, before creating the email
    .................................................

    If Me.Machine <> " " Then
    MailSubj = "New Work Order(test) - " & Me.Machine & IIf((Me.Check115 = -1), " - Safety Issue!", "")
    Mailatt = strDocsPath & strSaveName
    FileContents = "Work order is attached. Requested that work be done by " & Me.CompleteBy
    ElseIf Me.Tools <> " " Then
    MailSubj = "New Tool Room Work Order(test) - " & Me.Tools & IIf((Me.Check115 = -1), " - Safety Issue!", "")
    Mailatt = strDocsPath & strSaveName
    FileContents = "Tool Room Work order is attached. Requested that work be done by " & Me.CompleteBy
    End If
    bpurge = True 'this will prevent the message from being saved in the sent items
    ' should be set to false if copy needs to be saved
    bpreview = False ' this will send the message instead of displaying it and waiting for you to send it
    'sends out email
    Call SendMailAttach(MailSubj, FileContents, MailCC1, MailRecip, MailCC2, Mailatt, bpreview, bpurge)
    'deletes .doc file, stamps entry as being mailed, deletes data in temporary table and closes form
    Kill Mailatt
    .................................................
    now it cleans up after itself by deleting the data and closing the form
    ............................................
    The function isWordMail is as follows (courtesy Microsoft)

    Function isWordMail(oWord As Word.Application) As Boolean
    'Is focus in a Word Mail Header (To, CCC or Subject line)?
    If oWord.Application.FocusInMailHeader Then
    isWordMail = True
    Exit Function
    End If
    'if not in WordMail Header, is focus in
    'the body of a WordMail message?
    If oWord.Selection.Information(wdInWordMail) Then
    isWordMail = True
    End If
    End Function

    Does this better illuminate my situation? <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>
    Carpy Diem, it&#39;s .

  7. #7
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    Sorry for the long delay in responding - for one thing it took a bit to chew through your code, but clients got demanding too.

    Anyhow, the SendMail command is fairly limited in what you can do with it, while Outlook OLE Automation is a fair bit more robust, and is typically the route we use, as it lets you set each of the various email properties. It also doesn't seem to care whether you are using WordMail or not. You might take a look at MS knowledge base article Q153311 to see some sample code for creating an email. There are a number of other articles on automation as well.

    A couple of questions - why are you attaching the Word document instead of putting the information in the email? (I can think of a couple of good reason, but curious what drove you down that path.) Also, where in the code are you getting the error message?
    Wendell

  8. #8
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access/Word/Outlook Mess (Access 97, Word 97, Outlook 2K)

    Thanks, Wendell, for getting back to me. My message appears to be working - people don't seem to mind unclicking the Use Word as Editor box because, so far, noone recalls setting their email up this way to begin with, and they don't see a difference when it's gone. I'll look at the MS article to see if I can streamline the process at all.

    In answer to your questions:

    1. we're using a Word document because the users need a form that they can take to the repair area and they feel more comfortable with a piece of paper than anything else. Since they want a form, loading the data into the email would be too big of a change. Besides, if they get a piece of paper dirty from the machine they're repairing, they can reprint the form - it's a bit harder to quickly replace anything else.

    2. It's difficult for me to ascertain exactly where the process was erroring out if WordMail was active. I put in the error message at the approximate point, and it seems to work.

    Now all I have to do is get the repair guys to update the data on the system, so the requestors can see what's going on, everyone will be happy. <img src=/S/groovin.gif border=0 alt=groovin width=21 height=21>
    Carpy Diem, it&#39;s .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •