Disable all fields on a Form when a field is not null (1 Viewer)

gstreichan

Registered User.
Local time
Today, 17:28
Joined
Apr 1, 2014
Messages
28
Dear Access Support, need your help.

I have a form called PAF_Assignment and on this form there are many textboxes for editing. After all fields are entered, the user clicks on a button and this button populates the PAF_Issued_Date field with the actual date.

Then I want to disable (enable=False) all fields on this form once there is a date on PAF_Issued_Date as I don't want any user to make any changes after submitting it, although the user would still be able to read the information submitted.

Can anyone help me please?

I have tried the following...

PAF_Assignment Form AfterUpdate Event

If Me.PAF_Issued_Date=Not null Then
Me.FieldName1.Enabled=False
Me.FieldName2.Enabled=False
Me.FieldName3.Enabled=False
...

ElseIf Me.PAF_Issued_Date=Null Then
Me.FieldName1.Enabled=True
Me.FieldName2.Enabled=True
Me.FieldName3.Enabled=True
....

End IF
End Sub

However this is not working, there is no error message or anything but the fields remain enabled with the date...

Really appreciated with a help on that. Thanks.
 

namliam

The Mailman - AWF VIP
Local time
Today, 17:28
Joined
Aug 11, 2003
Messages
11,695
Nothing is ever equal to NULL, even NULL is not equal to NULL, it doesnt exist.

To test if something is NULL in vba you use the function IsNull(yourfield)
 

gstreichan

Registered User.
Local time
Today, 17:28
Joined
Apr 1, 2014
Messages
28
Hello NamLiam,

Thanks for the reply. I guess that might still be something I am doing wrong.

Let me explain you a little more please.

I have a form with a combobox and when selected a value, the subform PAF_Assignement shows all data from that field selected.

The Subform PAF_Assignement contains the PAF_Issued_Date field.

I have entered the following code on afterupdate event:

Private Sub Form_AfterUpdate()
If IsNull(Me.PAF_Issued_Date) Then
Me.FieldName1.Enabled = True
ElseIf Not IsNull(Me.PAF_Issued_Date) Then
Me.FieldName1 = False
End If
End Sub

What I would like also is that, if a new value is selected on the combobox, which the PAF_Issued_Date "is null", I want it to enable all fields again.
Is it possible?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:28
Joined
Sep 12, 2006
Messages
15,653
use the forms current event

the easy way is just

me.allowedits=me.newrecord
or
me.allowedits = nz(somefield."")=""

then any incomplete record can be edited, and as soon as it is saved, it can no longer be. Use some appropriate validation in the forms beforeupdate event. This is a bit of a blunderbuss approach, but it might help get you started.

the trouble is, setting allowedits to false also disables combo boxes, and so on, which is why it sometimes isn't the best way.
 

Users who are viewing this thread

Top Bottom