Results 1 to 8 of 8
  1. #1
    VAer's Avatar
    VAer is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Location
    USA
    Posts
    163

    How to unload Current form, and load a different form?

    How to switch from current form to another form?

    The navigation button appears on multiple forms, and the code should be in multiple forms.

    Thanks.

    Code:
    Private Sub NavigationButtonABC_Click()
    
    
    If CurrentProject.AllForms("Login").IsLoaded = True Then
         ' Form is open, do nothing
    Else
        'Unload current form, load form "Login"
    End If
    
    
    
    
    End Sub


  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Load and unload from what? You mean close and open another one?
    Your code suggests you simply want to close some form and open another one, but what is 'current' form? You can close Login form easily enough,
    DoCmd.Close acForm, "Login"
    but what are you wanting to 'unload' after that? Maybe you just want to close and open the same form?
    Last edited by Micron; 09-17-2018 at 11:29 AM. 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.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Code:
    Private Sub NavigationButtonABC_Click()
        If CurrentProject.AllForms("Login").IsLoaded = True Then
         ' Form is open, do nothing
        Else
            'Unload current form, load form "Login"
            docmd.openform "Login"
            docmd.close acform, me.name
        End If
    End Sub

  4. #4
    VAer's Avatar
    VAer is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Location
    USA
    Posts
    163
    Quote Originally Posted by Micron View Post
    Load and unload from what? You mean close and open another one?
    Your code suggests you simply want to close some form and open another one, but what is 'current' form? You can close Login form easily enough,
    DoCmd.Close acForm, "Login"
    but what are you wanting to 'unload' after that? Maybe you just want to close and open the same form?
    Current form means whatever form is visible on computer screen currently. As it states, the navigation button (with the shared code) appears in multiple forms.

    Not close and open the same form. Close the currently opened form (visible on computer screen, but not form Login), then open form Login.

  5. #5
    VAer's Avatar
    VAer is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Location
    USA
    Posts
    163
    Quote Originally Posted by davegri View Post
    Code:
    Private Sub NavigationButtonABC_Click()
        If CurrentProject.AllForms("Login").IsLoaded = True Then
         ' Form is open, do nothing
        Else
            'Unload current form, load form "Login"
            docmd.openform "Login"
            docmd.close acform, me.name
        End If
    End Sub
    Thank you very much!

  6. #6
    VAer's Avatar
    VAer is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Location
    USA
    Posts
    163
    Quote Originally Posted by davegri View Post
    Code:
    Private Sub NavigationButtonABC_Click()
        If CurrentProject.AllForms("Login").IsLoaded = True Then
         ' Form is open, do nothing
        Else
            'Unload current form, load form "Login"
            docmd.openform "Login"
            docmd.close acform, me.name
        End If
    End Sub
    It seems the code If CurrentProject.AllForms("Login").IsLoaded = True does not work properly.

    If I have forms Login and Copy, the navigation button with same code appear on both forms.

    If I click form Login (All Access Objects left nagivate panel), and the form Login is open on the screen. Then if I click form Copy, then form Copy is also opened. When I click the navigation button on form Copy, it does not switch to form Login, since form Login has never been closed before opening form Copy.

    Maybe I need the code to switch form Login to active form, and let form Login appear on screen when clicking the navigation button.

    How to do that?

    Thanks.

    Edit: It seems I need the code SetFocus

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    How to do that?
    Your original post indicated that the code is triggered via a button on a form, and the code will work for that situation.
    However, your latest post is loading forms directly via clicking in the Navigation Pane. That method will never see the original button click code.
    My suggestion is that you do not load any forms via the Navigation Pane. Create a custom menu form and launch all forms from there via buttons.

  8. #8
    VAer's Avatar
    VAer is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Sep 2016
    Location
    USA
    Posts
    163
    Quote Originally Posted by davegri View Post
    Your original post indicated that the code is triggered via a button on a form, and the code will work for that situation.
    However, your latest post is loading forms directly via clicking in the Navigation Pane. That method will never see the original button click code.
    My suggestion is that you do not load any forms via the Navigation Pane. Create a custom menu form and launch all forms from there via buttons.
    As post #6 states, I figured it out, it is the code SetFocus.

    To answer your question, I did NOT load form via Navigation Pane (I just tested the Navigation button code and made sure it works properly), I mean Navigation Buttons inside form (see attached).

    Thanks.
    Attached Thumbnails Attached Thumbnails Nacigation Buttons.JPG  

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

Similar Threads

  1. Replies: 9
    Last Post: 05-30-2017, 04:11 PM
  2. clear rowsource on Form Unload
    By gammaman in forum Modules
    Replies: 5
    Last Post: 07-13-2016, 02:06 PM
  3. Replies: 3
    Last Post: 04-10-2015, 10:26 PM
  4. Replies: 1
    Last Post: 11-18-2014, 12:35 PM
  5. Unload called when opening a form?
    By Kirtap in forum Programming
    Replies: 6
    Last Post: 12-11-2013, 06:23 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