A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Want to enable fields after combox selection



 
 
Thread Tools Display Modes
  #1  
Old December 20th, 2006, 07:52 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 32
Default Want to enable fields after combox selection

Hi,

Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL
the fields in a particular form. (It would be bonus if anyone could
tell me how to get rid of data showing up in disabled fields. I want
disabled fields to show no data until they "come to life" after a value
is chosen from the combobox)

I have played around with setting each individ field to visible=false
and then visible = true with "After Update" in combo box and this works
fine but I want to know if there is a quick way to set it such that in
one quick swoop, you can enable "disabled" fields after a combobox
selection...there has to be some code out there...like
Forms![Form_Name].fields.all.enabled=true...I tried this, didn't work.

I want to avoid having to code for each individ. field. every time one
has to be added at a later date.

Thx.
S

  #2  
Old December 20th, 2006, 09:24 PM posted to microsoft.public.access.forms
NthDegree via AccessMonster.com
external usenet poster
 
Posts: 14
Default Want to enable fields after combox selection

You could do something like this:
The Case statement will specify the various types of controls found on the
form that could contain data.
The control "cboSelectionBox" is the combo box that you want to control the
other fields.
This statement /If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.Name)
= ""/ could be used to clear the field if it was in a disabled state.

You could run this code from the combo box "After Update" action to enable
the fields and in the forms "On Open" action to disable them.

For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox, acOptionGroup, acCheckBox
If ctl.Name = "cboSelectionBox" Then
' do nothing
Else
Me.Controls(ctl.Name).Enabled (or Disabled)
' If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.
Name) = ""
End If
End Select
End With
Next ctl

wrote:
Hi,

Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL
the fields in a particular form. (It would be bonus if anyone could
tell me how to get rid of data showing up in disabled fields. I want
disabled fields to show no data until they "come to life" after a value
is chosen from the combobox)

I have played around with setting each individ field to visible=false
and then visible = true with "After Update" in combo box and this works
fine but I want to know if there is a quick way to set it such that in
one quick swoop, you can enable "disabled" fields after a combobox
selection...there has to be some code out there...like
Forms![Form_Name].fields.all.enabled=true...I tried this, didn't work.

I want to avoid having to code for each individ. field. every time one
has to be added at a later date.

Thx.
S


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

  #3  
Old December 20th, 2006, 09:49 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Want to enable fields after combox selection

In one quick swoop!
Here is a function that either locks or unlocks the controls on a form. You
pass the form as a form object, True to Lock or False to Unlock, and the name
of any controls you want to exclude (Like your combo).

I don't know where I got this code, I didn't write it.

Put the code below in a standard module so you can use it from any form.
There are two functions. The first calls the second.

As to making the controls that contain values appear to be blank, it can be
done. As you know, Access always show the data for some record. The only
time you see the controls blank is if you are on a new record. But, being the
sneaky devil I am, here is a way to do it. I haven't written the code, but
your post made me think about it.

Write a function (or you could add it to this one) that loops through the
controls and saves the Forecolor for each control so you know what color the
text originally was and sets the Forecolor to the same color as the
Backcolor. Now, it appears to be blank

Then to turn the text back on, you would have to go through the controls and
set the forecolor to what it used to be.

and one more thing

TERMINOLOGY ALERT!!!!

"Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL the
fields in a particular form."

Regardless of what a lot of Microsoft documentation says, in true database
terminology, there are no field on a form. The form's recordset has fields,
but the form itself only has controls. A text box is a control, a combo box
is a control, etc.



