Results 1 to 3 of 3
  1. #1
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17

    How do I change the focus to Word after document is opened from Access

    I'm almost where I need to be. I can get my code to check to see if a file exists, display an error message if it doesn't, or open the file in Word if it does. Unfortunately, the focus does not change to Word at that point with a maximized window. What code do I need to add to do that? Here is what I have so far:



    Private Sub View_manual_button_Click()


    Dim filepath As String
    filepath = CurrentProject.Path & "\Instructions_for_CAFP_Inventory_Program.doc"
    'MsgBox CurrentProject.Path 'MsgBox for debugging

    If Len(Dir(CurrentProject.Path & "\Instructions_for_CAFP_Inventory_Program.doc" )) = 0 Then

    MsgBox "File does not exist. "

    Else


    Dim oApp As Object
    Dim oWord As Object
    Set oApp = CreateObject("Word.Application")
    Set oWord = oApp.Documents.Open(FileName:=filepath)
    oApp.Visible = True

    'Dim oApp As Object
    'Set oApp = CreateObject("Word.Application")
    'oApp.Visible = True


    End If


    On Error GoTo Err_View_manual_button_Click

    Exit_View_manual_button_Click:




    Exit Sub


    Err_View_manual_button_Click:


    MsgBox Err.Description


    Resume Exit_View_manual_button_Click

    End Sub
    Last edited by June7; 02-24-2014 at 02:18 AM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Bing: Access VBA set focus on Word

    http://www.dbforums.com/microsoft-ac...ation-vba.html

    Try:

    oApp.Activate
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17
    Thank you so much! oApp.Activate was exactly what I needed.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 06-03-2013, 12:58 PM
  2. Closing Word Document From Access
    By bburton in forum Programming
    Replies: 2
    Last Post: 04-25-2011, 10:23 AM
  3. Mail Merge document locked when opened from Access
    By retro in forum Import/Export Data
    Replies: 0
    Last Post: 08-14-2009, 03:12 AM
  4. Word document INTO Access form
    By jonathonhicks in forum Forms
    Replies: 0
    Last Post: 04-30-2007, 05:59 PM
  5. Replies: 1
    Last Post: 12-21-2005, 12:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums