Results 1 to 16 of 16

Issue with multipage form page changes

Threaded View

jerH Issue with multipage form... 01-06-2016, 10:34 PM
Leith Ross Re: Issue with multipage form... 01-06-2016, 11:31 PM
jerH Re: Issue with multipage form... 01-06-2016, 11:38 PM
jerH Re: Issue with multipage form... 01-07-2016, 10:37 AM
mikerickson Re: Issue with multipage form... 01-07-2016, 10:45 AM
jerH Re: Issue with multipage form... 01-07-2016, 11:01 AM
jerH Re: Issue with multipage form... 01-07-2016, 01:13 PM
mikerickson Re: Issue with multipage form... 01-07-2016, 03:10 PM
jerH Re: Issue with multipage form... 01-07-2016, 03:15 PM
jerH Re: Issue with multipage form... 01-07-2016, 03:16 PM
jerH Re: Issue with multipage form... 01-07-2016, 05:32 PM
mikerickson Re: Issue with multipage form... 01-07-2016, 05:32 PM
jerH Re: Issue with multipage form... 01-07-2016, 05:41 PM
mikerickson Re: Issue with multipage form... 01-07-2016, 09:34 PM
jerH Re: Issue with multipage form... 01-07-2016, 10:22 PM
jerH Re: Issue with multipage form... 01-11-2016, 10:05 AM
  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Dayton, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    33

    Issue with multipage form page changes

    I suspect this may be a long post...apologies in advance.

    I have a multipage form with 12 tabs (index 0-11) designed for use by users to enter data for a model. That was fine, but then they asked for the ability to have it also edit previous entries, and I'm having a weird issue with one of the event handlers that I use to read in old data.

    The issue starts on this tab, which is index 3

    ROIpage.JPG

    If the YES radio button under Common Repairable is selected, the event handler takes them over to another tab

    CommonalityPage.JPG

    (which is index 9) to enter some additional data, and then come back. This works fine for new data entry, but the issue comes in when they're editing a previous entry. Here's how it should work...

    This is the event handler for whenever there is a page change:

    Private Sub MultiPage1_Change()
    
        Dim i As Integer
        Dim num_alternatives As Integer
        Dim found As Boolean
        Dim SearchSheet As Worksheet
        Dim PreviousSORs As String
        Dim ArmySORs(1 To 8) As String
        Dim AirForceSORs(1 To 3) As String
        Dim NavySORs(1 To 26) As String
        Dim MarineSORs(1 To 2) As String
        Dim OtherSOROptions(1 To 6) As String
        Dim Army As Boolean
        Dim Navy As Boolean
        Dim AirForce As Boolean
        Dim Marines As Boolean
        Dim Other As Boolean
    
    
        'this handler gets called every time there is a change to a new page
        'we'll use this to handle a lot of the functions associated with editing an alternative
        'every time there is a page change, we check to see if we're editing, and if so, we do anything that needs to be done on that page
        
        If EnableEvents = False Then
            Exit Sub
        End If
        
        
        If (MultiPage1.Value = 1) And (CurrentFunction = "Edit") Then
            'we're editing, and we're on the Existing Capabilities page, so we need to check for MILCON,
            
            If ((comboFacilities.ListIndex = 1) Or (comboFacilities.ListIndex = 2)) Then
                'there's a choice that requires MILCON - make sure they're happy with the current amount
                
                num_alternatives = Sheets("Tactical").Range("AG1").Value
                found = False
        
                For i = 1 To num_alternatives
                    If Sheets("Tactical Ancillary").Range("A1").Offset(i).Value = edit_alternative_name Then
                        found = True
                        Exit For
                    End If
                Next i
        
                If Not found Then
                    MsgBox "Error in Page Change Event Handler - Facilities.  Alternative Not Found.", vbCritical, "Error"
                    Exit Sub
                End If
        
                milcon_required = InputBox("Estimated facility MILCON requirement. Enter 0 if not available.", "Estimated MILCON Requirement", Sheets("Tactical Ancillary").Range("P1").Offset(i).Value)
            End If
        ElseIf (MultiPage1.Value = 2) And (CurrentFunction = "Edit") And (CurrentModelType = "Tactical") Then
            'we're editing, and we're on the Strategic Posturing page, so we need to see if they said Tech Data couldn't be purchased - only for tactical alternatives
                
            num_alternatives = Sheets("Tactical").Range("AG1").Value
            found = False
    
            For i = 1 To num_alternatives
                If Sheets("Tactical Ancillary").Range("A1").Offset(i).Value = edit_alternative_name Then
                    found = True
                    Exit For
                End If
            Next i
    
            If Not found Then
                MsgBox "Error in Tech Orders Change Event Handler.  Tactical alternative Not Found.", vbCritical, "Error"
                Exit Sub
            End If
    
            'get the values from the existing entry
            legal_office = Sheets("Tactical Ancillary").Range("Q1").Offset(i).Value
            If legal_office = "Not Contacted" Then
                'blank it out
                legal_office = ""
            End If
    
            legal_date = Sheets("Tactical Ancillary").Range("R1").Offset(i).Value
            If legal_date = "N/A" Then
                'blank it out
                legal_date = ""
            End If
    
            legal_date = InputBox("Please enter the date legal was contacted.  Leave blank if unknown:", "Legal Contact Date", legal_date)
            legal_office = InputBox("Please enter the office symbol of the legal office contacted. Leave blank if unknown:", "Legal Office", legal_office)
        
            
        ElseIf (MultiPage1.Value = 3) And CurrentFunction = "Edit" Then
            'we're editing, and we're on the ROI page, so we need to do the common repairable check
            If (Not DoneEditingCommon) And optCommonRepairable_Yes.Value = True Then
                'the DoneEditingCommon flag keeps us from getting caught in a loop every time we change back to this page
                EnableEvents = False
                
                MultiPage1.Pages(9).Visible = True
                MultiPage1.Value = 9
                
                For i = 0 To 8
                    MultiPage1.Pages(i).Visible = False
                Next i
                            
                MultiPage1.Pages(10).Visible = False
                MultiPage1.Pages(11).Visible = False
                            
                EnableEvents = True
                setup_common_form
            End If
            
        ElseIf (MultiPage1.Value = 5) And CurrentFunction = "Edit" Then
            'we're editing, and we're on the first Additional Data page, so we need to check the Organic SOR for "other"
            'this is pain - need to prepopulate their prior selections
            If CurrentModelType = "Tactical" Then
                num_alternatives = Sheets("Tactical").Range("AG1").Value
                Set SearchSheet = Sheets("Tactical Ancillary")
            Else
                num_alternatives = Sheets("Strategic").Range("AG1").Value
                Set SearchSheet = Sheets("Strategic Ancillary")
            End If
    
            found = False
    
            For i = 1 To num_alternatives
                If SearchSheet.Range("A1").Offset(i).Value = edit_alternative_name Then
                    found = True
                    Exit For
                End If
            Next i
    
            If Not found Then
                MsgBox "Error in Organic SOR Change Event Handler.  Alternative Not Found.", vbCritical, "Error"
                Exit Sub
            End If
    
            If CurrentModelType = "Tactical" Then
                PreviousSORs = SearchSheet.Range("H1").Offset(i).Value
            Else
                PreviousSORs = SearchSheet.Range("F1").Offset(i).Value
            End If
    
    
            'now the fun part - need to determine which options to pre-populate
            'build some arrays of all the depot source of repairs
            ArmySORs(1) = "Anniston Army Depot (ANAD), AL"
            ArmySORs(2) = "Corpus Christi Army Depot (CCAD), TX"
            ArmySORs(3) = "Pine Bluff Arsenal, AR"
            ArmySORs(4) = "Letterkenny Army Depot (LEAD), Chambersburg, PA"
            ArmySORs(5) = "Pirmasens Army Depot, Pirmasens, Germany"
            ArmySORs(6) = "Red River Army Depot (RRAD), Texarkana, TX"
            ArmySORs(7) = "Sierra Army Depot, Herlong, CA"
            ArmySORs(8) = "Tobyhanna Army Depot (TYAD), PA"
    
            NavySORs(1) = "Naval Surface Warfare Center, Carderock Division (NSWCCD), West Bethesda, MD"
            NavySORs(2) = "Combat Directions Systems Activity (CDSA) Dam Deck, NSWC Dahlgren Division, Virginia Beach, VA"
            NavySORs(3) = "Space and Naval Warfare Systems Center Atlantic (SSC LANT), Charleston, SC"
            NavySORs(4) = "Naval Air Warfare Center, Weapons Division, China Lake CA"""
            NavySORs(5) = "Fleet Readiness Center East (FRC-E), Cherry Point NC"
            NavySORs(6) = "Naval Surface Warfare Center (NSWC), Crane Division, Crane IN"
            NavySORs(7) = "Weapons Support Facility Yorktown, Detachment Earle, Colts Neck NJ"
            NavySORs(8) = "Space and Naval Warfare Systems Center Atlantic (SSC LANT), Portsmouth, VA"
            NavySORs(9) = "Space and Naval Warfare Systems Center Pacific (SSC PAC), San Diego, CA"
            NavySORs(10) = "Naval Surface Warfare Center (NSWC), Indian Head Division, Indian Head MD"
            NavySORs(11) = "Fleet Readiness Center South East (FRC-SE), Jacksonville FL"
            NavySORs(12) = "Naval Air Warfare Center, Aircraft Division, Lakehurst, Lakehurst NJ"
            NavySORs(13) = "Fleet Readiness Center, South West (FRC-SW), North Island, San Diego CA"
            NavySORs(14) = "Naval Shipyard (NSY) Norfolk, Portsmouth VA"
            NavySORs(15) = "Naval Undersea Warfare Center (NUWC), Newport Division, Newport, RI"
            NavySORs(16) = "Naval Explosive Ordnance Disposal Technology Center (NEOTC), Indian Head MD"
            NavySORs(17) = "Naval Surface Warfare Center (NSWC), Corona Division, Corona, CA"
            NavySORs(18) = "Naval Air Warfare Center, Weapons Division, Point Mugu, Point Mugu, CA"
            NavySORs(19) = "Puget Sound Naval Shipyard and Intermediate Maintenance Facility (PSNSY & IMF), Bremerton WA"
            NavySORs(20) = "Naval Shipyard (NSY) Portsmouth NH"
            NavySORs(21) = "Naval Air Warfare Center, Aircraft Division, Patuxent River MD (St. Inigoes)"
            NavySORs(22) = "Naval Undersea Warfare Center (NUWC), Keyport Division, Keyport, WA"
            NavySORs(23) = "Weapons Support Facility Yorktown, Detachment Charleston, Charleston SC"
            NavySORs(24) = "Naval Munitions Command CONUS East Division Detachment  Yorktown, Yorktown VA"
            NavySORs(25) = "Pearl Harbor Naval Shipyard and Intermediate Maintenance Facility (PHNSY & IMF),Pearl Harbor, HI"
            NavySORs(26) = "Naval Surface Warfare Center (NSWC), Panama City Division, Panama City FL"
    
            AirForceSORs(1) = "Aerospace Maintenance and Regeneration Center (AMARC), Davis Monthan AFB, AZ"
            AirForceSORs(2) = "Support Center Pacific (SCP), Kadena, Japan"
            AirForceSORs(3) = "Cryptologic Systems Group (CPSG), Lackland AFB, TX"
    
            MarineSORs(1) = "Maintenance Center Albany (MCA), Marine Corps Logistics Command (MCLC), Albany, GA"
            MarineSORs(2) = "Maintenance Center Barstow (MCB), Marine Corps Logistics Base (MCLB), Barstow, CA"
    
            OtherSOROptions(1) = "Contract, Contiguous United States (CONUS)"
            OtherSOROptions(2) = "Contract, Overseas and Noncontiguous United States (OCONUS)"
            OtherSOROptions(3) = "Industrial Plant Equipment Repair Facility, Mechanicsburg, PA"
            OtherSOROptions(4) = "Federal Aviation Agency, Mike Monroney Aeronautical Center, Oklahoma City, OK"
            OtherSOROptions(5) = "North Atlantic Treaty Organization (NATO) Maintenance and Supply Agency (NAMSA), Luxembourg City, Luxembourg"
            OtherSOROptions(6) = "National Oceanographic and Atmospheric Administration, National Weather Service (NWS), National Reconditioning Center, Kansas City, MO"
    
            'now look to see which of these is present in the string
            Army = False
            For i = 1 To UBound(ArmySORs)
                If InStr(1, PreviousSORs, ArmySORs(i)) Then
                    Army = True
                    Exit For
                End If
            Next i
    
            Navy = False
            For i = 1 To UBound(NavySORs)
                If InStr(1, PreviousSORs, NavySORs(i)) Then
                    Navy = True
                    Exit For
                End If
            Next i
    
            Marines = False
            For i = 1 To UBound(MarineSORs)
                If InStr(1, PreviousSORs, MarineSORs(i)) Then
                    Marines = True
                    Exit For
                End If
            Next i
    
            AirForce = False
            For i = 1 To UBound(AirForceSORs)
                If InStr(1, PreviousSORs, AirForceSORs(i)) Then
                    AirForce = True
                    Exit For
                End If
            Next i
    
            Other = False
            For i = 1 To UBound(OtherSOROptions)
                If InStr(1, PreviousSORs, OtherSOROptions(i)) Then
                    Other = True
                    Exit For
                End If
            Next i
    
            'now we can pre-populate the check boxes
            If Army Then
                chkArmy.Value = True
            End If
    
            If Navy Then
                chkNavy.Value = True
            End If
    
            If AirForce Then
                chkAF.Value = True
            End If
    
            If Marines Then
                chkMarines.Value = True
            End If
    
            If Other Then
                chkOther.Value = True
            End If
    
            'now call the Populate button click handler to populate the list box
            btnPopulate_Click
    
            'now go through whatever has wound up in the list box, and if it is also in the string, select it
            For i = 0 To lstSORs.ListCount - 1
                If InStr(1, PreviousSORs, lstSORs.List(i)) Then
                    'this item in the listbox is in the list of previous SORs, so select it
                    lstSORs.Selected(i) = True
                End If
            Next i
    
            'switch to the additional SOR entry page
            EnableEvents = False
            For i = 0 To 9
                MultiPage1.Pages(i).Visible = False
            Next i
            MultiPage1.Pages(11).Visible = False
    
            lblSOR_AlternativeName.Caption = edit_alternative_name
            lstSORs.Visible = False
            btnSORSave.Visible = False
    
            MultiPage1.Pages(10).Visible = True
            MultiPage1.Value = 10
            EnableEvents = True
        End If
    End Sub
    The important block of code is

        ElseIf (MultiPage1.Value = 3) And CurrentFunction = "Edit" Then
            'we're editing, and we're on the ROI page, so we need to do the common repairable check
            If (Not DoneEditingCommon) And optCommonRepairable_Yes.Value = True Then
                'the DoneEditingCommon flag keeps us from getting caught in a loop every time we change back to this page
                EnableEvents = False
                
                MultiPage1.Pages(9).Visible = True
                MultiPage1.Value = 9
                
                For i = 0 To 8
                    MultiPage1.Pages(i).Visible = False
                Next i
                            
                MultiPage1.Pages(10).Visible = False
                MultiPage1.Pages(11).Visible = False
                            
                EnableEvents = True
                setup_common_form
            End If
    So if we're on page 3, and we're in the edit mode, the code should
    -- make tab index 9 visible
    -- switch to tab index 9
    -- make all the other tabs invisible

    But here's a screen shot from when I stepped through that code in the debugger

    ErrorROIPage.JPG

    You'll note that the tab title is "Commonality" which is the title of tab index 9, but the contents of the tab are still index 3.

    What's even more bizarre is that if I click the next button in the lower right, whose handler just says multipage1.value = multipage1.value + 1, then I'm suddenly taken to the correct tab 9. What's going on?
    Attached Images Attached Images

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how to switch multipage page from multipage change event??
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2015, 10:31 AM
  2. Replies: 4
    Last Post: 08-28-2014, 02:23 AM
  3. [SOLVED] ActiveControl - Return non-Multipage control when Form contains Multipage?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2014, 08:37 PM
  4. [SOLVED] MultiPage Form / cell to show active page
    By ckk403 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2012, 04:02 PM
  5. Changing the Color of Page on a MultiPage Form
    By NaNaBoo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-31-2009, 04:21 AM
  6. Multipage form: Referencing controls on one page
    By Post Tenebras Lux in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2006, 02:45 PM
  7. Adding controls to each page in a multipage form
    By michael fuller in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2006, 05:50 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1