Public Function LockBoundControls(ByVal frm As Form, bLock As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form any
its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to lock
(variant array of strings).
'Usage: Call LockBoundControls(Me. True)

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
'Block deletions.
frm.AllowDeletions = Not bLock

For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox,
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") Then
If Len(ctl.ControlSource) 0 And Not ctl.ControlSource
Like "=*" Then
If ctl.Locked bLock Then
ctl.Locked = bLock
End If
End If
End If
End If

Case acSubform
'Recursive call to handle all subforms.
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 Len(Nz(ctl.SourceObject, vbNullString)) 0 Then
ctl.Form.AllowDeletions = Not bLock
ctl.Form.AllowAdditions = Not bLock
Call LockBoundControls(ctl.Form, bLock)
End If
End If

Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
'Do nothing

Case Else
'Includes acBoundObjectFrame, acCustomControl
Debug.Print ctl.Name & " not handled " & Now()
End Select
Next

'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
frm!rctLock.Visible = bLock


Exit_Handler:
Set ctl = Nothing
Exit Function

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
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


" wrote:

Hi,

Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL
the fields in a particular form. (It would be bonus if anyone could
tell me how to get rid of data showing up in disabled fields. I want
disabled fields to show no data until they "come to life" after a value
is chosen from the combobox)

I have played around with setting each individ field to visible=false
and then visible = true with "After Update" in combo box and this works
fine but I want to know if there is a quick way to set it such that in
one quick swoop, you can enable "disabled" fields after a combobox
selection...there has to be some code out there...like
Forms![Form_Name].fields.all.enabled=true...I tried this, didn't work.

I want to avoid having to code for each individ. field. every time one
has to be added at a later date.

Thx.
S


  #4  
Old December 21st, 2006, 04:26 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 32
Default Want to enable fields after combox selection

Hello,

I will try this and get back to you. I have a feeling I will have
questions so please stay with...

Thx.

Sargum

NthDegree via AccessMonster.com wrote:
You could do something like this:
The Case statement will specify the various types of controls found on the
form that could contain data.
The control "cboSelectionBox" is the combo box that you want to control the
other fields.
This statement /If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.Name)
= ""/ could be used to clear the field if it was in a disabled state.

You could run this code from the combo box "After Update" action to enable
the fields and in the forms "On Open" action to disable them.

For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox, acOptionGroup, acCheckBox
If ctl.Name = "cboSelectionBox" Then
' do nothing
Else
Me.Controls(ctl.Name).Enabled (or Disabled)
' If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.
Name) = ""
End If
End Select
End With
Next ctl

wrote:
Hi,

Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL
the fields in a particular form. (It would be bonus if anyone could
tell me how to get rid of data showing up in disabled fields. I want
disabled fields to show no data until they "come to life" after a value
is chosen from the combobox)

I have played around with setting each individ field to visible=false
and then visible = true with "After Update" in combo box and this works
fine but I want to know if there is a quick way to set it such that in
one quick swoop, you can enable "disabled" fields after a combobox
selection...there has to be some code out there...like
Forms![Form_Name].fields.all.enabled=true...I tried this, didn't work.

I want to avoid having to code for each individ. field. every time one
has to be added at a later date.

Thx.
S


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1


  #5  
Old December 21st, 2006, 05:14 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Want to enable fields after combox selection

Yesterday I said I might try doing the hide the text part of your request.
Well, here it is. The only problem is with Check Boxes. They don't have
forecolor or backcolor properties, so making the text and back color the same
wont work. I thought about Unchecking and rechecking, but that is changing
data in the current record which may not be desireable.

BTW, the code I sent yesterday was originally written by Allen Browne. If
you paste all 3 of the functions (2 from yesterday, 1 today) into a standard
module, you can call it from any form.

'---------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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

On Error GoTo HideFormText_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

HideFormText_Exit:

On Error Resume Next
Exit Function

HideFormText_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit

End Function


" wrote:

Hello,

I will try this and get back to you. I have a feeling I will have
questions so please stay with...

Thx.

Sargum

NthDegree via AccessMonster.com wrote:
You could do something like this:
The Case statement will specify the various types of controls found on the
form that could contain data.
The control "cboSelectionBox" is the combo box that you want to control the
other fields.
This statement /If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.Name)
= ""/ could be used to clear the field if it was in a disabled state.

