Hide / Unhide Database window with VBA

Posted on 2005-05-16
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
    LVL 4

    Accepted Solution

    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

    LVL 1

    Author Comment

    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"
            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?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now