Link to home
Start Free TrialLog in
Avatar of rbichon
rbichon

asked on

Hide / Unhide Database window with VBA

I have an Access database that I open with vbscript using the command:

Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase("C:\new.mdb")

I have the modal and popup properties set to true so that when the database opens, it opens with a specific form visible but the rest of the Access window is hidden. This part works fine. However, I have a button that unhides the Access window so that people can select a table or another form when they want to. The problem is that when I unhide the window, the Database Window remains hidden even when I do a DoCmd.SelectObject acForm, , True on it. I have figured out that if I open the form like this:

Set appAccess = CreateObject("Access.Application")
appAccess.Visible = true
appAccess.OpenCurrentDatabase("C:\new.mdb")
appAccess.Visible = false

then the Database Window does not remain hidden when the button is clicked. This however defeats the purpose of using the vbscript to open the database in the first place because I don't want the users to see the initial startup of Access. Please let me know if there is another way. Also let me know if this makes sense.
ASKER CERTIFIED SOLUTION
Avatar of nmilmine
nmilmine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rbichon
rbichon

ASKER

That didn't work. If you read above, I am not having an issue with the startup of the database if a user simply opens it. It is when it is opened using a VBS file and appAccess.visible = false. Right now I am using a module to make the window visible again:

Option Compare Database
Option Explicit

Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3


Private Declare Function apiShowWindow Lib "user32" _
    Alias "ShowWindow" (ByVal hwnd As Long, _
          ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
'       ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
'       ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
'       ?fSetAccessWindow(SW_HIDE)
'Normal window:
'       ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX  As Long
Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm
    If Err <> 0 Then 'no Activeform
      If nCmdShow = SW_HIDE Then
        MsgBox "Cannot hide Access unless " _
                    & "a form is on screen"
      Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
      End If
    Else
        If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
            MsgBox "Cannot minimize Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
            MsgBox "Cannot hide Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        Else
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
        End If
    End If
    fSetAccessWindow = (loX <> 0)
End Function

Is there a way to set the visible property of the window without this module? Can it be done in VBA for the current database?