You could run this code from the combo box "After Update" action to enable
the fields and in the forms "On Open" action to disable them.

For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox, acOptionGroup, acCheckBox
If ctl.Name = "cboSelectionBox" Then
' do nothing
Else
Me.Controls(ctl.Name).Enabled (or Disabled)
' If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.
Name) = ""
End If
End Select
End With
Next ctl

wrote:
Hi,

Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL
the fields in a particular form. (It would be bonus if anyone could
tell me how to get rid of data showing up in disabled fields. I want
disabled fields to show no data until they "come to life" after a value
is chosen from the combobox)

I have played around with setting each individ field to visible=false
and then visible = true with "After Update" in combo box and this works
fine but I want to know if there is a quick way to set it such that in
one quick swoop, you can enable "disabled" fields after a combobox
selection...there has to be some code out there...like
Forms![Form_Name].fields.all.enabled=true...I tried this, didn't work.

I want to avoid having to code for each individ. field. every time one
has to be added at a later date.

Thx.
S


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1



  #6  
Old January 2nd, 2007, 03:33 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 32
Default Want to enable fields after combox selection

Hi Klatuu,

Thank you for your help thus far. This is more than I hoped for and
all very useful. I pasted the following (all three code excerpts) into
a Module but am having trouble calling it from my Form. When I open my
Form, I see no changes. I even tried just havign the 'Hide Form Text'
code to see if that worked by itself alone but no luck. Any ideas? Is
there something special I need to do to "call" the module from my Form
which has many associated subforms?

Public Function LockBoundControls(ByVal frm As Form, bLock As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to
lock(variant array of strings).
'Usage: Call LockBoundControls(Me. True)


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
'Block deletions.
frm.AllowDeletions = Not bLock


For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox, 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") Then
If Len(ctl.ControlSource) 0 And Not
ctl.ControlSource Like "=*" Then
If ctl.Locked bLock Then
ctl.Locked = bLock
End If
End If
End If
End If


Case acSubform
'Recursive call to handle all subforms.
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 Len(Nz(ctl.SourceObject, vbNullString)) 0 Then
ctl.Form.AllowDeletions = Not bLock
ctl.Form.AllowAdditions = Not bLock
Call LockBoundControls(ctl.Form, bLock)
End If
End If


Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
'Do nothing


Case Else
'Includes acBoundObjectFrame, acCustomControl
Debug.Print ctl.Name & " not handled " & Now()
End Select
Next


'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
frm!rctLock.Visible = bLock


Exit_Handler:
Set ctl = Nothing
Exit Function


Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
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


'--------------------------------------------------------------------------*-------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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


On Error GoTo HideFormText_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


HideFormText_Exit:


On Error Resume Next
Exit Function


HideFormText_Error:


MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit


End Function



Thx.
Sargum


Klatuu wrote:
Yesterday I said I might try doing the hide the text part of your request.
Well, here it is. The only problem is with Check Boxes. They don't have
forecolor or backcolor properties, so making the text and back color the same
wont work. I thought about Unchecking and rechecking, but that is changing
data in the current record which may not be desireable.

BTW, the code I sent yesterday was originally written by Allen Browne. If
you paste all 3 of the functions (2 from yesterday, 1 today) into a standard
module, you can call it from any form.

'---------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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

On Error GoTo HideFormText_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

HideFormText_Exit:

On Error Resume Next
Exit Function

HideFormText_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit

End Function


" wrote:

Hello,

I will try this and get back to you. I have a feeling I will have
questions so please stay with...

Thx.

Sargum

NthDegree via AccessMonster.com wrote:
You could do something like this:
The Case statement will specify the various types of controls found on the
form that could contain data.
The control "cboSelectionBox" is the combo box that you want to control the
other fields.
This statement /If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.Name)
= ""/ could be used to clear the field if it was in a disabled state.

