Grayed-out fields on New Record?

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

Guest

Hello,

I have the strangest thing happening on a Command Button on a Form to open a
new Record. Here's the code:

Private Sub CommandOpenNewRecord_Click()
DoCmd.OpenForm "FCycChemistry", acNormal
DoCmd.GoToRecord acDataForm, "FCycChemistry", acNewRec
DoCmd.GoToControl "cyclenum"
End Sub

It works great, except there is other code that 'grays out' some fields if a
'Not Done' field is checked. For those fields on the form that were 'greyed
out' because the 'Not Done' field was checked, they show up as 'greyed out'
on the New Record. Here's an example of the 'grey out if true' code:

Private Sub creat_nd_AfterUpdate()
Dim blnEnable As Boolean
blnEnable = (Me.creat_nd.Value <> True)
Me.creat_u.Enabled = blnEnable
Me.creat.Enabled = blnEnable
End Sub

Is there something that needs to be 'cleared out' (some sort of cache,
maybe?) so that the new record doesn't automatically show fields greyed out?

Thanks.
 
Private Sub creat_nd_AfterUpdate()
Dim blnEnable As Boolean
blnEnable = (Me.creat_nd.Value <> True)
Me.creat_u.Enabled = blnEnable
Me.creat.Enabled = blnEnable
End Sub

Is there something that needs to be 'cleared out' (some sort of cache,
maybe?) so that the new record doesn't automatically show fields greyed out?

On the new record, creat_nd.Value will neither be True nor False - it
will be NULL, and any comparison statement with NULL will return NULL.

Try

blnEnable = Not NZ(Me.creat_nd)


John W. Vinson[MVP]
 
Hi John,

It is still behaving the same way-- when I click on the 'New Record' Command
Button, the same fields that were 'greyed out' on the previous record are
already 'greyed out' on the New Record, even though the 'Not Done' check box
is empty. Here is an example of one of these instances:

Private Sub tprot_nd_AfterUpdate()
Dim blnEnable As Boolean
' blnEnable = (Me.tprot_nd.Value <> True)
blnEnable = Not Nz(Me.tprot_nd)
Me.tprot_u.Enabled = blnEnable
Me.tprot.Enabled = blnEnable
End Sub

Either method of the 'blnEnable = ...' line above produces the same result.
Here is the other code running on the form:

Private Sub Form_Current()
If Me.NewRecord Then
Call SetAutoValues(Me)
Else
Call LockControls(Me)
End If
End Sub

Sub SetAutoValues(frm As Form)
On Error GoTo SetAutoValues_err
' Set Automatic Values in each form in series
' Add as many fields as necessary (make sure each field has the same
name on EVERY form)
With frm
!id = Forms!fEnterPatientInfo!id
!ptin = Forms!fEnterPatientInfo!ptin
!site = Forms!fEnterPatientInfo!site
End With
SetAutoValues_err:
'MsgBox Err.Description
Resume Next
End Sub

Public Sub LockControls(frm As Form)
On Error Resume Next
Dim ctl As Control

For Each ctl In frm.Controls
With ctl

Select Case .ControlType
Case acTextBox
ctl.Locked = True

Case acComboBox
If ctl.Tag = 2 Then
ctl.Locked = False
Else
ctl.Locked = True
End If

Case acListBox
ctl.Locked = True

Case acCheckBox
ctl.Locked = True

Case acToggleButton
ctl.Locked = True

Case acCommandButton
If ctl.Tag = 2 Then
ctl.Enabled = False
Else
ctl.Enalbled = True
End If

Case acSubform
ctl.Locked = True

Case acOptionGroup
ctl.Locked = True

Case acOptionButton
ctl.Locked = True
End Select
End With
Next ctl
Set ctl = Nothing
Set frm = Nothing
End Sub

Private Sub CommandOpenNewRecord_Click()
DoCmd.OpenForm "FCycChemistry", acNormal
DoCmd.GoToRecord acDataForm, "FCycChemistry", acNewRec
DoCmd.GoToControl "cyclenum"
End Sub

From what I can tell, I don't think the 'LockControls' or 'SetAutoValues'
code kicked offin the the Form's 'On Current' Event, is causing this.
'SetAutoValues simply sets a couple of fields in the 'header' section of the
form, and 'LockControls' locks down records that have already been entered.
These New Records with the greyed-out fields are not 'locked', they can be
edited, but it does make my data entry people somewhat more susceptible to
errors. Any thoughts are greatly appreciated. Thanks.
 
Back
Top