Locking controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code in my CurrentEvent procedure of my form. This locks
all the controls when a date is filled into the "txtDateClosed" control. This
also locks my command buttons. How do I keep the command buttons unlocked no
matter the state of this code?

If IsNull([txtDateClosed]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If
 
Secret Squirrel ha scritto:
I have the following code in my CurrentEvent procedure of my form. This locks
all the controls when a date is filled into the "txtDateClosed" control. This
also locks my command buttons. How do I keep the command buttons unlocked no
matter the state of this code?

If IsNull([txtDateClosed]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If


May be this way...?

On Current

Call LookState(Me,IsNull([txtDateClosed]))


Private Function LookState(frm as Access.Form, state as Boolean)
Dim ctl as Access.Control
For each ctl in frm.controls
Select case ctl.Controltype
Case acTextBox, acListBox, acComboBox,
acOptionButton, acOptionGroup
ctl.looked=state
case acSubForm
LookState ctl.Form,state
End Select
Next
End Function

@Alex
 
Hi,
I'm getting a run-time error "438". The ctl.looked = state is erroring out.
Should I try something else?

Alessandro Baraldi said:
Secret Squirrel ha scritto:
I have the following code in my CurrentEvent procedure of my form. This locks
all the controls when a date is filled into the "txtDateClosed" control. This
also locks my command buttons. How do I keep the command buttons unlocked no
matter the state of this code?

If IsNull([txtDateClosed]) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If


May be this way...?

On Current

Call LookState(Me,IsNull([txtDateClosed]))


Private Function LookState(frm as Access.Form, state as Boolean)
Dim ctl as Access.Control
For each ctl in frm.controls
Select case ctl.Controltype
Case acTextBox, acListBox, acComboBox,
acOptionButton, acOptionGroup
ctl.looked=state
case acSubForm
LookState ctl.Form,state
End Select
Next
End Function

@Alex
 
I don't have Access in front of me, so I haven't tested it, but I think
this should work

In the event that you want to use to trigger the fields locking:

LookState(Me, Not IsNull([txtDateClosed]))

In the form module:

Private Function LookState(frm as Access.Form, state as Boolean)
Dim ctl as Access.Control
For each ctl in frm.controls
Select case ctl.Controltype
Case acTextBox, acListBox, acComboBox,acOptionButton,
acOptionGroup
ctl.locked = state
End Select
Next
End Function
 
Thanks Keven! That worked perfectly! It leaves my comman button unlocked no
matter what but locks everything else. Thanks again!
 
Actually I have one follow up question. I had a command button on my form
that I used to "AllowEdits" to the form even when there was a date in the
"txtDateClosed" field. What it does was unlock that record for updating but
once you close that record it locks it back up again. How can I modify my
existing code to compliment your code so users can click the button to make
edits?
 
(e-mail address removed) ha scritto:
I don't have Access in front of me, so I haven't tested it, but I think
this should work

In the event that you want to use to trigger the fields locking:

LookState(Me, Not IsNull([txtDateClosed]))

In the form module:

Private Function LookState(frm as Access.Form, state as Boolean)
Dim ctl as Access.Control
For each ctl in frm.controls
Select case ctl.Controltype
Case acTextBox, acListBox, acComboBox,acOptionButton,
acOptionGroup
ctl.locked = state
End Select
Next
End Function

Ops NOT on control state.....
Yes like this is good.

On the First Case you need to add all controlType that need of test....

@Alex
 
(e-mail address removed) ha scritto:
What event did you put the LookState(Me, Not IsNull([txtDateClosed]))
in?

This function must be called each time you change record to Look all
controls, so
i know only one Event that can do this....

Private Sub Form_Current()
If not Me.NewRecord then LookState(Me, Not IsNull([txtDateClosed]))
End Sub

Bye

@Alex
 
How can I modify my existing code to compliment your code so users can click the button to make edits?

The easiest way to do that would be:

For the OnClick event of the button:

Dim Ctrl as Access.Control
For each ctl in frm.controls
Ctrl.Locked = False
Next
 
Back
Top