You could run this code from the combo box "After Update" action to enable
the fields and in the forms "On Open" action to disable them.

For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case acTextBox, acComboBox, acOptionGroup, acCheckBox
If ctl.Name = "cboSelectionBox" Then
' do nothing
Else
Me.Controls(ctl.Name).Enabled (or Disabled)
' If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.
Name) = ""
End If
End Select
End With
Next ctl

wrote:
Hi,

Is there a way to enable ALL fields in a form only after a combo box
selection? I am not worried about enabling/diabling controls, only ALL
the fields in a particular form. (It would be bonus if anyone could
tell me how to get rid of data showing up in disabled fields. I want
disabled fields to show no data until they "come to life" after a value
is chosen from the combobox)

I have played around with setting each individ field to visible=false
and then visible = true with "After Update" in combo box and this works
fine but I want to know if there is a quick way to set it such that in
one quick swoop, you can enable "disabled" fields after a combobox
selection...there has to be some code out there...like
Forms![Form_Name].fields.all.enabled=true...I tried this, didn't work.

I want to avoid having to code for each individ. field. every time one
has to be added at a later date.

Thx.
S

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1




  #7  
Old January 2nd, 2007, 04:29 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Want to enable fields after combox selection

I don't know how you are calling it. I might suggest the Current event of
your form. It will not affect any subforms. You will have to call it form
each form.

Here is an example of hiding the text:
HideFormText(Me, False)


" wrote:

Hi Klatuu,

Thank you for your help thus far. This is more than I hoped for and
all very useful. I pasted the following (all three code excerpts) into
a Module but am having trouble calling it from my Form. When I open my
Form, I see no changes. I even tried just havign the 'Hide Form Text'
code to see if that worked by itself alone but no luck. Any ideas? Is
there something special I need to do to "call" the module from my Form
which has many associated subforms?

Public Function LockBoundControls(ByVal frm As Form, bLock As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to
lock(variant array of strings).
'Usage: Call LockBoundControls(Me. True)


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
'Block deletions.
frm.AllowDeletions = Not bLock


For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox, 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") Then
If Len(ctl.ControlSource) 0 And Not
ctl.ControlSource Like "=*" Then
If ctl.Locked bLock Then
ctl.Locked = bLock
End If
End If
End If
End If


Case acSubform
'Recursive call to handle all subforms.
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 Len(Nz(ctl.SourceObject, vbNullString)) 0 Then
ctl.Form.AllowDeletions = Not bLock
ctl.Form.AllowAdditions = Not bLock
Call LockBoundControls(ctl.Form, bLock)
End If
End If


Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
'Do nothing


Case Else
'Includes acBoundObjectFrame, acCustomControl
Debug.Print ctl.Name & " not handled " & Now()
End Select
Next


'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
frm!rctLock.Visible = bLock


Exit_Handler:
Set ctl = Nothing
Exit Function


Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
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


'----------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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


On Error GoTo HideFormText_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


HideFormText_Exit:


On Error Resume Next
Exit Function


HideFormText_Error:


MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit


End Function



Thx.
Sargum


Klatuu wrote:
Yesterday I said I might try doing the hide the text part of your request.
Well, here it is. The only problem is with Check Boxes. They don't have
forecolor or backcolor properties, so making the text and back color the same
wont work. I thought about Unchecking and rechecking, but that is changing
data in the current record which may not be desireable.

BTW, the code I sent yesterday was originally written by Allen Browne. If
you paste all 3 of the functions (2 from yesterday, 1 today) into a standard
module, you can call it from any form.

'---------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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

On Error GoTo HideFormText_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

HideFormText_Exit:

On Error Resume Next
Exit Function

HideFormText_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit

End Function


" wrote:

Hello,

I will try this and get back to you. I have a feeling I will have
questions so please stay with...

Thx.

Sargum

NthDegree via AccessMonster.com wrote:
You could do something like this:
The Case statement will specify the various types of controls found on the
form that could contain data.
The control "cboSelectionBox" is the combo box that you want to control the
other fields.
This statement /If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.Name)
= ""/ could be used to clear the field if it was in a disabled state.

  #8  
