Section 6 of the ap_AppInit() function deals solely with handling the repair of the back end if it requires it:
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
This code hasn't changed from the DAO version.
Note
One big change that has occurred with Jet is that you no longer use Compact and Repair to perform the separate functions. They're combined in the CompactDatabase method in ADO and DAO. DAO is located off the Workspace object, as before; ADO can be found off the JRO.JetEngine object.
Section 6 starts by handling the situation where lngCurrError is equal to apErrDBCorrupted1, which is the constant used for corrupted database error. Next, a message box informs the user of the situation and asks whether he wants to try to compact/repair it.
After displaying the message box, the ap_CompactDatabase form opens. The OnLoad event of ap_CompactDatabase first checks whether anyone has already created the LogOut.flg file. If someone has created the file, the routine exits the system. Listing 27.5 shows the OnLoad procedure for ap_CompactDatabase.
Tip
Notice that the constant apProvider is being used. If you take a look at the declarations section, you will see the following line of code:
Public Const apProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
By using a constant such as this one for the provider string, you will save yourself many hassles later when you have to upgrade to a new version of ADO or Jet, or switch providers altogether.
Section 7 is unchanged between ADO and DAO. Section 8 uses the Open method off the recordset object, rather than the OpenRecordset method that DAO uses:
'-- 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
The last section is section 9:
'-- 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
This code performs the following actions:
1. |
It stores the current back-end path into the ztblDatabaseProperties table's LastBackEndPath field. (The ap_SetDatabaseProp routine was covered earlier in the section “Setting and Retrieving System Settings with ADO.”) |
2. |
The next two routines perform tasks that are discussed in other chapters. The ap_ErrorCheckLocal subroutine, discussed in Chapter 7, “Handling Your Errors in Access with VBA,” helps log errors into a table. The ap_CheckReplicatedTables subroutine, discussed in Chapter 28, “Creating Maintenance Routines,” replicates tables from the back end to the front end for performance purposes. The ADO version of ap_CheckReplicatedTables is discussed in the next section. |
3. |
The code opens the UserLogOutMonitor form. This form, used to monitor whether users need to log out, was discussed in Chapter 26 in the section “Logging Users Out in the Middle of the Application.” |
4. |
It closes the splash screen. |
5. |
The code closes the rstSharedTables recordset. |
18.116.15.161