Code required to lock/disable all form fields on inputted value.

southwestgooner

Registered User.
Local time
Today, 12:31
Joined
May 14, 2009
Messages
28
Hi,
Can any VB Code writing experts help ?
I am looking to completely disable a record when a specific Yes/No tick box is checked.
By that I mean all form fields are locked and disabled when the Yes/No tick box is checked (Yes)

Can anyone reply with a chunk of VB Code I can add to my database Module ?

Many thanks in anticipation of a satisfactory resolution to my problem.

Cheers,
Steve.
:banghead::banghead:
 
You can utilize the "tag" property of each control that you need to manage. For each control that you want to "Lock" by putting "SetLocked" in the tag property. I then use a public function that I have written that evaluates these controls in the specified form or sub form and sets or changes the property setting of each control with the value in the "tag" property when the function is called. This also works for setting the enabled or visibility properties.

Here is a link to a demo that will provide you with examples of this method. The public function is in the demo.
http://www.askdoctoraccess.com/DownloadPage.aspx
Down load the "ManagingMultipleControls.zip" file, unzip it an give it a try.

Hope this helps.
 
Replacing the name CheckboxName with the actual name of your Yes/No Controls:

Code:
Private Sub Form_Current()
 If Me.CheckboxName = -1 Then
   Me.AllowEdits = False
   Me.AllowAdditions = False
   Me.AllowDeletions = False
 Else
   Me.AllowEdits = True
   Me.AllowAdditions = True
   Me.AllowDeletions = True
 End If
End Sub
If you want the Record locked immediately after the Checkbox is ticked, you can put the same code in the AfterUpdate event of the Checkbox. But best practice is to not lock it until after the Record is exited/saved; this makes it much easier to correct if the Checkbox is ticked by accident and the user realizes it while still on the Record.

Linq ;0)>
 
Last edited:

Users who are viewing this thread

Back
Top Bottom