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.Appli cation")
appAccess.OpenCurrentDatab ase("C:\ne w.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.Appli cation")
appAccess.Visible = true
appAccess.OpenCurrentDatab ase("C:\ne w.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.
Set appAccess = CreateObject("Access.Appli
appAccess.OpenCurrentDatab
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.Appli
appAccess.Visible = true
appAccess.OpenCurrentDatab
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_SHOWM
'Minimize window:
' ?fSetAccessWindow(SW_SHOWM
'Hide window:
' ?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWN
'
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(hWndAccessAp
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(hWndAccessAp
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?