locking records in a subform through checkbox

G

Guest

Hi,

I have a subform on which I want to be able lock every record seperately by
using a checkbox. To do this I've added a field with the data type "yes/no"
to the source table of the subform, and then added this field (checkbox) to
the subform. I want to use the field as follows: when the box is checked, all
others fields (in the corresponding record of the subform) get locked, and
when the box is unchecked all other cells of the record get unlocked.

To do this, I've tried writing the following code:

Private Sub Form_Current()

If (Forms!subformName!checkboxName = True) Then
Forms!subformName!controlName1.Locked = True
End If
If (Forms!subformName!checkboxName = True) Then
Forms!subformName!controlName2.Locked = True
End If
If (Forms!subformName!checkboxName = False) Then
Forms!subformName!controlName1.Locked = False
End If
If (Forms!subformName!checkboxName = False) Then
Forms!subformName!controlName2.Locked = False
End If

End Sub

The above code doesn't work. Could the problem be that it is a subform or
perhaps that I should use another kind of event?

Furthermore, unchecking the box should not be possible without entering a
password. I've written the following code:

Private Sub lockRecord_AfterUpdate()
Dim password
If Forms!subformName!checkboxName = False Then
password = InputBox("Enter password")
If password = "myPassword" Then
Forms!subformName!checkboxName = False
Else
Forms!subformName!checkboxName = True
Call MsgBox("Wrong password!", vbOKOnly)
End If
End If
End Sub

The above code works when I've opened the subform without the mainform, but
when it's embedded in the mainform (as it's supposed to!) the code apparently
has no effect at all.

I would be most grateful to receive some help here.

Best regards from Denmark,
Hjalte Dam
 
V

Van T. Dinh

Try:

****Untested****
Private Sub Form_Current()
With Me
If (.checkboxName = True) Then
.controlName1.Locked = True
.controlName2.Locked = True
Else
.controlName1.Locked = False
.controlName2.Locked = False
End If
End With
End Sub
****Code ends****

You may want to check out the Enabled Property of the Controls also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top