Allow Edits

history

Egyptian Pharaoh
Local time
Today, 07:41
Joined
Jan 26, 2008
Messages
190
Hello Friends

I have a form for employees and on the Current event I put a code that prevent the user to Edit any field without entering a password.

If Me.NewRecord Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If

All of that working very well.
My problem is : on the form I have 3 combo boxes to look for the employees ,, but unfortunately after searching for anyone the code close these combo boxes too ,,,but I need these combo boxes to be active , I mean to be available to the user to look for the employees.

Please I need a help for this ,,, how can I tell the program to not AllowEdits to all fields except these 3 combo boxes ???

waiting to hear from you
 
Instead of using the Allow Edits property of your form, you will need to set the Locked or Enabled property of each control that you do not want users to use and then reset them to unlocked or enabled when you need or want them to use them.

You can create a user defined function that you can call to set the properties as you desire. Just pass a value of "true" or "false" to the function to set the property. Like:

Code:
Function LockUnlockCtrls(Statue as Boolean)
     Me.NameOfSomeControl.Locked = Status
     Me.NameOfSomeOtherControl.Locked = Status
End function

Of course you will change the "NameOfSomeControl" to the actual name of the control you want to lock. If you pass "true" as the status, the controls listed in the function will be "locked". If you pass "False" as the Status, the controls listed in the function will be Unlocked.

If you want to enable/disable these controls instead of locking/unlocking them, just change the Locked property to the Enabled property.
 
Thank you for your fast reply

I liked your way
But this will make me start from the scratch ,, as I defined all as Enabled fields and made a button to Allow Edits to all after entering a password.

Thank you very much for your care
And I'll be so appreciated if you advised me to solve the problem on the current case
 
A quick way using the TAG property of a control. Put this in the TAG property of any control you want locked:

Lock

and then use this code to lock or unlock:

Code:
Dim ctl As Control
Dim blnLock As Boolean

blnLock = Not Me.NewRecord

For Each ctl In Me.Controls
   If ctl.Tag = "Lock" Then
      ctl.Locked = blnLock
   End If
Next ctl

That will lock or unlock based on if it is a new record or not.
 

Users who are viewing this thread

Back
Top Bottom