Locking records in a form based on a combo box selection

Discussion in 'Microsoft Access' started by Owl, Jan 18, 2010.

  1. Owl

    Owl Guest

    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
     
    Owl, Jan 18, 2010
    #1
    1. Advertisements

  2. Owl

    Owl Guest

    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
    >
     
    Owl, Jan 18, 2010
    #2
    1. Advertisements

  3. Owl

    Daryl S Guest

    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
    >
     
    Daryl S, Jan 18, 2010
    #3
  4. On Sun, 17 Jan 2010 23:43:01 -0800, 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


    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]
     
    John W. Vinson, Jan 18, 2010
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    355
    Douglas J. Steele
    Mar 30, 2007
  2. Ruth
    Replies:
    0
    Views:
    802
  3. Dan H.
    Replies:
    1
    Views:
    237
  4. kealaz
    Replies:
    0
    Views:
    245
    kealaz
    Apr 13, 2009
  5. newtoaccess

    Locking Text Box - based upon Combo Box Selection

    newtoaccess, Jun 14, 2010, in forum: Microsoft Access
    Replies:
    4
    Views:
    739
    newtoaccess
    Jun 15, 2010
Loading...

Share This Page