Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2004
    Posts
    56

    Unanswered: Record Locking / Enabling

    I have a table which has a large number of fields in it. A form which the table is inputted into through has a number of pages to it. One of the fields is called Archive. The answer is either Yes/No.

    When the check box is ticked yes. I want every text box/combo box for that record to be disabled so that they can not enter details in the boxes but the data can still be seen. I have toyed with doing VBA code and it will work as i've done this in the past to make boxes visible or not. The only thing with this is that there are a large number of fields and I just wondered if there was a quicker way of Enabling or disabling the whole record on the form or not.

    Thanks



    Col_bol

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Half the battle is already won....

    Because you already have a Yes/No field named Archive, You can obviously use this field to determine whether or not the record should be Locked (which is apparently what you intend). If Archive is checked (Yes) then the Record should be locked. If Archive is unchecked (No) then the Record should be Unlocked.

    Note: The Archive field can be either visible or not visible.

    Place this line of code into the OnCurrent event of the Form displaying your records:

    Me.Locked = Me.Archive.Value

    If you have a SubForm in your main form and you only want to lock that specific SubForm then place this line of code into the OnCurrent event of the main Form displaying your records:

    Forms!myMainFormName!mySubFormName.Locked = Me.Archive.Value


    Hope this helps....


  3. #3
    Join Date
    Jul 2004
    Posts
    56
    Thanks

    This caused a few errors. It didn't seem to like the Locked Statement in the VBA. Any ideas.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Try this:

    me.RecordLocks = 1

  5. #5
    Join Date
    Jul 2004
    Posts
    56
    I put this on its own in VBA on the OnCurrent in the main form. When I went to open the form it said that the form can not be altered programatically.

    I take it there needs to be a criteria to the reocrd lock - Any ideas? Thanks for your help so far.

    Col_bol

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Another method you could try is to use the function provided below:
    Code:
    Public Function LockAllRecords(Frm as Form, OnOff As Integer )
    'if OnOff = 0 then Unlocked | If OnOff = 1 then Locked.
    Dim Ctrl As Control
    On Error Resume next
    For Each Ctrl In Frm.Controls
    		 Ctrl.Locked = OnOff
    Next Ctrl
    End Function
    Usage:
    Place this line into the OnCurrent event:

    Call LockAllRecords(Me, Me.Archive.Value)

    My mistake for your particular application. The Lock property only applys to controls...sorry people.


    Last edited by CyberLynx; 08-26-04 at 05:47.

Posting Permissions

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