Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Posts
    300

    Red face Unanswered: Form not Locking On Open

    Got a problem with the following VB code not working quite right in a form I have:

    Sub Mainform_Lock(OnOff As Boolean)

    Me![Field1].Locked = OnOff
    Me![Field2].Locked = OnOff
    Me![Field3].Locked = OnOff
    .........
    Me![Field11].Locked = OnOff

    End Sub
    ___________________________________
    Private Sub Form_Open(Cancel As Integer)
    Mainform_Lock True
    DoCmd.GoToControl "Really Cool Stuff"
    End Sub

    __________________________________________________ _

    It does not lock the fields ON OPEN.. but I noticed if I click on the record save button[code not shown] and then mouse over or tab over to the fields, they are then LOCKED...

    What's going on??

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ok, I'm just being picky first.
    Change Mainform_Lock to a function
    Code:
    Function Mainform_Lock(OnOff As Boolean)
    
    Me![Field1].Locked = OnOff
    Me![Field2].Locked = OnOff
    Me![Field3].Locked = OnOff
    .........
    Me![Field11].Locked = OnOff
    
    End Function
    Then call it like this
    Code:
    Mainform_Lock(True)
    Now... Instead of using On_Open try utilizing the On_Load event HTH!
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2003
    Posts
    300
    darn, no that did not work. unles I am missing anything else in your suggestion.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    In fact, much easier...
    When in form design set the control's locked property to true/yes and then there's no need to call it on load as they'll already be locked!
    Genius
    George
    Home | Blog

  5. #5
    Join Date
    Nov 2003
    Posts
    300
    AHH, the simple things!

    Can't explain why but on other forms that are almost the same they work and this one, I was having problems

    THANKS!!!

Posting Permissions

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