Word 2010 from Access 2010 returns blinking taskbar

Answered Word 2010 from Access 2010 returns blinking taskbar

  • Thursday, March 08, 2012 1:57 PM
     
     

    Hi,

    In all versions of Access I always used the following (normal working) code tot start Word and open a template or merge with a template.

    Dim objWord As Word.Application

    Set objWord = StartWord()

    With objWord

    .Visible = True

    .Documents.Add Template:= _

            "C:\Users\Louis\Documents\Vormit\Vormit sjablonen\Brief Vormit Access.DOT", _

             NewTemplate:=False, DocumentType:=0

    .ActiveDocument.bookmarks("Tekst").Select

    .Activate

    .Application.WindowState = wdWindowStateMaximize

    End with .....

    Why is it that in Windows 7 and Office 2010 all code works fine except for the fact that Word doesn't get the focus at the end of all actions.

    Instead I have to activate Word by klicking a blinking Word taskbar icon?

    Who can help me out?

All Replies

  • Thursday, March 08, 2012 3:52 PM
     
      Has Code

    I tested your code in Access 2010 SP1 (32-bit) on Windows 7 Home Premium SP1 (64-bit), using a template on my computer.

    Word did get the focus as intended: I could start typing in the new document.

    So it's not a problem with Access 2010 or Windows 7.

    But try adding a line

    AppActivate "Microsoft Word"

    before the end of the procedure.

    Regards, Hans Vogelaar

  • Thursday, March 08, 2012 5:35 PM
     
     

    Hi Hans,

    Still the result is a blinking Word icon on the taskbar, nothing changed, while in older versions this code works perfect.

    The fact you don't have the problem acknowledges that I have to test not with an existing database but a new one.

    Thanks for testing.

    Louis

  • Friday, March 09, 2012 10:15 AM
     
     

    Hi Hans,

    The problem after testing is a line of code that closes the original DOT template for the user.

    When I add the last line to close the original template after merging:

    .ActiveDocument.MailMerge.Destination = wdSendToNewDocument
    .ActiveDocument.MailMerge.Execute
    .Activate
    .Application.WindowState = wdWindowStateMaximize
    .Application.Documents(2).Close wdDoNotSaveChanges


    This last line makes Word only to blink on the taskbar, but why?

  • Friday, March 09, 2012 10:54 AM
     
      Has Code

    Does it make a difference if you create a variable to refer to the document, and only make the application visible at the end?

        Dim objWord As Word.Application
        Dim objDoc As Word.Document
        Set objWord = StartWord()
        With objWord
            Set objDoc = .Documents.Add(Template:= _
                "C:\Users\Louis\Documents\Vormit\Vormit sjablonen\Brief Vormit Access.DOT")
            objDoc.Bookmarks("Tekst").Select
            ' other code here - use objDoc to refer to the document.
            ' ...
            objDoc.MailMerge.Destination = wdSendToNewDocument
            objDoc.MailMerge.Execute
            objDoc.Close wdDoNotSaveChanges
            .Visible = True
            .Activate
            .Application.WindowState = wdWindowStateMaximize
        End With


    Regards, Hans Vogelaar

  • Friday, March 09, 2012 11:38 AM
     
     

    Hi Hans,

    Changing the code to the suggestion above does not make a difference....


    _______________________________________ Regards, Louis Vorstenbosch

  • Friday, March 09, 2012 11:50 AM
     
     
    I'm afraid you'll have to live with it - Windows can be very stubborn when it comes to yielding the focus.

    Regards, Hans Vogelaar

  • Friday, March 09, 2012 11:51 AM
     
     

    Hi Hans,

    I Noticed something else strange:

    When I open the database and at one time use Alt+F11 (codescreen) , while nothing changing in code, the above code works properly.

    !! until the database is closed an opened again!!!

    So restarting of the database is essential to testing the functionality of this code for merging to a new document.


    Regards, Louis Vorstenbosch

  • Friday, March 09, 2012 12:33 PM
     
     
    That's strange indeed...

    Regards, Hans Vogelaar

  • Friday, March 09, 2012 2:14 PM
     
     

    Good Morning Gentlemen,

    I don't know the answer but I was hoping to suggest something. On my computer at work I have similar issues with Adobe while at home I do not. The difference for my situation is at home I have on both machines Windows 7 Home Premium and at work Windows 7 Enterprise. Does this correlate to the differences in your OS's and results?


    Chris Ward

  • Friday, March 09, 2012 2:25 PM
     
     
    I tested in Windows 7 Home Premium and did not have the problem reported by Louis.

    Regards, Hans Vogelaar

  • Friday, March 09, 2012 5:03 PM
     
     
    Just tested the code in Vista Business SP2 with Office 2007 SP3, works perfect, closes the template and makes mergeresult in Word the active screen.

    Regards, Louis Vorstenbosch

  • Friday, March 09, 2012 5:04 PM
     
     
    Windows 7, however nice it may be, has some strange quirks.

    Regards, Hans Vogelaar

  • Friday, March 09, 2012 6:19 PM
     
      Has Code

    Hi Hans,

    Perhaps you are right!

    .ActiveDocument.MailMerge.Destination = wdSendToNewDocument
    .ActiveDocument.MailMerge.Execute
    .Activate
    .Application.WindowState = wdWindowStateMaximize
    .Application.Documents(2).Close wdDoNotSaveChanges

    The latest test Windows 7 Pro SP1 with Office 2007, after restarting the database, mailmerge results in a blinking Word taskbar icon  instead of Word in the active maximized screen!!!!

    Only with the next code it works how it was intended except without the deletion of the original mergetemplate:

    .ActiveDocument.MailMerge.Destination = wdSendToNewDocument
    .ActiveDocument.MailMerge.Execute
    .Application.WindowState = wdWindowStateMaximize
    End With
    AppActivate "Microsoft Word" (this is necessary in Windows 7, thanks Hans!!)

    deletion of the original mergetemplate by the code:  .Application.Documents(2).Close wdDoNotSaveChanges

    is impossible because this apparently prevents Word to become the active screen.



    Regards, Louis Vorstenbosch

  • Tuesday, March 13, 2012 6:49 PM
     
     

    Hi Hans,

    Don't know how to make a workaroud in VBA but the following change in regedit did the trick:

    Fix:

    Follow the steps below: 

    1. Open Start >> Run and typeregedit” (without quotes)

    2. Navigate to the following path:

      [HKEY_CURRENT_USER\Control Panel\Desktop]

    3. Right Click on the empty space and create a new DWORD value, or modify the existing value named ‘ForegroundLockTimeout’, set or modify the value to 0. (this value will cause the application to take the focus instantly.)


    Regards, Louis Vorstenbosch

  • Tuesday, March 13, 2012 7:58 PM
     
     
    Thanks for sharing this workaround!

    Regards, Hans Vogelaar

  • Tuesday, March 13, 2012 8:18 PM
     
     

    Good Afternoon Louis,

    Can this be used to fix my Adobe problem from Access also?


    Chris Ward

  • Wednesday, March 14, 2012 7:39 AM
     
     Answered

    Hi Chris,

    Don't know for sure but read the full article and do just as I did..give it a try...

    window focus issues


    Regards, Louis Vorstenbosch

  • Sunday, April 08, 2012 1:24 PM
     
     

    Hi Chris,

    How about it, did it work out for you good?


    Regards, Louis Vorstenbosch

  • Monday, April 09, 2012 3:08 AM
     
     

    This is only a problem at my work machine. I don't have access rights to the registry (not that I couldn't get to it anyway) so I forwarded your information to our IT department. I am confident that when this issue becomes significant enough something will be done.

    Thank you for your information.


    Chris Ward