Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automaton error with Word (Access 2k Word 2k Win 2k)

    Hello All

    I'm having some real difficulties sorting out some automation code. I have a Word template with all the relevant bokkmarks, some code tht fills the book marks, asks the user for a file name and saves the file. The code then either emails the file as an attachment using Outlook automation, or prints the file off to provide a hard copy.

    My problem is with the exit handler, it just can not clean up the instances of Word I've created, run time error 462 is what it says. Now I've been to the MSKB for a solution, I've read Wendell's rather good tips on Automation, I've tried everything I understand from these and frankly I'm in over my head.

    If necessary I'll post the code, but it's long as the whoe thing runs from one button and uses input forms and message boxes to select the next activity.

    Assuming I've not got any .Active.Document type entries (the cause of error 462as far as I can understand it) what else do I need to ensure is covered by the objWord instance I use to create a word application? I've tried using the New Word.Application and the CreateObject("Word.Application") alternative to it (although I don't see the difference, all I get is it's a 'binding' issue).

    Apologies for the length of this post, but I'm trying to explain it without having anyone read through many many lines of code.

    Thanks

    Ian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    I would check and check again that you don't have code that implicitly refers to Word instead of explicitly through the objWord object, it is all too easy to miss the culprit. If you are absolutely sure, there is not much we can say without seeing the code.

  3. #3
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    Hans

    I've been going over this for a while now and the only lines I see that concern me are the ones where I'm filling the bookmarks. Heres a short sample: -

    With objWord.ActiveDocument.Bookmarks
    .Item("DateRejected").Range.Text = Me.DateReceived
    End With

    I've since seen examples with this coded differrently, for example: -
    WordDoc.BookMarks("DataReference").Select
    objWord.Selection.TypeText DataSource.Fields("DataFieldName").

    So, should I be using the objWord variable before the .Item line??

    If this isn't the problem I'll put the code up with any lines that carry out identical instructions removed.

    Thanks

    Ian

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    No, the With statement specifies that .Item belongs to the objWord.ActiveDocument.Bookmarks object, so it is already dependent on objWord. In fact, objWord.Item would cause an error.

  5. #5
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    OK, I've been doing some more work on this and I've noticed the problem is only happening when the user takes the print option. I should have noticed this last night, but it was the end of a long day......

    So, as the exit handler works for two out of three scenarios I'm guessing it's the print code that's wrong....... Should I be saying anything more specific in there? I'm printing to a network printer, as will all users, so there is some time where the thing is spooling in the print manager, but the form is available to use.

    Ian

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    Try replacing objWord.ActiveDocument.PrintOut by objWord.ActiveDocument.PrintOut Background:=False (or WordDoc.PrintOut Background:=False.) This should make the macro wait until the printing has been done.

    By the way, here are some comments on your code:
    <UL><LI>I would first ask the user if he/she wants to mail or print the document. In the latter case, there is no need to save the document, and to start Outlook etc. Starting Outlook causes a lot of overhead, you should avoid it if you're not going to use it.
    <LI>You declare and assign variables strRecipientFax ans strRecipientName but never use them.
    <LI>I don't understand the way you set the e-mail recipients. You seem to have two identical recordsets, then you loop through one of them first to concatenate names into strRecipient, then loop through the other one and repeatedly add the same strRecipient to the recipients of the e-mail. The second loop does not refer to any field of the recordset. I fail to see the purpose of that.
    <LI>You don't close the recordsets, and set only one of them to Nothing at the end.
    <LI>To be on the safe side, I would close the Word doc without saving it - if printing has updated fields, Word would prompt the user to save changes.

    Worddoc.Close SaveChanges:=wdDoNotSaveChanges
    <LI>The code contains what might be your real e-mail address.[/list]

  7. #7
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    Edited by HansV to move very long code fragment to text attachment (with the added advantage of preserving indentation)

    Drat, I was hoping I'd worked it out on my own.... Ah well.

    The code is inserted below, with a few lines taken out. The error handler and exit handlers are a mess as I've been trying all sorts of options, but don't delete the previous untill I know it's no good.

    Some variables are rem'd out due to other things I've got to add to this once the code works. I'm looking into writing separate modules, but the code wouldn't be used anywhere else, so other than reducing the number of lines behind my form I don't see an advantage.

    I'm actually quite impressed with this as it's my first ever attempt at using Automation and the Outlook bit works........ But the Word automation has got me by the wotsits....

    Thanks, and apologies for using you as a 'syntax' checker.....

    Ian
    Attached Files Attached Files

  8. #8
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automaton error with Word (Access 2k Word 2k Win 2k)

    Hans

    Thanks for the help.

    The two variabbles I've declared, strRecipientFAX and strRecipientNames are to be used by the code. The names on is goin into the body text marked For the Attention Of strRecipientNames. The FAX one will be offerred to the user if the email string is empty when tested. This is not written that yet as I've been hung up on sorting out the errant Word sessions.

    Thanks for pointing out I'd missed those recordsets, they had been overlooked.

    I have to offer them the opttion of saving, the usrs want to have the file, I've expalined about databases but due to things like local custom, traceability and habit they insist they want to save the file and fill up a bit more disk space.....

    Thanks for the help.

    email addy changed, I'd overlooked that as well.

    Ian

Posting Permissions

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