Old January 3rd, 2007, 03:53 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 32
Default Want to enable fields after combox selection

Hi Klatuu,

I pasted only the HideFormText code in a regular Module (not class
Module) and then called it from the OnCurrent on the form using a
Macro.

The Action in the Macro is 'RunCode' and the Action Argument has a
'Function Name' called HideFormText («frm», «blnShow»,
«avarExceptionList»).

When I open the form, I get an error
"The object doesn't contain the Automation object 'frm." You tried
to run a Visual Basic procedure to set a property or method for an
object. However, the component doesn't make the property or method
availble for Automation operations."

I also tried the HideFormText without the double arrows "" (i.e.
(frm, blnShow, avarExceptionList) for the 'Function Name' and got the
same error.

Thoughts?

Sargum

Klatuu wrote:
I don't know how you are calling it. I might suggest the Current event of
your form. It will not affect any subforms. You will have to call it form
each form.

Here is an example of hiding the text:
HideFormText(Me, False)


" wrote:

Hi Klatuu,

Thank you for your help thus far. This is more than I hoped for and
all very useful. I pasted the following (all three code excerpts) into
a Module but am having trouble calling it from my Form. When I open my
Form, I see no changes. I even tried just havign the 'Hide Form Text'
code to see if that worked by itself alone but no luck. Any ideas? Is
there something special I need to do to "call" the module from my Form
which has many associated subforms?

Public Function LockBoundControls(ByVal frm As Form, bLock As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to
lock(variant array of strings).
'Usage: Call LockBoundControls(Me. True)


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
'Block deletions.
frm.AllowDeletions = Not bLock


For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox, 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") Then
If Len(ctl.ControlSource) 0 And Not
ctl.ControlSource Like "=*" Then
If ctl.Locked bLock Then
ctl.Locked = bLock
End If
End If
End If
End If


Case acSubform
'Recursive call to handle all subforms.
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 Len(Nz(ctl.SourceObject, vbNullString)) 0 Then
ctl.Form.AllowDeletions = Not bLock
ctl.Form.AllowAdditions = Not bLock
Call LockBoundControls(ctl.Form, bLock)
End If
End If


Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
'Do nothing


Case Else
'Includes acBoundObjectFrame, acCustomControl
Debug.Print ctl.Name & " not handled " & Now()
End Select
Next


'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
frm!rctLock.Visible = bLock


Exit_Handler:
Set ctl = Nothing
Exit Function


Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
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


'----------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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


On Error GoTo HideFormText_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


HideFormText_Exit:


On Error Resume Next
Exit Function


HideFormText_Error:


MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit


End Function



Thx.
Sargum


Klatuu wrote:
Yesterday I said I might try doing the hide the text part of your request.
Well, here it is. The only problem is with Check Boxes. They don't have
forecolor or backcolor properties, so making the text and back color the same
wont work. I thought about Unchecking and rechecking, but that is changing
data in the current record which may not be desireable.

BTW, the code I sent yesterday was originally written by Allen Browne.. If
you paste all 3 of the functions (2 from yesterday, 1 today) into a standard
module, you can call it from any form.

'---------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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

On Error GoTo HideFormText_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

HideFormText_Exit:

On Error Resume Next
Exit Function

HideFormText_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit

End Function


" wrote:

Hello,

I will try this and get back to you. I have a feeling I will have
questions so please stay with...

Thx.

Sargum

NthDegree via AccessMonster.com wrote:
You could do something like this:
The Case statement will specify the various types of controls found on the
form that could contain data.
The control "cboSelectionBox" is the combo box that you want to control the
other fields.
This statement /If Me.Controls(ctl.Name).Disabled then Me.Controls(ctl.Name)
= ""/ could be used to clear the field if it was in a disabled state.


  #9  
Old January 3rd, 2007, 05:35 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Want to enable fields after combox selection

There should be no macro involved.
A standard module is the correct place to put the code, but be sure the name
of the module is not the same as the function.
Call the function directly from the current event. It needs to be coded in
the form's module, not directly in the OnCurrent event box.
--
Dave Hargis, Microsoft Access MVP


" wrote:

Hi Klatuu,

I pasted only the HideFormText code in a regular Module (not class
Module) and then called it from the OnCurrent on the form using a
Macro.

The Action in the Macro is 'RunCode' and the Action Argument has a
'Function Name' called HideFormText (+frm;, +blnShow;,
+avarExceptionList.

When I open the form, I get an error
"The object doesn't contain the Automation object 'frm." You tried
to run a Visual Basic procedure to set a property or method for an
object. However, the component doesn't make the property or method
availble for Automation operations."

I also tried the HideFormText without the double arrows "" (i.e.
(frm, blnShow, avarExceptionList) for the 'Function Name' and got the
same error.

Thoughts?

Sargum

Klatuu wrote:
I don't know how you are calling it. I might suggest the Current event of
your form. It will not affect any subforms. You will have to call it form
each form.

Here is an example of hiding the text:
HideFormText(Me, False)


" wrote:

Hi Klatuu,

Thank you for your help thus far. This is more than I hoped for and
all very useful. I pasted the following (all three code excerpts) into
a Module but am having trouble calling it from my Form. When I open my
Form, I see no changes. I even tried just havign the 'Hide Form Text'
code to see if that worked by itself alone but no luck. Any ideas? Is
there something special I need to do to "call" the module from my Form
which has many associated subforms?

Public Function LockBoundControls(ByVal frm As Form, bLock As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to
lock(variant array of strings).
'Usage: Call LockBoundControls(Me. True)


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
'Block deletions.
frm.AllowDeletions = Not bLock


For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox, 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") Then
If Len(ctl.ControlSource) 0 And Not
ctl.ControlSource Like "=*" Then
If ctl.Locked bLock Then
ctl.Locked = bLock
End If
End If
End If
End If


Case acSubform
'Recursive call to handle all subforms.
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 Len(Nz(ctl.SourceObject, vbNullString)) 0 Then
ctl.Form.AllowDeletions = Not bLock
ctl.Form.AllowAdditions = Not bLock
Call LockBoundControls(ctl.Form, bLock)
End If
End If


Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
'Do nothing


Case Else
'Includes acBoundObjectFrame, acCustomControl
Debug.Print ctl.Name & " not handled " & Now()
End Select
Next


'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
frm!rctLock.Visible = bLock


Exit_Handler:
Set ctl = Nothing
Exit Function


Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
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


'----------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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


On Error GoTo HideFormText_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


HideFormText_Exit:


On Error Resume Next
Exit Function


HideFormText_Error:


MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit


End Function



Thx.
Sargum


Klatuu wrote:
Yesterday I said I might try doing the hide the text part of your request.
Well, here it is. The only problem is with Check Boxes. They don't have
forecolor or backcolor properties, so making the text and back color the same
wont work. I thought about Unchecking and rechecking, but that is changing
data in the current record which may not be desireable.

BTW, the code I sent yesterday was originally written by Allen Browne.. If
you paste all 3 of the functions (2 from yesterday, 1 today) into a standard
module, you can call it from any form.

'---------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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

On Error GoTo HideFormText_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

  #10  
Old January 4th, 2007, 02:58 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 32
Default Want to enable fields after combox selection

Hi,

To clarify, the standard module is not named the same as the function.

I have created the standard modules (called it Module1) in Modules
under Objects in the Database window. I don't understand how to call
it from the form unless I put it in the OnCurrent event box on this
form. Since I am having trouble with this, can someone lay out, step
by step, what I need to do to call Module1 from my form? What is the
current event if it is not the ONCurrent box found in the form's
property??

S

Klatuu wrote:
There should be no macro involved.
A standard module is the correct place to put the code, but be sure the name
of the module is not the same as the function.
Call the function directly from the current event. It needs to be coded in
the form's module, not directly in the OnCurrent event box.
--
Dave Hargis, Microsoft Access MVP


" wrote:

Hi Klatuu,

I pasted only the HideFormText code in a regular Module (not class
Module) and then called it from the OnCurrent on the form using a
Macro.

The Action in the Macro is 'RunCode' and the Action Argument has a
'Function Name' called HideFormText (+frm;, +blnShow;,
+avarExceptionList.

When I open the form, I get an error
"The object doesn't contain the Automation object 'frm." You tried
to run a Visual Basic procedure to set a property or method for an
object. However, the component doesn't make the property or method
availble for Automation operations."

I also tried the HideFormText without the double arrows "" (i.e.
(frm, blnShow, avarExceptionList) for the 'Function Name' and got the
same error.

Thoughts?

Sargum

Klatuu wrote:
I don't know how you are calling it. I might suggest the Current event of
your form. It will not affect any subforms. You will have to call it form
each form.

Here is an example of hiding the text:
HideFormText(Me, False)


" wrote:

Hi Klatuu,

Thank you for your help thus far. This is more than I hoped for and
all very useful. I pasted the following (all three code excerpts) into
a Module but am having trouble calling it from my Form. When I open my
Form, I see no changes. I even tried just havign the 'Hide Form Text'
code to see if that worked by itself alone but no luck. Any ideas? Is
there something special I need to do to "call" the module from my Form
which has many associated subforms?

Public Function LockBoundControls(ByVal frm As Form, bLock As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose: Lock the bound controls and prevent deletes on the form
any its subforms.
'Arguments frm = the form to be locked
' bLock = True to lock, False to unlock.
' avarExceptionList: Names of the controls NOT to
lock(variant array of strings).
'Usage: Call LockBoundControls(Me. True)


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
'Block deletions.
frm.AllowDeletions = Not bLock


For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acOptionGroup,
acCheckBox, 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") Then
If Len(ctl.ControlSource) 0 And Not
ctl.ControlSource Like "=*" Then
If ctl.Locked bLock Then
ctl.Locked = bLock
End If
End If
End If
End If


Case acSubform
'Recursive call to handle all subforms.
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 Len(Nz(ctl.SourceObject, vbNullString)) 0 Then
ctl.Form.AllowDeletions = Not bLock
ctl.Form.AllowAdditions = Not bLock
Call LockBoundControls(ctl.Form, bLock)
End If
End If


Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
'Do nothing


Case Else
'Includes acBoundObjectFrame, acCustomControl
Debug.Print ctl.Name & " not handled " & Now()
End Select
Next


'Set the visual indicators on the form.
On Error Resume Next
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
frm!rctLock.Visible = bLock


Exit_Handler:
Set ctl = Nothing
Exit Function


Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
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


'----------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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


On Error GoTo HideFormText_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


HideFormText_Exit:


On Error Resume Next
Exit Function


HideFormText_Error:


MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure HideFormText of Module modFormOperations"
GoTo HideFormText_Exit


End Function



Thx.
Sargum


Klatuu wrote:
Yesterday I said I might try doing the hide the text part of your request.
Well, here it is. The only problem is with Check Boxes. They don't have
forecolor or backcolor properties, so making the text and back color the same
wont work. I thought about Unchecking and rechecking, but that is changing
data in the current record which may not be desireable.

BTW, the code I sent yesterday was originally written by Allen Browne.. If
you paste all 3 of the functions (2 from yesterday, 1 today) into a standard
module, you can call it from any form.

'---------------------------------------------------------------------------------------
' Procedure : HideFormText
' 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 HideFormText(ByVal 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

On Error GoTo HideFormText_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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.