Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Don't overwrite field (2000)

    I have some code (see below) that won't let somebody overwrite the Client Number and Client Name fields if not a new record. My problem is this works fine if they enter something in those fields but they may not enter something until they bring the record up later making the record not new and they are unable to put a client number or a client name in that field. My reason for using this code is because people are going to use those fields to do a search and they might overwrite the field when they think they can type in those fields to search. How can I change the code to include a record that is not new and one or both of those fields are blank? Thanks for your help.

    Private Sub Form_Current()

    'Set Locked property based on whether user is entering a new record
    Dim fLocked As Boolean
    fLocked = Not Me.NewRecord
    [CLIENT_NUMBER].Locked = fLocked
    [Client_Name].Locked = fLocked
    End Sub

  2. #2
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't overwrite field (2000)

    Test the fields and if empty make then available for input.

    Private Sub Form_Current()

    'Set Locked property based on whether user is entering a new record
    Dim fLocked As Boolean
    fLocked = Not Me.NewRecord
    if isnull(me.client_Number) _
    or me.client_Number = "" then
    me.client_Number .Locked = False
    else
    [CLIENT_NUMBER].Locked = fLocked
    end if
    if isnull(me.client_Name) _
    or me.client_Name= "" then
    me.client_Name.Locked = False
    else
    [Client_Name].Locked = fLocked
    end if

    End Sub
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't overwrite field (2000)

    For some reason that didn't work - I could overwrite the field if something was in it. Then Access froze and closed.

  4. #4
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Schenectady, New York, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't overwrite field (2000)

    I'm sorry, you're right it won't work as written

    As to why it crashed I don't know
    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> As I was previewing this a few minutes ago ,I lost my connection to the lounge and couldn't get back.

    Private Sub Form_Current()
    <UL>'Set Locked property based on whether user is entering a new record
    Dim fLocked As Boolean
    fLocked = Not Me.NewRecord ' set to true if old record.
    if tlocked _ ' if old record
    or isnull(me.client_Number) _ ' or no entry for client number
    or me.client_Number = "" then
    me.client_Number.Locked = False ' open the textbox
    else ' must be old record with text box full - lock the textbox
    me.client_Number.Locked = fLocked
    end if
    if tlocked _ ' Same logic here for Client Name
    or isnull(me.client_Name) _
    or me.client_Name= "" then
    me.client_Name.Locked = False
    else
    me.client_Name.Locked = tlocked
    end if

    End Sub [/list]or I'd just doe something like this.

    if isnull(me.client_Name) _
    or me.client_Name= "" then
    me.client_Name.Locked = False
    else
    me.client_Name.Locked = tlocked
    end if

    if isnull(me.client_number) _
    or me.client_number= "" then
    me.client_number.Locked = False
    else
    me.client_number.Locked = tlocked
    end if
    Don
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18> <img src=/S/flags/NewYork.gif border=0 alt=NewYork width=30 height=18> "Life on Earth is expensive, but at least it includes a free trip around the Sun."

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't overwrite field (2000)

    I really appreciate your help but neither coding worked. I tried the first, but that gave me errors. I tried the second and I could overwrite a client number or client name. Maybe I am doing something wrong. I am putting it behind the on current event of the form.

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't overwrite field (2000)

    Does this work for you ?
    Demo db in attachment.

    Private Sub Form_Current()
    Dim fLocked As Boolean
    fLocked = Not Me.NewRecord
    Me.Client_Number.Locked = fLocked
    Me.Client_Name.Locked = fLocked
    If IsNull(Me.Client_Number) Then
    Me.Client_Number.Locked = False
    End If
    If IsNull(Me.Client_Name) Then
    Me.Client_Name.Locked = False
    End If
    End Sub
    Francois

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Don't overwrite field (2000)

    Thank you for the code - that works. I will keep that code. This also worked:

    Private Sub Form_Current()
    Me![CLIENT_NUMBER].Locked = Not IsNull(Me![CLIENT_NUMBER])
    Me![Client_Name].Locked = Not IsNull(Me![Client_Name])

    End Sub

    I tested the above code and everything seems to work but I will keep your code in case I missed something. Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •