Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office 2007 and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

Separate version for Access/Office 2003, 2002, and 2000.

Separate version for:
Access 97/95

View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?


"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP




Microsoft Access, Office/VBA, VB6 Modules royalty-free source code libraryMicrosoft Access Modules royalty-free source code libraryMicrosoft Access VBA and VB6 Module Library Free trial of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

Module: Application in Category Microsoft Access : Environment from Total Visual SourceBook

Microsoft Access application level routines for managing the database window, login information, and closing Access using VBA.

Procedure List

Procedure Name



(Declarations) Declarations Declarations and private variables for the modApplication module
CloseAccess Procedure Close the current database and exits Access
CloseCurrentDatabase Procedure Close the current database
DebugCleanup Procedure Turns the hourglass cursor off and restores the Echo state
GetAccessProfile Procedure Get the /profile setting specified by the user when starting Microsoft Access from the command line. A user profile is an Access-specific set of keys in the Windows Registry that you can create to change standard Microsoft Access and Microsoft Jet database engine settings. You can also use user profiles to set run-time options. To activate a user profile, use the /profile command-line option to specify this user profile when you start your application. For more information, search Access online help for "Profiles".
GetCurrentUserName Procedure Get the name of the current logged in user, as defined by the Microsoft Jet security model. This is the name logged into Microsoft Access. If Access Workgroup Security is not in use, this function always returns the user name "Admin".
GetWorkgroupFile Procedure Get the path and name of the Access security workgroup file currently in use. The Access/Jet security model uses a workgroup information file to store user, group and password information.
HideDatabaseWindow Procedure Hides or shows the database window or navigation pane
MinimizeDatabaseWindow Procedure Minimize the database window or navigation pane
RestoreDatabaseWindow Procedure Restore the database window or navigation pane after it was minimized
ShowSearchBar Procedure Show or hide the Search Bar in the Navigation Pane (Access 2007 or later)
HideAccessObject Procedure Programmatically hide or unhide a single object so that it doesn't appear in the Database Window or Navigation Pane.
HideAllAccessObjects Procedure Programmatically hide objects so they don't appear in the Database Window or Navigation Pane, or unhide them. Hide all objects or only objects of a particular type (e.g. tables)

Example Code for Using Module: Application

' Example of modApplication
' To try this example, do the following:
' 1. Create a new form in your copy of Sample.mdb (in the Total Visual SourceBook sample directory).
' 2. Create the following command buttons:
'       cmdCloseAccess
'       cmdCloseDB
'       cmdTest
'       cmdHideShowDB
'       cmdDBWindow
'       cmdShowHideSearchBar
'       cmdHideShowObjects
' 3. Paste this code into the form's module

#If VBA7 Then
  Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
  Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#End If

Private Sub cmdDBWindow_Click()
  ' Example of MinimizeDatabaseWindow and RestoreDatabaseWindow
  Static fMin As Boolean

  If fMin Then
    fMin = Not fMin
    fMin = Not fMin
  End If

End Sub

Private Sub cmdHideShowObject_Click()
  ' Example of hiding/showing a single object (HideAccessObject) and hiding/showing all Access objects (HideAccessObjects)

  Dim strTableName As String

  ' Default to first table in the database
  strTableName = CurrentDb.TableDefs(0).name

  strTableName = InputBox("First we'll hide/show a single table." & vbCrLf & "Enter the name of a table in the current database:", "HideAccessObject Example", strTableName)

  If strTableName <> "" Then
    HideAccessObject True, acTable, strTableName

    MsgBox strTableName & " is hidden. It will now be un-hidden."

    HideAccessObject False, acTable, strTableName

    If MsgBox("Now we'll hide/show all tables. Continue? ", vbYesNo, "HideAccessObjectS Example") = vbYes Then
      HideAllAccessObjects True, False, acTable
      MsgBox "All tables are hidden. They will now be un-hidden."
      HideAllAccessObjects False, False, acTable
    End If
  End If

End Sub

Private Sub cmdShowHideSearchBar_Click()
  ' Example of ShowSearchBar

  Static fShowSearch As Boolean
  fShowSearch = Not fShowSearch

  ShowSearchBar fShowSearch

End Sub

Private Sub Form_Load()
  ' Setup the controls

  Dim ctl As Control
  Dim lngTop As Integer

  Me.cmdTest.Caption = "Test Access application functions"
  Me.cmdCloseAccess.Caption = "Close Access"
  Me.cmdCloseDB.Caption = "Close DB"
  Me.cmdHideShowDB.Caption = "Hide/Show DB"
  Me.cmdDBWindow.Caption = "Min/Restore DB Window"
  Me.cmdShowHideSearchBar.Caption = "Show/Hide Search Bar (Access 2007+)"
  Me.cmdHideShowObject.Caption = "Hide/Show Objects"

  lngTop = 100
  For Each ctl In Me.Controls
    If ctl.ControlType = acCommandButton Then
      ctl.Top = lngTop
      ctl.Left = 100
      ctl.Width = 4000
      ctl.Height = 400
      lngTop = lngTop + 500
    End If
  Next ctl

End Sub

Private Sub cmdCloseAccess_Click()
  ' Example of CloseAccess
  If MsgBox("Are you sure you want to close Access?", vbYesNo) = vbYes Then
  End If
End Sub

Private Sub cmdCloseDB_Click()
  ' Example of CloseCurrentDatabase
  If MsgBox("Are you sure you want to this database?", vbYesNo) = vbYes Then
  End If
End Sub

Private Sub cmdHideShowDB_Click()
  Static fShow As Boolean

  ' Example of HideDatabaseWindow
  fShow = Not fShow
  HideDatabaseWindow fShow

End Sub

Private Sub cmdTest_Click()

  ' Example of DebugCleanup

  DoCmd.Hourglass True
  DoCmd.Echo False

  If MsgBox("Turn off hourglass and restore the Echo state?", vbYesNo) = vbYes Then
    Debug.Print "DebugCleanup turned the hourglass cursor off and restored the Echo state"
    'Wait 3 seconds, then restore echo state (otherwise the form appears locked)
    Sleep 3000
    DoCmd.Echo True
  End If

  ' Example of GetAccessProfile
  Debug.Print "Access profile: " & GetAccessProfile()

  ' Example of GetCurrentUserName
  Debug.Print "Current user: " & GetCurrentUserName()

  ' Example of GetWorkgroupFile
  Debug.Print "Workgroup: " & GetWorkgroupFile()

  MsgBox "Check debug (or Immediate) window for application information."

End Sub

Microsoft Access Module LibraryOverview of Total Visual SourceBook

The source code in Total Visual SourceBook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Additional Resources