Results 1 to 13 of 13
  1. #1
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Word Automation (Access 97)

    I'm using WordAutomation to print form letters. The basic program logic is as follows:
    <pre>Create Word object, opening minimized and visible
    Read each record from recordset, and do following:
    Create new letter from template.
    Resolve boomarks.
    Print letter.
    Close letter without saving.
    When finished with all letters, close Word Object.</pre>


    This works fine. However, I also have an Preview alternative in which the user can review/change each letter prior to printing. The Word object is not minimized, and I have a msgbox insert prior to the Print command.

    This works also, but requires 1 cosmetic change. When the Word object is opened, it becomes the current window object. So the first letter displays on the screen, and the Access message box displays on top of that, which I like. However, as soon as I make a selection from the msgbox, Access becomes the current application again, and the next letter doesn't actually show on the screen because it is behind Access. How do I make the Word Object move back on top when the next letter opens? I suppose I could keep closing/opening word object itself, but that would slow-down processing too much.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Word Automation (Access 97)

    Hi Mark,
    Have you tried something like
    appWord.Activate?
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Word Automation (Access 97)

    The .Activate definitely moves Word to the top, but the Access message box no longer displays on top of the document. The Access button on the taskbar does blink; which I guess indicates that it is waiting for a response in its message box. Having the Access message box on top of the Word document is a nice effect, and I'd like to be able to keep doing it after the first one.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    Star Lounger
    Join Date
    Aug 2001
    Location
    Seattle, Washington, USA
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Automation (Access 97)

    Mark,

    Could you open the Message Box using acDialog? That might cause the code to wait for a response from the user. Then, continuing with .Activate so Word comes up...

    Tom

  5. #5
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Word Automation (Access 97)

    I'm beginning to think it is a fluke that the message box appears over the letter the first time through, since it doesn't seem to always do it! It may be some sort of timing issue. I'm thinking I may just keep Word minimized, and let Users bring it to front if they want.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Word Automation (Access 97)

    Hi Mark,
    How does your code handle the changes being made to the created document - e.g. what happens if the user changes it, prints it and closes the app rather than just the document?
    Ignoring that, I guess it shoud be possible to reactivate your access window, minimized if necessary, to display the message box once again, then reactivate Word and so on. Otherwise, I guess you could simply create each word document with your code and leave them open for revision afterwards without printing any of them automatically.
    Does that help?
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Word Automation (Access 97)

    >>How does your code handle the changes being made to the created document - e.g. what happens if the user changes it, prints it and closes the app rather than just the document?<<

    I just put a "On Error Resume Next" to handle my trying to close a document that has already been closed. But you do raise a good point as to what to do if user closes Word. I'll have to re-examine that.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  8. #8
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Automation (Access 97)

    This may be a longshot, but could you call the MsgBox from within Word and just pass the answer back to Access?

    I've done some pretty heavy automation of Excel from Access and I've usually called MsgBoxes from within Excel once it is the Active App. That always seems to work well for me.

    HTH <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  9. #9
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Word Automation (Access 97)

    >>but could you call the MsgBox from within Word and just pass the answer back to Access?<<

    I don't know, I've never tried to do anything like that so I wouldn't know where to begin. Anyway, I'm guessing that once the Access message box was called, it would make Access the active app, and bring it to the front.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Word Automation (Access 97)

    Hi Mark,
    Assuming you're doing this in a loop, if you add 65536 to the vbMsgBoxStyle value (e.g. MsgBox "Test", 65539 will give you Yes, No, Cancel) then the message box should become the foreground window. Using appWord.Activate will then bring word to the foreground for editing etc.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Word Automation (Access 97)

    >>65536 to the vbMsgBoxStyle value (e.g. MsgBox "Test", 65539 will give you Yes, No, Cancel) <<

    Do you actually remember the numeric values? I find it easier to remember vbYesNoCancel.

    But the situation I was describing can't really be done, I found out. I wanted to know why the Access message box floated over the Word document for the first document, but not for subsequent documents. It turns out that my code in Access was such that I was actually opening the Word document and popping the message box BEFORE the rest of the Access screen was displayed! (That is, it all happened before the first Current event processed) So, while Access was displaying in front of Word, the only thing to display at that time was the message box. After that, the Access form was finally displayed, so the next time it became active, it covered Word.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  12. #12
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Altnau, Thurgau, Switzerland
    Posts
    447
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Automation (Access 97)

    Child windows won't appear infront of an App that they don't belong to EXCEPT if the Z-order is modified to set them as a topmost window whne it will appear in front of any window that is not a topmost window.
    If you do require behaviour that the message appears in front of both Access/Word then you may find it easiest to create a dll containg your special messagebox and use automation to put Access in front of word or vice versa before calling the special message box.

  13. #13
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Word Automation (Access 97)

    I found out why the first letter exhibited the behavior of floating the Access message box above the Word document. It was because the rest of the Access form hadn't displayed yet. A form doesn't display until AFTER the first Current event, and the message box got displayed first. Anyway, I've decided to keep the Word document minimized, which allows user to select it if they want.

    Thanks.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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