Disable Form text fields after Data entry

A

Ajay

I have designed a Database but users seem to edit records after printing off
reports.
Is there any way that to disable form fields after Data entry in the same
form??
 
D

Daniel Pineault

You can use the afterupdate event on the control in conjunction with the
form's current event to chack and see if there is a value in the control and
enable/disable it accordingly.

You can test the controls value using something like

If isnull(me.controlname) or me.controlname="" then
'Enable control
Me.controlname.Enable = True
'Etc
Else
'Disable control
Me.controlname.Enable = False
'Etc
End if
--
Hope this helps,

Daniel Pineault
For Access Tips and Examples: http://www.cardaconsultants.com/en/msaccess.php
If this post was helpful, please rate it by using the vote buttons.
 
L

Linq Adams via AccessMonster.com

You don't really want the controls disabled until after the record jhas been
saved, because on looking over the record, the user may want to change an
entry. Assuming that the only fields you want to Disable are textboxes:

Private Sub Form_Current()
Dim ctrl As Control

If Not Me.NewRecord Then
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If Not IsNull(ctrl) Or ctrl <> "" Then
ctrl.Enabled = False
Else
ctrl.Enabled = True
End If
End If
Next
Else
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Enabled = True
End If
Next
End If

End Sub

I don't really like the looks of Disabled controls, so I would use the Locked
property instead. It keeps the users from changing the data, once entered and
the record is saved, but it doesn't gray out the textboxes.


Private Sub Form_Current()
Dim ctrl As Control

If Not Me.NewRecord Then
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If Not IsNull(ctrl) Or ctrl <> "" Then
ctrl.Locked = True
Else
ctrl.Locked = False
End If
End If
Next
Else
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = False
End If
Next
End If

End Sub
 
J

John W. Vinson

I have designed a Database but users seem to edit records after printing off
reports.
Is there any way that to disable form fields after Data entry in the same
form??

Sounds like some user training would be more appropriate. Surely you want to
be able to bring up existing records and correct errors in them, do you not!?

You may also want to have the Form automatically move to a new record upon
opening, so users don't naively overwrite the first record in the
recordsource. You can put a line of code in the form's Load event

Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, Me.Name, acNewRecord
End Sub

or - if users should routinely only add records and never even see old ones -
set the Form's Data Entry property to True.
 
S

Stockwell43

Hi Ajay,

I have to agree with John, it appears as though some user training would
help. However, I go through this same thing everyday and they still mess
something up.

I would go with Daniel's code. It will allow you to enter data and change
whatever needs to be change before the record is added. If you find something
needs to be corrected, that should be a supervisor or manager (one for
security reasons and also gives managetment who is making all these errors
that need to be fixed). Please a password field and a command button on the
form so that when the password is entered it will unlock or enable the fields
and allow you to edit as many records as needed until you close the form then
it will reset itself.

I know it seems like a unecessary process to through but you do what you
gotta do to keep the peace. :eek:)
 
J

John W. Vinson

I have to agree with John, it appears as though some user training would
help. However, I go through this same thing everyday and they still mess
something up.

<wry grin> Yeah, you build a fool-proof application and the fools just get
better at it.
 
Top