• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 27. STARTUP CHECKING SYSTEM ROUT... > PERFORMING STARTUP SYSTEM CHECKS

PERFORMING STARTUP SYSTEM CHECKS

The routine for performing startup system routines is ap_AppInit (see Listing 27.1). All routines shown in this chapter can be found in the modGlobalUtilities module of VideoApp(ADO).mdb, which can be found in the \Examples folder on the CD-ROM.

Listing 27.1. VideoApp(ADO).mdb: The Main Startup System Checking Routine

Function ap_AppInit()

    Dim cnnLocal As New ADODB.Connection
    Dim rstSharedTables As New ADODB.Recordset
    Dim lngCurrError As Long, strCurrError As String

    DoEvents
    DoCmd.Echo True, "Checking Connections..."

    flgLeaveApplication = False

    Set cnnLocal = CurrentProject.Connection

    ap_InitializeDBProps cnnLocal

    '-- Section 2: User requested to logout, quit the application
    If ap_LogOutCheck(pstrBackEndPath) Then
       Beep
       MsgBox "Maintenance is being performed on the backend" & vbCrLf _
          & vbCrLf & "All users are requested to logout at this time.", _
          vbOKOnly + vbCritical, "Logging Out for Maintenance"
       Application.Quit
       Exit Function
    End If

    '-- Section 3: Open the table containing the list of linked tables
        ' Open employee table.
    rstSharedTables.Open "tblSharedTables", cnnLocal, adOpenStatic

    On Error Resume Next

    rstSharedTables.MoveLast

    Dim rstTestTable As New ADODB.Recordset
    Dim strTableName As String

    strTableName = rstSharedTables!TableName
    rstTestTable.Open strTableName, cnnLocal, adOpenStatic


    lngCurrError = Err.Number

    If lngCurrError = 0 Then

        Dim varTest As Variant
        varTest = rstTestTable(0).Name
        lngCurrError = Err.Number

    End If
    strCurrError = Err.Description

    Do Until lngCurrError = 0

      On Error GoTo Error_ap_App_Init

      Select Case lngCurrError

        Case apErrInvalidSQL


         '-- Section 4: If the Data MDB is found in the App Directory,
         '--            link the files.

         If Dir(pstrAppPath & "\" & pstrBackEndName) = pstrBackEndName _
            Then

            ap_LinkTables rstSharedTables, pstrAppPath & "\" & _
                           pstrBackEndName
            pstrBackEndPath = pstrAppPath & "\"

         Else

                '-- Section 5: Allow the user to locate the BackEnd MDB
                If Not ap_LocateBackend(rstSharedTables, _
                       strCurrError) Then
                   flgLeaveApplication = True
                End If

             End If

         Case apErrDBCorrupted1
            '-- Section 6: Backend Corrupted. Repair?
            Beep

            If MsgBox("The Backend Database is Corrupted." & vbCrLf & _
               vbCrLf & "Would you like to log users out and " & _
               " attempt to compact/repair it?", vbYesNo + vbCritical, _
               "Corrupted Backend!") = vbYes Then

               DoCmd.OpenForm "ap_CompactDatabase", acForm

            Else

               flgLeaveApplication = True

            End If

       End Select

       '-- Section 7: Leave the application if requested
       If flgLeaveApplication Then
          Application.Quit
          Exit Function
       End If

       On Error Resume Next

       '-- Section 8: Let's try and open the first table again.
       rstTestTable.Open strTableName, cnnLocal, adOpenStatic
       lngCurrError = Err.Number
       strCurrError = Err.Description

    Loop

    On Error GoTo Error_ap_App_Init


    '-- Section 9: Save the BackEnd path in the BackEndPath property
    '--             for future use.
    ap_SetDatabaseProp "LastBackEndPath", pstrBackEndPath

    '-- Check for Replicated Tables
    ap_CheckReplicatedTables
    '-- Turn on the Monitor Form
    DoCmd.OpenForm "UserLogOutMonitor", , , , , acHidden

    DoCmd.Close acForm, "SplashScreen"
    DoCmd.Echo True
    rstSharedTables.Close

Exit_ap_App_Init:
   Exit Function

Error_ap_App_Init:
   Beep
   MsgBox "The following error occurred: " & Err.Description & vbCrLf & _
           vbCrLf & "The system will now be closed down!"
   Application.Quit

End Function


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint