Microsoft Access 2010 Bible

(Rick Simeone) #1

Part III: More-Advanced Access Techniques


686


ExitHere:
Exit Function
HandleError:
Select Case Err
Case 2450
strMsg = “‘“ & strFormName & “‘ is not an open form”
Case 2465
strMsg = “‘“ & strCtrlName _
& “‘ is not a control on ‘“ & strFormName & “‘“
Case 2455
strMsg = “‘“ & strPropName _
& “‘ is not a property of ‘“ & strObjName & “‘“
Case Else
strMsg = “Error# “ & Err & “: “ & Err.Description
End Select
MsgBox strMsg, vbExclamation + vbOKOnly, _
“Error in Procedure “ & strFunction
GetProperty = strMsg
Resume ExitHere
End Function

Notice that GetProperty returns a variant data type value. A variant is returned because the
function might return a property object, or — in the event of a problem accessing the property —
a string containing ERROR. If a runtime error is triggered by the GetProperty function, a string
containing the error number and message is returned.

Working with Subforms


Subforms are indispensable for displaying information from two different tables or queries on the
screen together. Typically, subforms are used where the main form’s record source has a one-to-
many relationship with the subform’s record source. Many records in the subform are associated
with one record in the main form.

Access uses the LinkMasterFields and LinkChildFields properties of the subform control
to choose the records in the subform that are related to each record in the main form. Whenever a
value in the main form’s link field changes, Access automatically requeries the subform.

When creating a subform, you might want to display subform aggregate information in the master
form. For example, you might want to display the count of the records in the subform somewhere
on your main form. For an example of this technique, see the txtItemCount control in frm-
CustomerSales in Chapter19.accdb. In this case the ControlSource expression in the
txtItemCount control is

=“(“ & [subfPurchases].[Form]![txtItemCount] & “ items)”

(Note that the equal sign needs to be included.) The result of this expression is shown in
Figure 19.3.
Free download pdf