Locking individual records

Pusher

BEOGRAD Put
Local time
Today, 15:49
Joined
May 25, 2011
Messages
230
Hi all,
I want to have an option to lock a particular record (i.e. if an employee leaves, I want to lock their record so that the data can only be viewed but no further changes can be made to it. I know how to lock fields - but that will lock the fields for all records! I want to have an option to only lock certain records. I think I need a check box on my form to achieve this. But again, unfortunately, I’m having difficult of writing the code for this!
I wound this http://allenbrowne.com/ser-56.html but when i do this i lock ALL the records and because its a button i can UNLOCK it again, I want to when pressed it can't be unlocked and that is made for every record separately .

I also made this code
Code:
Private Sub NEZAVRSENE_INTERVENCIJE_AfterUpdate()
Dim ctrl As Control

If Me.NEZAVRSENE_INTERVENCIJE = -1 Then

For Each ctrl In Me.Controls
    If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is CheckBox) Or (TypeOf ctrl Is ComboBox) Then
     ctrl.Locked = True
    End If
 Next

Else

For Each ctrl In Me.Controls
    If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is CheckBox) Or (TypeOf ctrl Is ComboBox) Then
      ctrl.Locked = False
    End If
 Next
 
End If
End Sub
Where NEZAVRSENE_INTERVENCIJE is a check box that can lock the record but when i go to the next record it must be reclicked...
 
Presuming the checkbox is bound to a field in the data, you'd want the same code in the current event of the form. Also, rather than loop controls I'd toggle the AllowEdits (and perhaps AllowDeletions) property of the form.
 
How do I do that? I made this work with Form_Current() but I have some buttons that can automatically fill some fields. They can fill it even when I LOCK the TextBox CheckBox and ComboBox with LockRecord. How to correct this? Maybe I can include the buttons in the lock…but I have some navigation buttons that will be locked too… :(
How do I toggle the allow edits or Allow Deletions by a CheckBox event?
 
Me.AllowEdits = False

To continue with your loop, you could use and test the Tag property of controls to determine which to lock.
 
How do i lock specific buttons with my Tag property? (ctrl is Me.command) ?
I cant make Me.AllowEdits work. :(
 
Last edited:
Instead of testing the type of control, you test the tag property (after entering something in that property for the appropriate controls:

If ctrl.Tag = "Whatever" Then
 
I made it work by editing the buttons :) if locked the buttons don't work
 
Glad you got it sorted out.
 
I have a question. Can I somehow lock individual controls and not group of controls like all textboxes all comboboxes and all checkboxes. Can I lock like combobox 1 but not combobox 2
 
did you miss this?

Instead of testing the type of control, you test the tag property (after entering something in that property for the appropriate controls:

If ctrl.Tag = "Whatever" Then
 
I'm not so good in MS programming :( can you give me an example for this
 
Can someone help me please, i need this because i need to have one checkbox free to be changed after i lock the record.
 
I think i solved it :)
Code:
For Each ctrl In Me.Controls
   
    If (TypeOf ctrl Is TextBox) Or (ctrl Is NEZAVRSENE_INTERVENCIJE) Or (TypeOf ctrl Is ComboBox) Then
     ctrl.Locked = True

    End If
 Next
 
Glad you found a solution, though I would have used the Tag property. It would be more flexible.
 
:) Would like to learn how to solve this with the Tag property. If you can tell me how i would be grateful :)
 
Start with post 6 and 10, after putting something in the Tag property of the controls to set.
 
I need your help with partial locking of a record. This is the situation when there is a shift change and one record is started by one person and finished by another. What one has written another can’t change but must finished a record. So u must lock only the combo boxes and text boxes that are filled. This code lockes all the combo boxes and text boxes and 2 check boxes (NEZAVRSENE_INTERVENCIJE and IZMENA_RASKRSNICE) by clicking on a NEZAVRSENE_INTERVENCIJE check box. Lets say I have combo boxes 1 2 and 3 and text boxes 1 2 and 3 and I have to lock only the ones that are filled. How do I code that another check box lockes just the filled controls?

Code:
Private Sub NEZAVRSENE_INTERVENCIJE_AfterUpdate()
Dim ctrl As Control

If Me.NEZAVRSENE_INTERVENCIJE = -1 Then

For Each ctrl In Me.Controls
   
    If (TypeOf ctrl Is TextBox) Or (ctrl Is NEZAVRSENE_INTERVENCIJE) Or (ctrl Is IZMENA_RASKRSNICE) Or (TypeOf ctrl Is ComboBox) Then
     ctrl.Locked = True
  
    End If
 Next

Else

For Each ctrl In Me.Controls
   
   If (TypeOf ctrl Is TextBox) Or (ctrl Is NEZAVRSENE_INTERVENCIJE) Or (ctrl Is IZMENA_RASKRSNICE) Or (TypeOf ctrl Is ComboBox) Then
      ctrl.Locked = False

    End If
 Next
 
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom