Microsoft Access 2010 Bible

(Rick Simeone) #1

Part III: More-Advanced Access Techniques


684


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 2465
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
SetProperty = False
Resume ExitHere
End Function

This function takes four arguments:

l The name of the form

l (^) The name of the control (if any)
l The name of the property to set
l (^) The new value of the property
SetProperty returns True if the operation is successful and False if it is not. For example, to
disable the button named GoToNew on frmEmployees, use the following statement:
intRetVal = SetProperty(“frmEmployees”, “GoToNew”,
“Enabled”, False)
Although this task is easily done in code behind frmEmployees, SetProperty can be called
from anywhere in the application. This means that, another form (perhaps a switchboard form)
can easily control the enabled state the New button on frmEmployees.
To set the value of a form property, pass an empty string (““) as the control name. For example,
use the following statement to set the frmEmployees form’s caption (in the Chapter19.accdb
database) to Sales Department:
intRetVal = SetProperty(“frmEmployees”, ““,

“Caption”, “Sales Department”)
You can easily hide and show controls by adjusting a control’s Visible property. You might want
to hide certain controls (such as command buttons or text boxes) when they’re irrelevant to the

Free download pdf