View Full Version : [SOLVED:] Locking a feild if a different feild is true
Cazca
02-22-2016, 03:11 PM
I have a split form with datasheet on the bottom. Some of the fields are locked.
Some requirements have changed, so now I need all the fields to be unlocked, for that record only, IF a specific field is false.
How do I make this happen?
EXAMPLE:
AutoNum
field1
(default locked)
field2
(default UNlocked
field3
(default UNlocked)
field4
(default locked)
1
locked
UNlocked
UNlocked
True
2
locked
UNlocked
UNlocked
True
3
UNlocked
UNlocked
UNlocked
False
Anehab
02-22-2016, 04:07 PM
Maybe an after update event
If [field 1].value = [you pick a value] OR [add more values you may think will trigger the lock/unlock] Then
[field 2]![locked] = false or true'
End If
Thats all i can think of. Use an after-update event in all fields in a form. IDK about a datasheet. I was able to make a continuous form look like a datasheet so if you need the feel of one, maybe that can be where you meet halfway.
Using After Update would only run after a data change and leave the fields locked/unlocked after moving to another record.
Private Sub Form_Current()
field1.Locked = field4
End Sub
Cazca
02-23-2016, 08:31 AM
Maybe an after update event
If [field 1].value = [you pick a value] OR [add more values you may think will trigger the lock/unlock] Then
[field 2]![locked] = false or true'
End If
Thats all i can think of. Use an after-update event in all fields in a form. IDK about a datasheet. I was able to make a continuous form look like a datasheet so if you need the feel of one, maybe that can be where you meet halfway.
Thanks for the help... I may be able to adapt this to meet my needs.
Using After Update would only run after a data change and leave the fields locked/unlocked after moving to another record.
Private Sub Form_Current()
field1.Locked = field4
End Sub
Actually this is exactly what I'm looking for, however, I'm getting the following error:
15454
Cazca
02-23-2016, 10:23 AM
Contract = field1
CSManaged = field4
I just used field1,2,3,4 for the example.
Cazca
02-23-2016, 10:29 AM
This is what I am interpreting your code as:
If field4 is true, then lock field1. If field4 is false, then do not lock field1.
If this interpretation is correct, this is in fact what I'm trying to accomplish.
You are correct. But Access doesn't appear to know what 'locked' is.
Most basic controls should have a locked property so what is Contract? A textbox or what?
It needs to be a control on a form. You can't run code events on a normal datasheet.
Cazca
02-23-2016, 11:48 AM
Contract is a text box and the control source for a column in a split form.
the split form has fields at top displaying the current record data and the it has a datasheet at the bottom displaying all the records and fields.
Cazca
02-23-2016, 11:50 AM
I can see the Locked option under the property sheet view for each control, however, I now need this code to basically toggle that based on the value of another field.
*can't edit posts for some reason, sorry for double posts
can you post a picture of the form?
Cazca
02-23-2016, 12:19 PM
I had to GREY out some info, but this is what the form looks like in Layout View. Looks the same in Form view, just without the Property Sheet pane.
15459
Small picture isn't very clear. I can't see any textboxes on your main form.
+ edit
yep just tested it and without a control I get the same error. add the controls to the form. Set visible to false if you want.
Also, the code probably needs an edit in case you select a new record
Private Sub Form_Current()
If Not IsNull(csmanaged) Then
contract.Locked = csmanaged
Else
contract.Locked = False
End If
End Sub
Cazca
02-23-2016, 12:59 PM
won't let me post the img for some reason.
I PM'd it to you.
Ok I got your PM.
Image shows the column name as Contract #
So in your code you should use the control's name, not the field name,
and because it has a space you need brackets, i.e.
[contract #].locked = csmanaged
Cazca
02-23-2016, 02:55 PM
SUCCESS! You da man!
I thought "Name" was display only and everything that had to do with actual reference was tied to Control Source.
Thanks again!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.