S
sargum
Hello,
I am trying to use the following code to hide data in a subform when it
loads. The subform Property Default view is set to "Datasheet" as
opposed to "Single Form", etc. The code works great for Single Form,
Continuous Form fields, etc. but does nothing if one desires the
subform to appear as a datasheet. Any suggestions on how to modify the
code to hide text for fields in a datasheet?
'---------------------------------------------------------------------------------------
' Procedure : HideText
' DateTime : 12/21/2006 10:53
' Author : Klatuu
' Purpose : Hide Text on a form
' Notes : Always call this function the first time in a form with
blnShow = False
' : Otherwise, the text may not reappear.
' : Based on code by Allen Browne
'---------------------------------------------------------------------------------------
'
Public Function HideText(frm As Form, blnShow As Boolean, ParamArray
avarExceptionList())
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
'Save any edits
If frm.Dirty Then
frm.Dirty = False
End If
On Error GoTo HideText_Error
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acOptionButton, acToggleButton
'Lock/unlock these controls if bound to fields.
bSkip = False
For lngI = LBound(avarExceptionList) To
UBound(avarExceptionList)
If avarExceptionList(lngI) = ctl.Name Then
bSkip = True
Exit For
End If
Next
If Not bSkip Then
If HasProperty(ctl, "ControlSource") And
HasProperty(ctl, "ForeColor") Then
If blnShow Then
ctl.ForeColor = ctl.Tag
Else
ctl.Tag = ctl.ForeColor
ctl.ForeColor = ctl.BackColor
End If
End If
End If
Case acCheckBox, acLabel, acLine, acRectangle, acCommandButton,
acTabCtl, acPage, _
acPageBreak, acImage, acObjectFrame
'Do nothing
Case Else
'Includes acBoundObjectFrame, acCustomControl
'Do Nothing
End Select
Next
HideText_Exit:
On Error Resume Next
Exit Function
HideText_Error:
Select Case Err.Number
Case 13 'Error Trapping
Resume Next
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideText of Module modFormOperations"
GoTo HideText_Exit
End Select
End Function
Public Function HasProperty(obj As Object, strPropName As String) As
Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
Thx.
Sargum
I am trying to use the following code to hide data in a subform when it
loads. The subform Property Default view is set to "Datasheet" as
opposed to "Single Form", etc. The code works great for Single Form,
Continuous Form fields, etc. but does nothing if one desires the
subform to appear as a datasheet. Any suggestions on how to modify the
code to hide text for fields in a datasheet?
'---------------------------------------------------------------------------------------
' Procedure : HideText
' DateTime : 12/21/2006 10:53
' Author : Klatuu
' Purpose : Hide Text on a form
' Notes : Always call this function the first time in a form with
blnShow = False
' : Otherwise, the text may not reappear.
' : Based on code by Allen Browne
'---------------------------------------------------------------------------------------
'
Public Function HideText(frm As Form, blnShow As Boolean, ParamArray
avarExceptionList())
Dim ctl As Control 'Each control on the form
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean
'Save any edits
If frm.Dirty Then
frm.Dirty = False
End If
On Error GoTo HideText_Error
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acOptionButton, acToggleButton
'Lock/unlock these controls if bound to fields.
bSkip = False
For lngI = LBound(avarExceptionList) To
UBound(avarExceptionList)
If avarExceptionList(lngI) = ctl.Name Then
bSkip = True
Exit For
End If
Next
If Not bSkip Then
If HasProperty(ctl, "ControlSource") And
HasProperty(ctl, "ForeColor") Then
If blnShow Then
ctl.ForeColor = ctl.Tag
Else
ctl.Tag = ctl.ForeColor
ctl.ForeColor = ctl.BackColor
End If
End If
End If
Case acCheckBox, acLabel, acLine, acRectangle, acCommandButton,
acTabCtl, acPage, _
acPageBreak, acImage, acObjectFrame
'Do nothing
Case Else
'Includes acBoundObjectFrame, acCustomControl
'Do Nothing
End Select
Next
HideText_Exit:
On Error Resume Next
Exit Function
HideText_Error:
Select Case Err.Number
Case 13 'Error Trapping
Resume Next
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideText of Module modFormOperations"
GoTo HideText_Exit
End Select
End Function
Public Function HasProperty(obj As Object, strPropName As String) As
Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
Thx.
Sargum