Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Locking (Access 2000)

    I am trying to lock a form after a final date has been entered.
    I have been referring to the allowedits and allowdeletions property of the form. This seems to have no effect. In fact, I tried setting these properties manually and still no joy.
    My interpretation of the help files led me to believe that this would be the most efficient way to lock the form (instead of locking each control on the form). Was I incorrect?
    TIA

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

    Re: Form Locking (Access 2000)

    No, you were looking in the right direction. You need code in the On Current event of the form, to lock/unlock the form as the user moves from record to record. Say that your text box with the date is txtDate (I'm repeating myself, I think):

    Private Sub Form_Current()
    Me.AllowEdits = IsNull(Me.txtDate)
    Me.AllowDeletions = IsNull(Me.txtDate)
    End Sub

    Note that you can't turn off AllowEdits the moment the user fills in a date - he/she wouldn't be able to save the record any more!

  3. #3
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Locking (Access 2000)

    A little longer than your code, but still I believe the same concept:

    Private Sub Form_Current()
    Dim blnDecommissioned As Boolean

    If Not IsNull(Me.DecommissioningDate) Then
    'set decommissioned switch to true
    blnDecommissioned = True
    Else
    blnDecommissioned = False
    End If

    If blnDecommissioned = True Then
    'change the background colour of the form
    Me.Detail.BackColor = 12565966
    Me.AllowEdits = False
    Me.AllowDeletions = False
    Else
    Me.Detail.BackColor = 13095891
    Me.AllowEdits = True
    Me.AllowDeletions = True
    End If
    End Sub

    However, when I test I can still change information, though the record delete menu option is disabled.

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

    Re: Form Locking (Access 2000)

    Strange. I copied your code to my test form and only modified the name of the field DecommissioningDate to that of a field on my form, it works OK - the form locks/inlocks as needed. You have to be aware that the code only fires when the user moves to another record; you could call Form_Current from Form_AfterUpdate if you wish to lock the form if the user fills in the date and saves the record explicitly without moving to another record.

  5. #5
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Locking (Access 2000)

    In other words, locking won't be triggered until the user comes back into the form. Which is fine, I'll let them edit until they leave the form.

    Well, at least I understood the principle - small comfort right now....

Posting Permissions

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