Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2004
    Posts
    11

    Question Unanswered: locking 1 field in table

    the form is in datasheet view, how do i lock a certain field in it? or do i lock it directly in the table, if so, how?

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    In your Form's OnCurrent Event place something like the following:

    Code:
    Me.myFormFieldName.Locked = True  'Form Record Field is Locked
    You will obviously want to set specific conditions before a field is locked. How you do this is entirely up to you. For example, let suppose we do not want it locked if it contains no value (it is null). We may then want to do it this way:

    Code:
    If IsNull(Me.myFormFieldName) Then 
       Me.myFormFieldName.Locked = False  
    Else
       Me.myFormFieldName.Locked = True  
    End If
    To lock All fields on A Form you can do it this way:

    Code:
    'Lock ALL the Controls (Fields) on a Form.
    On Error ReSume Next
    Dim Ctrl As Control
    For Each Ctrl In Me.Controls
    	 Ctrl.Locked = True
    Next Ctrl

  3. #3
    Join Date
    Nov 2004
    Posts
    11
    i'm sorry i forgot to tell you that the form in question is a subform. the subform is in datasheet view and i want to lock 1 field in it. the subform has an underlying query in it.

  4. #4
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146
    Quote Originally Posted by corics15
    i'm sorry i forgot to tell you that the form in question is a subform. the subform is in datasheet view and i want to lock 1 field in it. the subform has an underlying query in it.
    I beleive that what CyberLynx told you is correct and applies to both the main form and the subform. Open the subform in Design view, select the control in question, and set it's Locked Property to "Yes" (True). Additionally, you could also set the Enabled Property to "No" (False) to prevent the cursor from entering the field at all. Just keep in mind that this prevents all edits to the data in that particular field.
    Last edited by smacdonaldnc; 11-23-04 at 21:17.

  5. #5
    Join Date
    Nov 2004
    Posts
    11
    when i open the subform in design view, the only events available are On Enter and On Exit. mind you it has an underlying query in it.

  6. #6
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146
    Quote Originally Posted by corics15
    when i open the subform in design view, the only events available are On Enter and On Exit. mind you it has an underlying query in it.
    If by underlying you mean the form is based on a query, it doesn't matter. CyberLynx's approach was through the OnCurrent event and therefore, code. My approach is to simply manipulate the properties of the control in question to acheive the same result. Check the properties of the control itself, not the form, and you should be fine.

  7. #7
    Join Date
    Nov 2004
    Posts
    11
    the form in question is a subform w/c is in datasheet view. you see i have a mainform and a form on the mainform w/c is the subform. the subform is in datasheet view, but of course when the subform is viewed as a single form (not datasheet view), the suggestion you made works fine. the problem occurs when it's viewed as datasheet view.
    imagine locking a single field in a form w/c is viewed in datasheet view (just like in excel).

  8. #8
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146
    Quote Originally Posted by corics15
    the form in question is a subform w/c is in datasheet view. you see i have a mainform and a form on the mainform w/c is the subform. the subform is in datasheet view, but of course when the subform is viewed as a single form (not datasheet view), the suggestion you made works fine. the problem occurs when it's viewed as datasheet view.
    imagine locking a single field in a form w/c is viewed in datasheet view (just like in excel).
    I use subforms with locked fields in many of my Access DBs. Even in datasheet view, the fields retain the properties that were set in Design/Form views. If it still doesn't make sense, zip a copy of the DB and post it and I'll demonstrate.

  9. #9
    Join Date
    Nov 2004
    Posts
    11
    would you be kind enough to supply a sample database? thanks a lot. you could send it to me at eperez@primestars.net. thanks! you're a great help man.

Posting Permissions

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