Locking a specified record with check box

oliver916

Registered User.
Local time
Today, 10:17
Joined
Nov 24, 2009
Messages
32
Hello dears....

simply, i have a form with sub-form
i want to ass a check box to lock the records from the main form & the sub form for the specified record only,

is that possible? & how?
 
Re: Locking a specifide recorde with ceck box

Create a boolean Yes/No field in the table that your mainform is based on. Lets call it blnLocked, then you create a subroutine on your mainform that looks like this:

Code:
Private Sub Lockrecord()
If Me.blnLocked = True Then
   Me.AllowEdits = False
   Me.[COLOR=red]NameOfSubformControl[/COLOR].Locked = True
Else
   Me.AllowEdits = True
   Me.[COLOR=red]NameOfSubformControl[/COLOR].Locked = False
End If
End Sub

Match whats marked in red with your controlname

And in the mainforms OnCurrent event you call the sub

Code:
Private Sub Form_Current()
   Lockrecord
End Sub

This will lock the record after you leave it if you want an emediate lock, call the Lockrecord Sub in the checkbox After_Update event.

You should also create a methode to unlock records.

Hope this helps

JR
 
Re: Locking a specifide recorde with ceck box

When i place the lock every thing is closed even the lock check box
so how i will unlock it?
 
Re: Locking a specifide recorde with ceck box

Look at "DemoLockSpecRecA2000.mdb" (attachment, zip).
Look at Table1 and Form1, Table2 and Form2.
Look at VBA in the forms.
Adapt it as you need.
 

Attachments

Re: Locking a specifide recorde with ceck box

When i place the lock every thing is closed even the lock check box
so how i will unlock it?

Well I said:

You should also create a methode to unlock records.

A simple way is to use a commandbutton that calls and UnlockRecord Sub which is the revers of the Lockrecord Sub

Code:
Private Sub UnLock_Click()
Me.blnLock = False
UnlockRecord
End Sub

JR
 
Re: Locking a specifide recorde with ceck box

Look at "DemoLockSpecRecA2000.mdb" (attachment, zip).
Look at Table1 and Form1, Table2 and Form2.
Look at VBA in the forms.
Adapt it as you need.
Thanks alot
this works fine with me.:D

i need one more help
is there is a way to hide the record from the search if the the record was locked?
 
Re: Locking a specifide recorde with ceck box

Yes, it can be done, (look at Form1 (Record source, VBA)),
but in that case you can't to make UNLOCK (if you want).
In that case you need a separate Form (Form3), with the
all records.
Look at attachment.
 

Attachments

Re: Locking a specifide recorde with ceck box

BTW This code can be made a lot tidier and more efficient.

Code:
Private Sub Lockrecord()
If Me.blnLocked = True Then
Me.AllowEdits = False
Me.[COLOR=red]NameOfSubformControl[/COLOR].Locked = True
Else
Me.AllowEdits = True
Me.[COLOR=red]NameOfSubformControl[/COLOR].Locked = False
End If
End Sub


Code:
Private Sub Lockrecord()
 
Dim Lock as Boolean
 
  With Me 
      Lock = .blnLocked
      .AllowEdits = Not Lock
      .[COLOR=red]NameOfSubformControl[/COLOR].Locked = Lock
   End With
 
End Sub

Or

Code:
Private Sub Lockrecord()
 
   With Me 
      .AllowEdits = Not .blnLocked
      .[COLOR=red]NameOfSubformControl[/COLOR].Locked = .blnLocked
   End With
 
End Sub

I generally read the control once as in the first alternative suggestion.
 

Users who are viewing this thread

Back
Top Bottom