Results 1 to 6 of 6
  1. #1
    ecampos is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    9

    Subforms don't load after pressing Escape key

    I have a "back" button on a navigation form. Whenever a form is loaded it's name is saved in a global variable. And the back button navigates to the last opened form.



    Code:
    Public Sub NavForm(ByVal form_name As String)
        If Not CurrentProject.AllForms("Navigation").IsLoaded Then OpenForm "Navigation"
        If form_name <> CurrentNav Then LastNav = CurrentNav
        CurrentNav = form_name
        [Forms]![Navigation].ActiveForm.SourceObject = "Form." & form_name
    End Sub
    
    
    Private Sub cmdBack_Click()
        If Nz(LastNav) <> "" Then NavForm LastNav
    End Sub
    This works perfectly. However, I recently set cmdBack.Cancel = Yes so that I can use the escape key as a shortcut for the back button. Now when I press ESC the correct form is loaded, but if said form has a subform on it the subform will show up empty. If there is more than one subform only one of them will show up blank and the others will load just fine. If I refresh the form the subform loads fine, if I click on the back button with the mouse the subforms always load fine. This only happens when I press the ESC key. Can anyone explain to me the mechanism that is causing this? I am assuming it has to do with me holding the ESC down while the form is loading. Is there any way to work around this?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    IIRC esc is equivalent to Undo so maybe something is dumped or lost and that affects the subform recordset. I'd say that most experienced developers wont' use navigation forms because of their limitations, but to add to that, what you're doing doesn't make any sense the way I'm interpreting your post. Nav form has a set of navigation buttons in a control. Choosing one button or the other simply loads whatever form it's associated with so why have a button to call back the last form when you can simply choose that button? Also, the nature of nav form is that only one form at a time can be loaded, so when you select another button (or however you're going to load the next form) all ties to that form are lost when it closes. That might be an additional factor responsible for your issue, but that's just a guess.
    Last edited by Micron; 06-06-2022 at 10:53 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ecampos is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    9
    IIRC esc is equivalent to Undo so maybe something is dumped or lost and that affects the subform recordset.
    This is what I am assuming as well. Looking for a technical description of the mechanism that might be causing this, so that I can work around it.

    I'd say that most experienced developers wont' use navigation forms because of their limitations
    What limitations?

    what you're doing doesn't make any sense the way I'm interpreting your post. Nav form has a set of navigation buttons in a control. Choosing one button or the other simply loads whatever form it's associated with so why have a button to call back the last form when you can simply choose that button?
    This application has dozens of forms. There will be over 100 by the time I am finished. The navigation form has short cuts to 7-8 high level "dashboard" type forms. The user might be on a form 3 levels deep and want to glance at one of the dashboards, and then return to the last form they were using without having to navigate through the tree again. That's what the back button is for.

    Also, the nature of nav form is that only one form at a time can be loaded, so when you select another button (or however you're going to load the next form) all ties to that form are lost when it closes. That might be an additional factor responsible for your issue, but that's just a guess.
    The only thing that is causing this issue is the ESC key. If I click on the Back button control with the mouse everything works fine. This back button is just a command button that navigates to a form. Which form it loads just happens to change.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    What limitations?
    - only one form can be open at a time
    - loaded form is always a subform; not a limitation per se, but certainly complicates references
    - cannot pass openArgs to next form
    - cannot apply form filter to next form
    - cannot set recordsource of next form if you want to make it dynamic
    - cannot refer back to prior form to retrieve any value
    - cannot use next form (e.g. popup for input) for things like adding control rowsource data and then return back to prior form

    Sure you can probably code around some of these limitations, such as exposing public variables which are then subject to undesired modification. If you're happy using them then by all means have at it.

    If I click on the Back button control with the mouse everything works fine
    As you said before. But that is not equivalent to Undo.
    I recently set cmdBack.Cancel = Yes
    A command button click event has no cancel parameter so I don't see how that line can help.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    ecampos is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    9
    Quote Originally Posted by Micron View Post
    - only one form can be open at a time
    - loaded form is always a subform; not a limitation per se, but certainly complicates references
    - cannot pass openArgs to next form
    - cannot apply form filter to next form
    ......
    Of course you are limited to one form at a time. That's a design decision that is made based on the requirements of the underlying data. The rest of these are so trivial to work around that I wouldn't call them limitations. I am sure there are applications that would benefit from a design that allows the user to open multiple forms at one time. But I don't see why any of this would cause most 'experienced' developers to eschew navigation forms completely. Nor do I understand how my initial question prompted your answer.



    As you said before. But that is not equivalent to Undo.
    Yes that's clear, I repeated myself in response to this comment:
    Also, the nature of nav form is that only one form at a time can be loaded, so when you select another button (or however you're going to load the next form) all ties to that form are lost when it closes. That might be an additional factor responsible for your issue, but that's just a guess.
    To be clear, the only factor causing this issue is the pressing of the escape key. The entirety of my question could be summed up as: What happens when you press the ESC key while a form is loading?



    A command button click event has no cancel parameter so I don't see how that line can help.
    The command button itself has a cancel parameter. Setting it to 'Yes' links that button to the ESC key.

  6. #6
    ecampos is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Posts
    9

    Solved

    I was able to mimic this behavior without canceling the subforms from loading by using the Form_KeyUp event. So that the form isn't loaded until after the escape key has been released.

    Code:
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
        If KeyCode = 27 Then
            'insert navigation code here
        End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. accidentally hit escape key in a form
    By paul7555 in forum Access
    Replies: 3
    Last Post: 04-11-2019, 03:35 PM
  2. Replies: 1
    Last Post: 04-24-2018, 04:45 PM
  3. Using the escape key to exit forms
    By joecamel9166 in forum Forms
    Replies: 9
    Last Post: 06-01-2016, 07:27 AM
  4. Parameter prompts when subforms load
    By jzacharias in forum Forms
    Replies: 2
    Last Post: 06-30-2015, 01:42 PM
  5. Update ControlField for Subforms on Load
    By Meanfish in forum Programming
    Replies: 1
    Last Post: 11-05-2012, 01:02 PM

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