Results 1 to 3 of 3
  1. #1
    Tenmakk is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    35

    Using a navigation control to organize several forms

    Hello, I have several forms on my Access project. It would be very convenient if I could organize all the forms using the navigation control so I just have to click on a tab (instead of the left navigation pane) to get the form to load. I saw this on a YouTube video, but it didn't explain how to do it. Would I need to redo my forms and change them to subforms on the navigation control? How would I do this? Where do I start?



    Thanks,
    Brad

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    Personally, I don't like the navigation form approach. It gets very sticky when you need hierarchical interform communications. Instead, I would create a new form, say frmControl, and put buttons on that form to call up your other forms. Here's code for the buttons to call. You can hide frmControl when it loads another form. When the other form closes it can use the sub to call back frmControl. The code needs to go in a MODULE.
    Code:
    '------------------------------------------------------------------------
    ' Sub will hide current form and load/make visible a selected form.
    ' Params:    GetForm - String name of form to swap to.
    '           ToControl - String control name to get focus in new form.
    '                       Set to zero length string ( vbnullstring ) if none.
    '           Disp - Disposition of calling form
    '                  "CLOSE" = Close calling form
    '                  "KEEP"  = Leave calling form unhidden
    '                  Anything else including nullstring = hide calling form
    ' 
    '------------------------------------------------------------------------
    Public Sub subSwapForm(GetForm As String, Optional ToControl As String, Optional Disp As String)
        On Error GoTo LogErr
        Dim i As Integer, IsLoaded  As Integer
        IsLoaded = False
        Select Case Disp
            Case "CLOSE"
                Dim cf As Form
                Set cf = Screen.ActiveForm
                DoCmd.Close acForm, cf.Name
                Set cf = Nothing
            Case ""
                Screen.ActiveForm.Visible = False
            Case "KEEP"
            Case Else
        End Select
        For i = 0 To Forms.Count - 1
            If Forms(i).FormName = GetForm Then
                IsLoaded = True
                Exit For
            End If
        Next
        If IsLoaded = True Then
            Forms(i).Visible = True
        Else
            DoCmd.OpenForm GetForm
        End If
        If Len(ToControl) > 0 Then DoCmd.GoToControl ToControl
    subSwapForm_exit:
        Exit Sub
    LogErr:
        If Err = 2475 Then Resume Next
        msgbox Err.Number & ", " & Err.Description & " subSwapForm of " & Name
        Resume subSwapForm_exit
    End Sub
    Last edited by davegri; 06-04-2016 at 04:25 PM. Reason: clarity

  3. #3
    Tenmakk is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    35
    Great. Thank you, I'm working on it.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-03-2022, 12:39 PM
  2. Replies: 3
    Last Post: 03-23-2016, 12:45 PM
  3. Replies: 2
    Last Post: 11-27-2014, 01:06 PM
  4. Replies: 5
    Last Post: 09-05-2014, 12:59 PM
  5. Replies: 2
    Last Post: 08-09-2014, 04:27 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