Practical Examples: Building a Library for Your Application
Now that you are familiar with library databases and what they offer, try extracting all the generic functions from an application and placing them in a library database. This section presents a step-by-step roadmap for accomplishing this task.NOTEThis process already has been completed for CHAP24.MDB. The associated library database is called CHAP24LIB.MDA. If you want to complete this process as an exercise, copy CHAP24.MDB and complete the outlined steps.To extract the generic functions from the Time and Billing application and place them in a library database, follow these steps:
You should move one more database element to the library database: the Report Selection Criteria form. This form is generic and you can therefore use it in many of the applications you create.Follow these steps to move the frmReportDateRange form to the library database:
DoCmd.OpenForm "frmReportDateRange", , , , , acDialog, _
strOpenArg
End Sub
You must modify three reports in the application database to accommodate the movement of the frmReportDateRange form to a library database: rptProjectBillingsByWorkCode, rptClientBillingsByProject, and rptEmployeeBillingsByProject. You must modify the Open event of the rptProjectBillingsByWorkCode report to look like this:Private Sub Report_Open(Cancel As Integer)
Call OpenReportDateRange("rptProjectBillingsByWorkCode")
If Not IsLoaded("frmReportDateRange") Then
Cancel = True
End If
End Sub
Instead of opening the form directly, which would not work because the form is in a library database, you must call the OpenReportDateRange library routine to open the form. The code uses the strOpenArg parameter to the OpenReportDateRange subroutine as the OpenArgs parameter for the frmReportCriteria form. You must make similar changes to the rptClientBillingsByProject and rptEmployeeBillingsByProject reports. You should modify the Open event of the rptClientBillingsByProject report to look like Listing 24.3.
Listing 24.3 Modifying the Open Event of the rptClientBillingsByProject Report
Private Sub Report_Open(Cancel As Integer)
Call OpenReportDateRange("rptClientBillingsByProject")
If Not IsLoaded("frmReportDateRange") Then
Cancel = True
Else
Select Case Forms!frmReportDateRange!optDetailLevel.Value
Case 1
Me.Caption = Me.Caption & " Summary Only"
Me!lblTitle.Caption = Me.lblTitle.Caption & " _
Summary Only"
Me.Detail.Visible = False
Case 2
Me.Caption = Me.Caption & " Detail Only"
Me!lblTitle.Caption = Me.lblTitle.Caption & " _
Detail Only"
Me.GroupHeader0.Visible = False
Me.GroupFooter1.Visible = False
Me!CompanyNameDet.Visible = True
Case 3
Me.Caption = Me.Caption & " Summary and Detail"
Me!lblTitle.Caption = Me.lblTitle.Caption & _
" Summary and Detail"
Me!CompanyNameDet.Visible = False
End Select
End If
End Sub
Modify the Open event of the rptEmployeeBillingsByProject report to look like this:Private Sub Report_Open(Cancel As Integer)
Call OpenReportDateRange("rptEmployeeBillingsByProject")
If Not IsLoaded("frmReportDateRange") Then
Cancel = True
End If
End Sub
After you move the generic features of the application to the library database, you can try to build another application database and use the same library features.