FMS Home FMS Software Development Team Blog FMS Facebook Page FMS Twitter
Jump: Search:

Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

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

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

Supports Access/Office 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

 

 

 

 
Royalty free source code library modules for Microsoft Access, VB6, VBA, OfficeRoyalty free source code library modules for Microsoft Access, VB6, VBA, OfficeVBA and VB6 Source Code Library Download the free trial version of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

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

Startup routines for a Microsoft Access database application to open backend databases, relink tables, set error trapping, etc. using Access VBA.

Procedure List

Procedure Name

Type

Description

(Declarations) Declarations Declarations and private variables for the modStartup module
CreateLinkedTable Procedure Create a new table linked to a Jet/Access table in another database
GetCommandLine Procedure Access can be started with a command line option passed after the /cmd tag (commonly in a shortcut). Your program can use this as a flag for special processing.
GetCommandLineValues Procedure Access can be started with a command line option passed after the /cmd tag (commonly in a shortcut) Your program can use this as a flag for special processing. If you pass multiple values in this manner separated by a delimiter, the values are loaded into the passed array.
OpenAllDatabases Procedure Use this procedure when there are multiple backend databases to keep open; or close the previously opened databases. NOTE: Significant performance improvements can be achieved by keeping a handle open during the entire time your application is running. Visit http://www.fmsinc.com/MicrosoftAccess/performance/linkeddatabase.html for more information.
OpenBackendDatabase Procedure Open a handle to a backend database and keep it open; or close the previously opened database. NOTE: Significant performance improvements can be achieved by keeping a database handle open during the entire time your application is running. Visit http://www.fmsinc.com/MicrosoftAccess/performance/linkeddatabase.html for more information.
RelinkAllTables Procedure Relink all the linked (attached) tables in the current database to a new database
RelinkTable Procedure Relink (attach) one table in the current database to a new database
RelinkTableDef Procedure Relink (attach) a table definition to a new database (eliminates the need to create a new database handle if processing lots of tables)
SetErrorTrapping Procedure Set or reset error trapping setting so errors are properly handled while your application runs. This setting can be manually set from the IDE under the Tools, Options menu, General Tab. If error trapping is set to Break on All Errors, code with On Error Resume Next will stop if an error occurs. This setting is at the machine level, not your application so what works fine on one machine may fail on another due to this setting. To avoid this, make sure error trapping is set to Break in Class Modules by calling this routine when your application starts. When the application finishes, call this routine again to reset the setting back to the original value.
StartupFormGet Procedure Get the Microsoft Access database's current startup form name
StartupFormSet Procedure Set or remove the startup form for a Microsoft Access database when it opens

Example Code for Using Module: modStartup

' Example of modStartup
'
' To try this example, do the following:
' 1. Create a new form
' 2. Create a command button 'cmdTest'
' 3. Link the table named Categories from Sample.mdb (in the directory where you installed TVSB sample files, usually C:\TVSBSamp).
' 4. Paste this code into the form's module

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

Private Const cstrSample As String = "C:\Total Visual SourceBook 2013\Samples\Sample.mdb"
Private Const cstrLinkedTable As String = "Categories"

Private Sub Command0_Click()
  Dim strTmp As String
  Dim astrTmp() As String
  Dim intI As Integer

  'GetCommandLine and GetCommandLineValues
  ' To test this, create a shortcut for your database with the command line /cmd Test1;Test2;Test3
  ' e.g. C:\Total Visual SourceBook 2013\Samples\sample.mdb /cmd Test1;Test2;Test3
  strTmp = GetCommandLine
  If strTmp = "" Then
    Debug.Print "Access was not started with a command line option."
  Else
    Debug.Print "Access was started with command line: " & strTmp
    If GetCommandLineValues(astrTmp()) Then
      For intI = 0 To UBound(astrTmp)
        Debug.Print astrTmp(intI)
      Next intI
    End If
  End If

  'OpenBackendDatabase
  If OpenBackendDatabase(True, cstrSample) Then
    Debug.Print cstrSample & " opened..."
    ' Wait 1 second
    Sleep 1000
    If OpenBackendDatabase(False, cstrSample) Then
      Debug.Print "..." & cstrSample & " closed"
    End If
  End If

  'RelinkTable
  If MsgBox("Relink " & cstrLinkedTable & " to " & cstrSample & "?", vbYesNo) = vbYes Then
    If RelinkTable(cstrLinkedTable, cstrSample) Then
      Debug.Print cstrLinkedTable & " relinked."
    End If
  End If

  'RelinkAllTables
  If MsgBox("Relink All Tables to " & cstrSample & "?", vbYesNo) = vbYes Then
    If RelinkAllTables(cstrSample) Then
      Debug.Print "All tables relinked."
    End If
  End If

  'SetErrorTrapping
  SetErrorTrapping True
  Debug.Print "Error trapping set..."
  ' Wait 1 second
  Sleep 1000
  SetErrorTrapping False
  Debug.Print "...error trapping reset to previous value."

  strTmp = StartupFormGet()
  Debug.Print "The startup form is : " & strTmp

  If False Then
    ' This example is shown but not run since it changes the startup form of your database
    If StartupFormSet("MyForm") Then
      Debug.Print "Startup form is set to MyForm"
    End If

    ' Removees the startup form on your database
    If StartupFormSet("") Then
      Debug.Print "Startup form removed"
    End If
  End If
End Sub

Overview 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

Feedback

Contact Us  l   Web questions: Webmaster   l   Copyright FMS, Inc., Vienna, Virginia
Celebrating our 28th Year of Software Excellence