Wayne Whittenberg
Wayne Whittenberg

Reputation: 13

Access 2016 UserForm Called From Word Covered by Word Document

Access 2016 Popup UserForm Obscured by Word Document

I have an Access 2016 database that contains authors and references that I use in my Word Documents. The authors are contained in one table which is joined to the references table.

If the data I need to input into Word isn't in the database, I have an Access UserForm that pops up to enter the data into the database. The problem is that I work with 2 Word documents opened side by side which takes up the full screen and the Access Userform is covered behind the Word documents. Due to the UserForm being popup and modal, it freezes everything. The only workaround I have come up with is to force the Word windows to minimize when the popup is called, but this is not optimal.

This Sub in Word calls the Access UserForm:

Sub OpenDataEntryForm(stAuthor As String)
Dim acc As Access.Application
Dim lngAuthor As Long
Dim stOpenArgs As String

Application.WindowState = wdWindowStateMinimize
Set acc = New Access.Application
    With acc

        .Visible = False
        .OpenCurrentDatabase stAccPath 'stAccPath is a constant
        lngAuthor = .DLookup("[ID]", "[tblAuthors]", "[Authors] = '" & _
              stAuthor & "'")
        stOpenArgs = CStr(lngAuthor)
       .DoCmd.OpenForm "frmDataEntry", acNormal, , , acFormAdd, _
                 acDialog, stOpenArgs
       .Quit   
End With
Application.WindowState = wdWindowStateMaximize
End Sub

This is the Load Event Sub of the Userform:

Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
        Me!Authors = CLng(Me.OpenArgs)
        Me.SetFocus
        Me!OriginalRef.SetFocus  
Else: Me!Authors.Locked = False
End If
End Sub

With the above code, the Word windows minimize so that data can be entered into the Access UserForm. I need to find a way to bring the Access UserForm to the front of the documents when it's called so that I don't have to minimize the document windows.

Upvotes: 0

Views: 72

Answers (1)

Wayne Whittenberg
Wayne Whittenberg

Reputation: 13

Using this link from Cindy Meister: VBA API declarations. Bring window to front , regardless of application, I was able to add this line of code to my Access UserFrom Form_Load Event:

AppActivate Me.Caption

This now brings the UserForm to the front whenever it is called.

Upvotes: 0

Related Questions