Chapter 19: Advanced Access Form Techniques
685
user’s current task. You might also want to hide controls if the user isn’t permitted to perform the
operation (such as deleting an existing record). Rather than simply disabling the control (by setting
its Enabled property to False), hiding the control makes it invisible to the user. Invisible con-
trols are less likely to confuse users than controls that are visible but disabled. The following state-
ment hides a command button named cmdDeleteRecord on the employees form:
intRetVal = SetProperty(“frmEmployees”, “cmdDeleteRecord”, _
“Visible”, “False”)
Reading control properties
If your application manipulates the control properties, at various times you’ll need to read the
value of a control’s property. The following GetProperty function returns the value of any prop-
erty of any open form or any property of any control in an open form. If the function encounters
an error, it returns the value ERROR.
Public Function GetProperty( _
ByVal strFormName As String, _
ByVal strCtrlName As String, _
ByVal strPropName As String) As Variant
Dim frmName As Form
Dim strMsg As String
Dim strFunction As String
Dim strObjName As String
On Error GoTo HandleError
GetProperty = “ERROR”
strFunction = “SetProperty”
‘If no control name is passed, must be a form:
If Len(strCtrlName) > 0 Then
‘We fall through to this code if
‘strCtrlName is not an empty string.
‘Get control property value:
strObjName = strCtrlName
Set frmName = Forms(strFormName)
GetProperty = _
frmName(strCtrlName).Properties(strPropName)
Else
‘We fall through to this code if
‘strCtrlName is an empty string.
‘If no form name provided,
‘exit procedure:
If Len(strFormName) = 0 Then
Exit Function
End If
‘Get form property value:
strObjName = strFormName
Set frmName = Forms(strFormName)
GetProperty = frmName.Properties(strPropName)
End If