Hide / Unhide Database window with VBA

Posted on 2005-05-16
Medium Priority
Last Modified: 2008-02-26
I have an Access database that I open with vbscript using the command:

Set appAccess = CreateObject("Access.Application")

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.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.
Question by:rbichon

Accepted Solution

nmilmine earned 750 total points
ID: 14014097
How about

'This sets security, so users can't fool around with stuff--very useful....

Sub SetStartupProperties()

ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowShortcutMenus", dbBoolean, False

ChangeProperty "AllowBreakIntoCode", dbBoolean, False
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, True

End Sub

'This turns all the protection off

Sub SetAdminProperties()

ChangeProperty "StartupShowDBWindow", dbBoolean, True
ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowShortcutMenus", dbBoolean, True

ChangeProperty "AllowBreakIntoCode", dbBoolean, True
ChangeProperty "AllowSpecialKeys", dbBoolean, True
ChangeProperty "AllowBypassKey", dbBoolean, True

End Sub

'This part is the function used to make the changes

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Database, prp As Property
Const conPropNotFoundError = 3270

Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = True

Exit Function

If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function


Author Comment

ID: 14017791
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

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"
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
      End If
        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"
            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?

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question