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!