Locking records in a form based on a combo box selection

O

Owl

I have read all I can find but still can't get this right. I have a combo
box with a selection of either Yes or No in a field called P5Pd and I want to
lock records if it Yes is selected.

I have the following code, but it is locking ALL records and not just if
P5Pd = "Yes"

Sub Form_Current()
If Me.P5Pd = "Yes" Then
Me.AllowEdits = False
End If
End Sub
 
O

Owl

In addition to the above information, I would like to say that I can edit
other records, but once I have passed that record either forwards or
backwards (e.g. if it is the 3rd record, I can edit records 4 onwards, but
once I go passed it backwards to record 1, I can't edit any records. If I
edit the record back again (in a copy of the form which doesn't have the
above code in On Current), I get everything back to normal. However, I need
this lock to work, and only on the relevant records.

Thank you for any help.
 
D

Daryl S

Owl -

You need to turn AllowEdits back on for the other cases:

Sub Form_Current()
If Me.P5Pd = "Yes" Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
End Sub

Check it out.
 
J

John W. Vinson

I have read all I can find but still can't get this right. I have a combo
box with a selection of either Yes or No in a field called P5Pd and I want to
lock records if it Yes is selected.

I have the following code, but it is locking ALL records and not just if
P5Pd = "Yes"

Sub Form_Current()
If Me.P5Pd = "Yes" Then
Me.AllowEdits = False
End If
End Sub

What is the datatype of the field referenced by the combo box? If it's Text,
then the combo may contain the string "Yes" or "No" - but more likely it's a
Yes/No field, in which case Yes is stored as -1 and No as 0 (though it may be
DISPLAYED as the English language word).

Try changing "Yes" to -1, or (synonymously) to True, or just using

Private Sub Form_Current()
Me.AlllowEdits = Not(Me.P5Pd)
End Sub
 

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