Enabled = NO | Locked = YES

J

JK

I'm using Access 03' and in the past, when I've made fields Enabled = no and
locked = yes the field was not grayed out when I viewed the form in live
mode. For some reason, when I set the aforementioned settings, the fields are
grayed out. How do fix this? I want to lock certain fields (text boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 
G

Gina Whipp

JK,

As far as I know that still works... so the first place I would look is any
code that is behind the form to see if you are changing any properties
there. I would also try a Compact & Repair. If all that fails, try
creating a new form and seeing if you can set the fields on it. If that
works your form might have become corrupt and you would need to recreate the
form and delete the old one.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
C

CrazyAccessProgrammer

This happens to me sometimes and typically it's because some other code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state of the
Enabled and Locked properites of your MyCheckControl control. (MyCheckControl
obviously is the control on your form, you should use its name in place of
MyCheckControl)

If you find that the values dictate your control should be grayed out, you
can start searching for the code that is changing the locked or enabled
properties to resolve your problem. If not, then it's something else.
 
J

JK

When I do what you're suggesting, and while the field in question is set to
Enabled = NO and Locked = YES, this is what I get.

Your example.Enabled = 0
Your example.Locked = 0

If I set the field to Enabled = YES and Locked = NO, this is what I get.

Your example.Enabled = -1
Your example.Locked = 0

I don't have any code behind the form messing with any locked or enabled
properties except a few command buttons (example: Me.cmdAddNew.Enabled = True)

This is driving me nutty.

Thx for your help.

Jason




CrazyAccessProgrammer said:
This happens to me sometimes and typically it's because some other code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state of the
Enabled and Locked properites of your MyCheckControl control. (MyCheckControl
obviously is the control on your form, you should use its name in place of
MyCheckControl)

If you find that the values dictate your control should be grayed out, you
can start searching for the code that is changing the locked or enabled
properties to resolve your problem. If not, then it's something else.


JK said:
I'm using Access 03' and in the past, when I've made fields Enabled = no and
locked = yes the field was not grayed out when I viewed the form in live
mode. For some reason, when I set the aforementioned settings, the fields are
grayed out. How do fix this? I want to lock certain fields (text boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 
J

JK

If on the On-Open Event I put this:

Me.cboAddress.Enabled = False
Me.cboAddress.Locked = True

The field is not grayed out; it works the way it should.
I don't get this at all...

Jason

CrazyAccessProgrammer said:
This happens to me sometimes and typically it's because some other code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state of the
Enabled and Locked properites of your MyCheckControl control. (MyCheckControl
obviously is the control on your form, you should use its name in place of
MyCheckControl)

If you find that the values dictate your control should be grayed out, you
can start searching for the code that is changing the locked or enabled
properties to resolve your problem. If not, then it's something else.


JK said:
I'm using Access 03' and in the past, when I've made fields Enabled = no and
locked = yes the field was not grayed out when I viewed the form in live
mode. For some reason, when I set the aforementioned settings, the fields are
grayed out. How do fix this? I want to lock certain fields (text boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 
C

CrazyAccessProgrammer

Your situation is starting to sound like there is some weirdness going on.
After I try a few logical things and still experience weirdness, what I
usually do is is start a brand new database and create a brand new form and
try the thing I think should be working.

If it does work with a brand new database and brand new form then it means
you may have corruption with your real database or an object in that database.

What you are trying to do, setting a control's enabled property to false and
locked property to true SHOULD result with the control NOT being greyed out
and as I type this message I have done this on a form in a database and it is
working properly.

JK said:
If on the On-Open Event I put this:

Me.cboAddress.Enabled = False
Me.cboAddress.Locked = True

The field is not grayed out; it works the way it should.
I don't get this at all...

Jason

CrazyAccessProgrammer said:
This happens to me sometimes and typically it's because some other code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state of the
Enabled and Locked properites of your MyCheckControl control. (MyCheckControl
obviously is the control on your form, you should use its name in place of
MyCheckControl)

If you find that the values dictate your control should be grayed out, you
can start searching for the code that is changing the locked or enabled
properties to resolve your problem. If not, then it's something else.


JK said:
I'm using Access 03' and in the past, when I've made fields Enabled = no and
locked = yes the field was not grayed out when I viewed the form in live
mode. For some reason, when I set the aforementioned settings, the fields are
grayed out. How do fix this? I want to lock certain fields (text boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 
J

JK

I've identified the problem. I don't remember where I got the following code
but it's used to date stamp records when they've been entered or altered. In
the OnCurrent Event, I have the following:

'Record Locking Feature
Call LockControls(Me, True)

If I remove that line, the enabled and locked features work as intended.
However, I've used this in the past without a problem - not sure what has
changed.

Public Function LockControls(frm As Form, bSetBorderColor As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose:
Dim rsClone As DAO.Recordset 'RecordsetClone of form.
Dim ctl As Control 'Each control on form.
Dim bLock As Boolean 'Flag to lock control.
Dim lngFldPrp As Long 'Value of custom property.
Dim strEnteredBy As String 'User who entered the record.
Dim dtEnteredOn As Date 'Date/Time the record was entered.
Dim strControl As String 'Name of control.
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean 'Flag to skip setting this control.
Dim bAllow As Boolean 'Flag to allow edits in this control.

Set rsClone = frm.RecordsetClone 'This fails if form is unbound.
'Get the user who created the record, and the date it was entered/updated.
Call GetUserAndDate4Record(frm, strEnteredBy, dtEnteredOn)

For Each ctl In frm.Controls
Select Case ctl.ControlType 'Skip the control if it is one of
these types
Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
bSkip = True
Case Else 'Otherwise initialize to process the
control if it has a Locked property.
If HasProperty(ctl, "Locked") Then
bSkip = False
Else
bSkip = True
End If
End Select

'Check if it is one of the names we want to skip, or one of the
names in the exception list.
If Not bSkip Then
strControl = ctl.Name
Select Case strControl
Case "EnteredOn", "EnteredBy", "UpdatedOn", "UpdatedBy",
"InactiveOn", "InactiveBy"
bSkip = True
Case Else
For lngI = LBound(avarExceptionList()) To
UBound(avarExceptionList())
If strControl = avarExceptionList(lngI) Then
bSkip = True
Exit For
End If
Next
End Select
End If

'Permit everything on a new record, other than the exceptions.
If Not bSkip Then
If frm.NewRecord Then
bAllow = True
End If
End If

'Get the user-defined attribute for the field this control is bound
to.
If Not (bSkip Or bAllow) Then
lngFldPrp = GetAttribUser(ctl, rsClone)
If lngFldPrp = -1& Then 'Skip if error.
bSkip = True
End If
End If

'Decide whether the control should be locked.
If Not bSkip Then
bLock = False 'Initialize to permit editing.
If Not (bAllow Or (lngFldPrp = uBlockNothing)) Then 'Allow
everything if zero.
'Block all?
If (lngFldPrp And uBlockAll) <> 0& Then
bLock = True
End If
'Block if record is more than 1 hour old?
If ((lngFldPrp And uBlockExcept1hr) <> 0&) And (dtEnteredOn
<> conNoDate) And (Not bLock) Then
If DateDiff("n", dtEnteredOn, Now()) > 60& Then
bLock = True
End If
End If
'Block if different user?
If ((lngFldPrp And uBlockExceptSameUser) <> 0&) And
(strEnteredBy <> vbNullString) And (Not bLock) Then
If strEnteredBy <> NetworkUserName() Then
bLock = True
End If
End If
End If

'Set the control's Locked property (unless already set correctly.)
If ctl.Locked <> bLock Then
ctl.Locked = bLock
If bSetBorderColor Then 'Set the border color if we were
asked to do that.
ctl.BorderColor = IIf(bLock, conBorderLocked,
conBorderNormal)
End If
End If
End If
Next

Exit_Handler:
Set rsClone = Nothing
Exit Function

Err_Handler:
If Err.Number <> 7951& Then 'Form is unbound (so no
RecordsetClone)
Call LogError(Err.Number, Err.Description, conMod & ".LockControls")
End If
Resume Exit_Handler
End Function

CrazyAccessProgrammer said:
Your situation is starting to sound like there is some weirdness going on.
After I try a few logical things and still experience weirdness, what I
usually do is is start a brand new database and create a brand new form and
try the thing I think should be working.

If it does work with a brand new database and brand new form then it means
you may have corruption with your real database or an object in that database.

What you are trying to do, setting a control's enabled property to false and
locked property to true SHOULD result with the control NOT being greyed out
and as I type this message I have done this on a form in a database and it is
working properly.

JK said:
If on the On-Open Event I put this:

Me.cboAddress.Enabled = False
Me.cboAddress.Locked = True

The field is not grayed out; it works the way it should.
I don't get this at all...

Jason

CrazyAccessProgrammer said:
This happens to me sometimes and typically it's because some other code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state of the
Enabled and Locked properites of your MyCheckControl control. (MyCheckControl
obviously is the control on your form, you should use its name in place of
MyCheckControl)

If you find that the values dictate your control should be grayed out, you
can start searching for the code that is changing the locked or enabled
properties to resolve your problem. If not, then it's something else.


:

I'm using Access 03' and in the past, when I've made fields Enabled = no and
locked = yes the field was not grayed out when I viewed the form in live
mode. For some reason, when I set the aforementioned settings, the fields are
grayed out. How do fix this? I want to lock certain fields (text boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 
D

dymondjack

I don't remember where I got the following code

This looks very similar to Allen Browne's example of locking/unlocking
controls
http://allenbrowne.com/ser-56.html

The code below has obviously been modified, and now seems to be a function
that does two different things: timestamps and locking controls. Why, I
have no idea. I can't see any reason for these two to be 'merged' like this.

I use Allen's LockBoundControls function a lot in my db, and like it because
of the fact that they are not 'greyed' when locked.

I'm not sure why this version you have is created havoc with your settings,
but I would consider putting the timestamps into a separate function... it
appears that the function you call from OnCurrent was written for something
else entirely.

My 2pennies



--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain


JK said:
I've identified the problem. I don't remember where I got the following code
but it's used to date stamp records when they've been entered or altered. In
the OnCurrent Event, I have the following:

'Record Locking Feature
Call LockControls(Me, True)

If I remove that line, the enabled and locked features work as intended.
However, I've used this in the past without a problem - not sure what has
changed.

Public Function LockControls(frm As Form, bSetBorderColor As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose:
Dim rsClone As DAO.Recordset 'RecordsetClone of form.
Dim ctl As Control 'Each control on form.
Dim bLock As Boolean 'Flag to lock control.
Dim lngFldPrp As Long 'Value of custom property.
Dim strEnteredBy As String 'User who entered the record.
Dim dtEnteredOn As Date 'Date/Time the record was entered.
Dim strControl As String 'Name of control.
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean 'Flag to skip setting this control.
Dim bAllow As Boolean 'Flag to allow edits in this control.

Set rsClone = frm.RecordsetClone 'This fails if form is unbound.
'Get the user who created the record, and the date it was entered/updated.
Call GetUserAndDate4Record(frm, strEnteredBy, dtEnteredOn)

For Each ctl In frm.Controls
Select Case ctl.ControlType 'Skip the control if it is one of
these types
Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
bSkip = True
Case Else 'Otherwise initialize to process the
control if it has a Locked property.
If HasProperty(ctl, "Locked") Then
bSkip = False
Else
bSkip = True
End If
End Select

'Check if it is one of the names we want to skip, or one of the
names in the exception list.
If Not bSkip Then
strControl = ctl.Name
Select Case strControl
Case "EnteredOn", "EnteredBy", "UpdatedOn", "UpdatedBy",
"InactiveOn", "InactiveBy"
bSkip = True
Case Else
For lngI = LBound(avarExceptionList()) To
UBound(avarExceptionList())
If strControl = avarExceptionList(lngI) Then
bSkip = True
Exit For
End If
Next
End Select
End If

'Permit everything on a new record, other than the exceptions.
If Not bSkip Then
If frm.NewRecord Then
bAllow = True
End If
End If

'Get the user-defined attribute for the field this control is bound
to.
If Not (bSkip Or bAllow) Then
lngFldPrp = GetAttribUser(ctl, rsClone)
If lngFldPrp = -1& Then 'Skip if error.
bSkip = True
End If
End If

'Decide whether the control should be locked.
If Not bSkip Then
bLock = False 'Initialize to permit editing.
If Not (bAllow Or (lngFldPrp = uBlockNothing)) Then 'Allow
everything if zero.
'Block all?
If (lngFldPrp And uBlockAll) <> 0& Then
bLock = True
End If
'Block if record is more than 1 hour old?
If ((lngFldPrp And uBlockExcept1hr) <> 0&) And (dtEnteredOn
<> conNoDate) And (Not bLock) Then
If DateDiff("n", dtEnteredOn, Now()) > 60& Then
bLock = True
End If
End If
'Block if different user?
If ((lngFldPrp And uBlockExceptSameUser) <> 0&) And
(strEnteredBy <> vbNullString) And (Not bLock) Then
If strEnteredBy <> NetworkUserName() Then
bLock = True
End If
End If
End If

'Set the control's Locked property (unless already set correctly.)
If ctl.Locked <> bLock Then
ctl.Locked = bLock
If bSetBorderColor Then 'Set the border color if we were
asked to do that.
ctl.BorderColor = IIf(bLock, conBorderLocked,
conBorderNormal)
End If
End If
End If
Next

Exit_Handler:
Set rsClone = Nothing
Exit Function

Err_Handler:
If Err.Number <> 7951& Then 'Form is unbound (so no
RecordsetClone)
Call LogError(Err.Number, Err.Description, conMod & ".LockControls")
End If
Resume Exit_Handler
End Function

CrazyAccessProgrammer said:
Your situation is starting to sound like there is some weirdness going on.
After I try a few logical things and still experience weirdness, what I
usually do is is start a brand new database and create a brand new form and
try the thing I think should be working.

If it does work with a brand new database and brand new form then it means
you may have corruption with your real database or an object in that database.

What you are trying to do, setting a control's enabled property to false and
locked property to true SHOULD result with the control NOT being greyed out
and as I type this message I have done this on a form in a database and it is
working properly.

JK said:
If on the On-Open Event I put this:

Me.cboAddress.Enabled = False
Me.cboAddress.Locked = True

The field is not grayed out; it works the way it should.
I don't get this at all...

Jason

:

This happens to me sometimes and typically it's because some other code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state of the
Enabled and Locked properites of your MyCheckControl control. (MyCheckControl
obviously is the control on your form, you should use its name in place of
MyCheckControl)

If you find that the values dictate your control should be grayed out, you
can start searching for the code that is changing the locked or enabled
properties to resolve your problem. If not, then it's something else.


:

I'm using Access 03' and in the past, when I've made fields Enabled = no and
locked = yes the field was not grayed out when I viewed the form in live
mode. For some reason, when I set the aforementioned settings, the fields are
grayed out. How do fix this? I want to lock certain fields (text boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 
G

Gina Whipp

JK,

This code will grey out a control because it is setting the Locked property
to No or False. If you are going to use this code I would suggest leaving
the Enabled property to Yes. If that is not what you want you are going to
have modify the code to either skip the controls where Enabled is set to No
and Locked is set to Yes OR abandon this code in favor of what you have set
your controls to do.

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm

JK said:
I've identified the problem. I don't remember where I got the following
code
but it's used to date stamp records when they've been entered or altered.
In
the OnCurrent Event, I have the following:

'Record Locking Feature
Call LockControls(Me, True)

If I remove that line, the enabled and locked features work as intended.
However, I've used this in the past without a problem - not sure what has
changed.

Public Function LockControls(frm As Form, bSetBorderColor As Boolean,
ParamArray avarExceptionList())
On Error GoTo Err_Handler
'Purpose:
Dim rsClone As DAO.Recordset 'RecordsetClone of form.
Dim ctl As Control 'Each control on form.
Dim bLock As Boolean 'Flag to lock control.
Dim lngFldPrp As Long 'Value of custom property.
Dim strEnteredBy As String 'User who entered the record.
Dim dtEnteredOn As Date 'Date/Time the record was entered.
Dim strControl As String 'Name of control.
Dim lngI As Long 'Loop controller.
Dim bSkip As Boolean 'Flag to skip setting this control.
Dim bAllow As Boolean 'Flag to allow edits in this
control.

Set rsClone = frm.RecordsetClone 'This fails if form is unbound.
'Get the user who created the record, and the date it was
entered/updated.
Call GetUserAndDate4Record(frm, strEnteredBy, dtEnteredOn)

For Each ctl In frm.Controls
Select Case ctl.ControlType 'Skip the control if it is one of
these types
Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl,
acPage, acPageBreak, acImage, acObjectFrame
bSkip = True
Case Else 'Otherwise initialize to process
the
control if it has a Locked property.
If HasProperty(ctl, "Locked") Then
bSkip = False
Else
bSkip = True
End If
End Select

'Check if it is one of the names we want to skip, or one of the
names in the exception list.
If Not bSkip Then
strControl = ctl.Name
Select Case strControl
Case "EnteredOn", "EnteredBy", "UpdatedOn", "UpdatedBy",
"InactiveOn", "InactiveBy"
bSkip = True
Case Else
For lngI = LBound(avarExceptionList()) To
UBound(avarExceptionList())
If strControl = avarExceptionList(lngI) Then
bSkip = True
Exit For
End If
Next
End Select
End If

'Permit everything on a new record, other than the exceptions.
If Not bSkip Then
If frm.NewRecord Then
bAllow = True
End If
End If

'Get the user-defined attribute for the field this control is bound
to.
If Not (bSkip Or bAllow) Then
lngFldPrp = GetAttribUser(ctl, rsClone)
If lngFldPrp = -1& Then 'Skip if error.
bSkip = True
End If
End If

'Decide whether the control should be locked.
If Not bSkip Then
bLock = False 'Initialize to permit
editing.
If Not (bAllow Or (lngFldPrp = uBlockNothing)) Then 'Allow
everything if zero.
'Block all?
If (lngFldPrp And uBlockAll) <> 0& Then
bLock = True
End If
'Block if record is more than 1 hour old?
If ((lngFldPrp And uBlockExcept1hr) <> 0&) And (dtEnteredOn
<> conNoDate) And (Not bLock) Then
If DateDiff("n", dtEnteredOn, Now()) > 60& Then
bLock = True
End If
End If
'Block if different user?
If ((lngFldPrp And uBlockExceptSameUser) <> 0&) And
(strEnteredBy <> vbNullString) And (Not bLock) Then
If strEnteredBy <> NetworkUserName() Then
bLock = True
End If
End If
End If

'Set the control's Locked property (unless already set
correctly.)
If ctl.Locked <> bLock Then
ctl.Locked = bLock
If bSetBorderColor Then 'Set the border color if we
were
asked to do that.
ctl.BorderColor = IIf(bLock, conBorderLocked,
conBorderNormal)
End If
End If
End If
Next

Exit_Handler:
Set rsClone = Nothing
Exit Function

Err_Handler:
If Err.Number <> 7951& Then 'Form is unbound (so no
RecordsetClone)
Call LogError(Err.Number, Err.Description, conMod &
".LockControls")
End If
Resume Exit_Handler
End Function

CrazyAccessProgrammer said:
Your situation is starting to sound like there is some weirdness going
on.
After I try a few logical things and still experience weirdness, what I
usually do is is start a brand new database and create a brand new form
and
try the thing I think should be working.

If it does work with a brand new database and brand new form then it
means
you may have corruption with your real database or an object in that
database.

What you are trying to do, setting a control's enabled property to false
and
locked property to true SHOULD result with the control NOT being greyed
out
and as I type this message I have done this on a form in a database and
it is
working properly.

JK said:
If on the On-Open Event I put this:

Me.cboAddress.Enabled = False
Me.cboAddress.Locked = True

The field is not grayed out; it works the way it should.
I don't get this at all...

Jason

:

This happens to me sometimes and typically it's because some other
code
behind the form is changing one of the two properties.

Throw two textboxes on your form.

Set the first control's control source to:
=[MyCheckControl].enabled

Set the second control's control source to:
=[MyCheckControl].locked

Then run your form. The two controls will tell you the current state
of the
Enabled and Locked properites of your MyCheckControl control.
(MyCheckControl
obviously is the control on your form, you should use its name in
place of
MyCheckControl)

If you find that the values dictate your control should be grayed
out, you
can start searching for the code that is changing the locked or
enabled
properties to resolve your problem. If not, then it's something else.


:

I'm using Access 03' and in the past, when I've made fields Enabled
= no and
locked = yes the field was not grayed out when I viewed the form in
live
mode. For some reason, when I set the aforementioned settings, the
fields are
grayed out. How do fix this? I want to lock certain fields (text
boxes and
combo boxes) but I don't want the fields grayed out.

Any ideas? Thx!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top