PC Review


Reply
Thread Tools Rate Thread

Locking records in a form based on a combo box selection

 
 
Owl
Guest
Posts: n/a
 
      18th Jan 2010
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

 
Reply With Quote
 
 
 
 
Owl
Guest
Posts: n/a
 
      18th Jan 2010
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.

"Owl" wrote:

> 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
>

 
Reply With Quote
 
 
 
 
Daryl S
Guest
Posts: n/a
 
      18th Jan 2010
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.
--
Daryl S


"Owl" wrote:

> 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
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      18th Jan 2010
On Sun, 17 Jan 2010 23:43:01 -0800, Owl <(E-Mail Removed)> wrote:

>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

--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locking Text Box - based upon Combo Box Selection newtoaccess Microsoft Access 4 15th Jun 2010 08:23 PM
Populate one combo box based on the selection of another combo box =?Utf-8?B?QWxleA==?= Microsoft Excel Programming 8 19th Apr 2007 06:40 PM
combo box list based on the selection in another combo box =?Utf-8?B?TWFyaWFubmU=?= Microsoft Access Form Coding 3 11th May 2006 06:35 PM
populating a combo box based on selection in another combo box Brian Beck Microsoft Access Form Coding 5 8th Feb 2006 01:25 PM
filtering combo box entries based on the selection of another combo box JulieD Microsoft Access Forms 1 4th Nov 2003 10:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:41 AM.