Locking Fields in Forms

McObraz

Registered User.
Local time
Today, 02:49
Joined
Nov 21, 2011
Messages
37
Hello all,

I am seeking help regarding locking entry of data in a form. Attached is the database in which my question lies.

The user first interacts with Table 1, which then leads to the opening of the Personal form (as per the user's wishes). What I would like to do is:
1: To give the user the authority to enter data in those cases where the fields in the Personal form is empty (in the case of the Names). The user should not be able to change any data if these fields are not empty.
2: To give the user the ability to change the Amount (If this figure is Zero) and not to change anything if this amount is not Zero.
Any help will be greatly appreciated.

Thanks.
Maurice.
 

Attachments

you can use conditional formatting to set enabled=false if the value is not null (or 0)
 
Many people don't want a populated Control to be 'grayed out,' and sadly, Conditional Formatting can't control Locking. If we were doing this for a large number of Controls I'd do this by looping all Controls and setting accordingly, but for three Controls, I'd do it like this:

Code:
Private Sub Form_Current()
 
 If Nz(Me.NAME_1, "") <> "" Then
  Me.NAME_1.Locked = True
 Else
  Me.NAME_1.Locked = False
 End If
 
 If Nz(Me.NAME_2, "") <> "" Then
  Me.NAME_2.Locked = True
 Else
  Me.NAME_2.Locked = False
 End If
 
 If Nz(Me.Text12, 0) = 0 Then
  Me.Text12.Locked = False
 Else
  Me.Text12.Locked = True
 End If
  
End Sub
You might also want to change the name of the 'Amount' Control to something other than Text12, as you have the other Controls.

Linq ;0>
 
Last edited:
I would replace this:
Code:
If Nz(Me.NAME_1, "") <> "" Then
  Me.NAME_1.Locked = True
 Else
  Me.NAME_1.Locked = False
 End If

with this far more efficient single line:

Code:
Me.NAME_1.Locked = Len(Me.NAME_1 & "")
 
Sorry, been up and about.

Galaxiom, Missinglinq and CjLondon; a BIG Thank You for your helpful replies.

With much appreciation,
Maurice.
 

Users who are viewing this thread

Back
Top Bottom