Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    88

    Checkboxes LOCK form Useless

    I have tried different options and have gone a field at a time. I want the form to be disabled as default then enabled once the Edit button is clicked. Everythig works as it should until I enter a 6th checkbox, then the entire form is locked and buttons don't work. I've deleted the code and the form is still locked. I have Enabled and Unlocked the fields within the Property settings but this just work as that and the code/buttons are useless. Here's what I'm doing:

    Private Sub Form_Current()
    'main fields
    Me.txt_Title.Enabled = False
    Me.cmb_Console.Enabled = False
    Me.cmb_Condition.Enabled = False
    Me.txt_Price.Enabled = False
    Me.chk_InCollection.Enabled = False
    Me.chk_Wishlist.Enabled = False
    Me.chk_Favorite.Enabled = False
    Me.chk_Rare.Enabled = False
    Me.txt_Remarks.Enabled = False
    Me.chk_Disc.Enabled = False
    Me.chk_Cartridge.Enabled = False <---this is the one that starts it all...the 6th checkbox locks everything up



    'Bottom buttons
    Me.cmd_New.Enabled = True
    Me.cmd_Save.Enabled = False
    Me.cmd_Cancel.Enabled = False
    Me.cmd_Edit.Enabled = True
    Me.cmd_Delete.Enabled = True
    Me.cmd_Exit.Enabled = True
    End Sub

    I have also used the following and get the same results:

    Private Sub Form_Current()
    Dim ctrl As Control

    'Lock all textboxes
    For Each ctrl In Me.Controls
    If TypeOf ctrl Is TextBox Then
    ctrl.Locked = True
    End If
    Next

    'Lock all checkboxes
    For Each ctrl In Me.Controls
    If TypeOf ctrl Is CheckBox Then
    ctrl.Locked = True
    End If
    Next

    'Lock all drop-down menus
    For Each ctrl In Me.Controls
    If TypeOf ctrl Is ComboBox Then
    ctrl.Locked = True
    End If
    Next

    'Bottom buttons
    Me.cmd_New.Enabled = True
    Me.cmd_Save.Enabled = False
    Me.cmd_Cancel.Enabled = False
    Me.cmd_Edit.Enabled = True
    End Sub

    Either will lock the form useless even when no code is in it at all, and I have to start from scratch just to end up here.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Please post code within CODE tags to retain indentation and readability.

    Other than simplifying code so there is only 1 loop through all controls, don't see anything wrong.
    Code:
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Or TypeOf ctrl Is CheckBox Or TypeOf ctrl Is ComboBox Then ctrl.Locked = True
    Next
    But that will probably still cause the lockup issue.

    I am not able to replicate issue. If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    much easier to set Allow Edits, Allow Additions and Allow Deletions to false, or alter the recordsettype property?
    I also can't see any issue, notwithstanding that there's much code for this. Perhaps the problem control has code associated with it, but I cannot think of an event that would fire by being disabled.
    Last edited by Micron; 06-12-2019 at 04:07 PM. Reason: spelin and gramur
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Quote Originally Posted by June7 View Post
    Please post code within CODE tags to retain indentation and readability.
    FYI - You have asked this person to do that at least once before.

  5. #5
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    88

    DB for Analysis

    DB for Analysis

    retrogamesDB.zip

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Instead of repeating the control code, put it in its own Sub and call that Sub in each event procedure as needed.
    Code:
    Private Sub SetControls(booEnable As Boolean)
    Dim ctrl As Control
        For Each ctrl In Me.Controls
            If ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox Or ctrl.ControlType = acCheckBox Then
                With ctrl
                    .Enabled = booEnable
                End With
            End If
        Next
    End Sub
    Move DoCmd.GoToRecord , , acNewRec to end of procedure
    Code:
    Private Sub cmd_New_click()
        SetControls (True)
        DoCmd.GoToRecord , , acNewRec
    End Sub
    Code:
    Private Sub Form_Load()
        DoCmd.SetOrderBy "Consoles, ASC, title, ASC"
        SetControls (False)
    End Sub
    There are only 4 checkboxes on form.

    I set breakpoint in Current event code it never executes. I generally avoid Split form but have used it twice for very simple, very small db.

    Still can't explain why New button is not enabled when form opens.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    It is a split form, and you put all your buttons in the detail section. No can do (well you did, but not much will work).
    You will have to select all, cut, and paste in footer (or header) and reconnect all of the events one by one.

    After doing so, it is very unstable. If I 'edit' I can use navigation controls to move from record to record, 'editing' as I go and detail record becomes the current record (in the bottom) and top view is enabled. Click on another record in the bottom and it crashes every time.

    You can try compact/repair or decompile switch on open on your db, but I'd say I'm not surprised by the result. A split form is supposed to be provide 2 views of the same data - single and datasheet. Each view is comprised of the same fields. It would seem Access doesn't like it if you select a locked datasheet record while the 'single view' record is enabled. When you think of it, there's no way you could do that in a single form view (select the next record while maintaining the view of the current one, especially with one locked and the other not) so maybe that's why the crash every time.

    If it works for you after fixing the control positions I'd sure like to know.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Okay, moving button into header section makes a big difference. And now the Current event runs.

    I simply dragged button into header section and code works.

    Current event runs after button click event so the controls are not available after clicking New button. I removed code from Current event.

    I am not getting the crash.

    Frankly, I really don't see any benefit to disabling all data controls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    88
    Quote Originally Posted by June7 View Post
    Okay, moving button into header section makes a big difference. And now the Current event runs.

    I simply dragged button into header section and code works.

    Current event runs after button click event so the controls are not available after clicking New button. I removed code from Current event.

    I am not getting the crash.

    Frankly, I really don't see any benefit to disabling all data controls.
    Copy...thank you all for your great help and explanations. I will do the changes and reply if I get it to work. FYI, I like having some buttons disabled until I need them due to human error. I understand is not a normal thing to do but with my Access 2003 everything worked as I need it. Now with 2016 version all became locked. Again thank you all as I continue learning.

    UPDATE:
    Well after working around with the suggestions in this post I found out that having the split-form is a no-go for Access 2016 (Micron). I will have to re-install my old copy of 2003 and see why it works there and not in this new version of Access. Thanks again!
    Last edited by ortizimo; 06-13-2019 at 08:42 AM.

  10. #10
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I am not getting the crash.
    you replicated my actions: navigating, unlocking (edit click) then selecting a locked one from the datasheet and no crash?

  11. #11
    ortizimo is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jun 2017
    Location
    FL
    Posts
    88
    i still get the crash but found out it was the split-form doing the hold-up/lock. in 2003 works fine (old db)...in 2016 split is no-go. will investigate further once I re-install 2003 in a VM tonight. thnx

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    @Micron, tried that and still no crash. After clicking Edit, the datasheet is not locked so no problem selecting another record, which is then locked by Current code.

    I do wonder how the 2003 version works because having code in Current event interferes with New Record.

    Also, acCmdSave is wrong command, should be acCmdSaveRecord. Maybe better to use Dirty. Review http://allenbrowne.com/bug-01.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    if datasheet isn't locked, then I'm not surprised it didn't crash, and if it didn't lock the datasheet, is that because your alterations were different than mine or is it a version thing?
    I'm not really looking for an answer because this isn't something I'll ever do.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can't say. Code to set controls is still called from same events.

    I have also never done to this degree. I have locked some controls that should not be available until another control has input. I have also locked/hidden buttons until they are relevant to the process.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    irish634 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2012
    Posts
    48
    Quote Originally Posted by ortizimo View Post
    I have tried different options and have gone a field at a time. I want the form to be disabled as default then enabled once the Edit button is clicked.
    Why don't you just toggle the 'AllowEdits' and 'AllowDeletions' properties on the form?

    In design mode, set the form properties:
    AllowAdditions = True
    AllowEdits = False
    AllowDeletions = False

    Then just toggle them:

    If you have an 'edit' button do something like this:
    Code:
    Private Sub cmd_Edit_Click()
    
        Me.AllowEdits = True
        Me.AllowDeletions = True
        
    End Sub
    Then when you click a 'save' button do the opposite:
    Code:
    Private Sub cmd_Save_Click()
    
        Me.AllowEdits = False
        Me.AllowDeletions = False
        
    End Sub
    It just seems to me you are going through an awful lot of programming when this may suffice...

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 11-13-2017, 02:09 PM
  2. Clear all checkboxes on form
    By Tommo in forum Modules
    Replies: 6
    Last Post: 10-08-2015, 03:04 PM
  3. How to loop through all checkboxes on form?
    By archaeofreak in forum Programming
    Replies: 9
    Last Post: 09-16-2013, 01:55 PM
  4. Disable Checkboxes for a row in Form
    By seshan in forum Programming
    Replies: 1
    Last Post: 02-05-2010, 07:36 PM
  5. Useless and needs help
    By asmith61 in forum Access
    Replies: 1
    Last Post: 08-10-2009, 07:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums