Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preventing edits on forms (2000)

    Hello all

    I have a problem. I open a form called statistics from a command button on a form called CONID , this links the stats to the the CONID number. I would like to set allowedits to NO in the Stats form so once data is entered it can not be changed at a later date. But when I do this the form does not allow me to enter any data, I think it is because the CONID field on the form automaticly self populates when opening

    Therefor the form thinks it has data entered and dosn't allow data . I have tried placing code behind each field all 36 of them with limited successwhere MYFIELD = the name of the field

    If MYFIELD <> 0 or isnull(MYFIELD) = False then
    Me.AllowEdits = False
    Else
    Me.AllowEdits = True
    Endif

    This works when the form is opened but each time it is saved and reopen it allows the user to change one record before it seems to work again I have this set to On Enter

    I sure there is a simple answer but I have spent many hours on this any help would be greatly appreciated

    thanks Ron in Australia

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Preventing edits on forms (2000)

    Welcome to Woody's Lounge!

    You can use the On Current event of the form as a whole; you probably won't need code for the individual controls. You need one field that is guaranteed to be filled in an existing record, and blank (null) in a new record; an AutoNumber field is very suitable.

    Private Sub Form_Current()
    Me.AllowEdits = IsNull(Me.KeyField)
    End Sub

    Replace KeyField with the name of the field you want to use (CONID perhaps?)

  3. #3
    New Lounger
    Join Date
    Feb 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preventing edits on forms (2000)

    Thanks Hans
    yes this code worked but I cant understand the auto number when i tried to use this it automaticly filled this record locking all other fields can you make an auto number the last field to fill

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Preventing edits on forms (2000)

    An AutoNumber field is filled automatically as soon as the user starts entering data in a new record. This behavior cannot be changed.

    But you should not set AllowEdits to False as soon as a field in a record changes; you should only test in the On Current event of the form.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Preventing edits on forms (2000)

    You wrote me
    <hr>It is hard for me to choose a field that I know the user will imput data into as there are over 36 stats fields in the form. As some of the form records self populates i cant set the as discussed to the whole form as it thinks it is not as new clean form.<hr>
    If you do not have an AutoNumber field in the table, I would add one especially for this purpose. An AutoNumber field is blank until the user starts to enter data in a new record, so you can use it in the Form_Current event to test if AllowEdits should be True or False.

Posting Permissions

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