How to open Access from the taskbar?

72 Views Asked by At

I had being reviewing the forum and trying several ideas but still have the problem. I am running Access 2013, in a form I hit a button to spell and grammar check a text field. The check is done properly using the Word Grammar check. So far so good. But, once Word is closed I activate Access but it stays blinking in the taskbar and I have to click on it to continue working. I want Access back into the screen to continue working as normal.

The code is the following:

Private Sub Comando2_Click()

Dim objWord As Word.Application
Dim doc As Word.Document

accessid = GetCurrentProcessId
accesshwnd = Application.hWndAccessApp

Set objWord = CreateObject("Word.Application")

With objWord
       Set doc = .Documents.Add
       .Selection.Text = Me.Texto0
       docum = doc & " - Word"
       .Visible = True
       VBA.AppActivate (docum)
       .Visible = False
       .Dialogs(wdDialogToolsSpellingAndGrammar).Show
       If Len(.Selection.Text) <> 1 Then
          Me.Texto0 = .Selection.Text
'          spellcancell = False
       Else
'          spellcancell = True
       End If
       doc.Close wdDoNotSaveChanges
    .Quit
End With

Set objWord = Nothing

AppActivate (accessid)
SetForegroundWindow accesshwnd


End Sub

Thanks in advance for your help Regards

As mentioned above, I want Access back into the screen to continue working as normal. I have tried to activate it by Hwnd, SetForegroundWindow and lots of other ideas read in the forum... nothing worked

2

There are 2 best solutions below

0
Luisja On BEST ANSWER

I found a workaround, it is not ideal, but at least it works till I get a better solution.

Thanks for your help, made me think in a differet way:

    AppActivate GetCurrentProcessId 
    SendKeys "%{TAB}", True 
    SendKeys "{TAB}", True
5
Gustav On

You are making it a bit too complicated, and do close all objects.

This runs as expected:

    Dim objWord     As Word.Application
    Dim doc         As Word.Document
    
    Dim docum       As String
    
    Set objWord = CreateObject("Word.Application")
    
    With objWord
        Set doc = .Documents.Add
        docum = doc.Name & " - Word"
        .Visible = True
        VBA.AppActivate docum
        .Visible = False
        
        .Selection.Text = Me.Texto0
        .Dialogs(wdDialogToolsSpellingAndGrammar).Show
        If Len(.Selection.Text) <> 1 Then
        Me.Texto0 = .Selection.Text
'          spellcancell = False
        Else
'          spellcancell = True
        End If
        
        doc.Close wdDoNotSaveChanges
        Set doc = Nothing
        .Quit
    End With

    Set objWord = Nothing