Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, I have an After Update event running, on a date field, that automatically generates the "FileNumber" field data. [I've adopted the code from the earlier database my one replaces, written by someone else, but essentially what it does is take the year, month, and generates successive numbers by storing the number in another table and populating the latest in the series in the FileNumber field. Ends up like 09-11/3 for the third record created for dates in November 2009. This though is not relevant to the question I have, I believe.]

    This works great in automatically generating a file number, which is recorded on the paper record in that office. I have found that should someone happen to update the date field in the future, or even "replace" the same date in the field, the event procedure is called again and so the file number changes. I would like to prevent this from happening, by somehow having the code called once only, or to subsequently lock the date field from changing after it is initially created and the record first saved.

    Is this possible? Hopefully this makes sense.

    Regards
    Roger

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could put code in the On Current event of the form:

    Code:
    Private Sub Form_Current()
      Me.DateField.Locked = Not IsNull(Me.DateField)
    End Sub
    where DateField is the name of the control bound to the date field. The code will lock the control if it is not empty. Of course, this also means that the user can't correct an erroneous date.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    And also the same code in the After Update event.

    Is there ever a reason to edit this field after it has been entered? what about if a mistake has been made?
    Regards
    John



  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Putting the same code in the AfterUpdate event of the date control would make ANY error correction impossible. Whether that is desirable is for Roger to decide.


  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    I agree, but without it he would get a 2nd file reference if a correction is made.

    Ideally you would allow corrections, but prevent a 2nd file reference.
    Regards
    John



Posting Permissions

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