Update Forms Module Logic Error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brilstern
    New Member
    • Dec 2011
    • 208

    #1

    Update Forms Module Logic Error?

    I have developed a login module and one of the functions of it is to iterate through all forms changing the Forms(obj.Name) .ShortcutMenu property to true or false depending on the access level.

    This works well for the latter half of the process which is locking them all down, but for some reason I have a logic error in setting the property value to true. Thoughts?

    I have already tried debugging inside of the For loop and it iterates through each form in the Admin/Design Case, it just doesn't seem to change the property value to true...

    Code:
    Public Function UpdateForms()
    
        'On Error Resume Next
        Dim obj As AccessObject, dbs As Object
        Set dbs = Application.CurrentProject
        
        Select Case strGlobalAccess
        
            Case "Administrator", "Design"
            
                'Search for open AccessObject objects in AllForms collection.
                For Each obj In dbs.AllForms
                
                    If obj.Name <> "frmBackground" Then
                        
                        DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
                        Forms(obj.Name).ShortcutMenu = True
                        DoCmd.Close acForm, obj.Name, acSaveYes
                                        
                    End If
            
                Next obj
                DoCmd.OpenForm strHomePage
                Exit Function
                        
            Case Else
                'Search for open AccessObject objects in AllForms collection.
                For Each obj In dbs.AllForms
                
                    If obj.Name <> "frmBackground" Then
                        DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
                        Forms(obj.Name).ShortcutMenu = False
                        DoCmd.Close acForm, obj.Name, acSaveYes
                    End If
            
                Next obj
                Exit Function
                
            End Select
                
    End Function
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    This bit of code might put you on the right track

    Code:
    Public Function UpdateForms()
     
        'On Error Resume Next
        Dim FrmName As String
        Dim Frm As Form
        Dim i As Integer
     
        For i = 0 To CurrentProject.AllForms.Count - 1
            FrmName = CurrentProject.AllForms(i).Name
            If FrmName = "Address" Then                ' Named form found
                DoCmd.OpenForm FrmName, acDesign, , , , acHidden
                Set Frm = Forms(FrmName)
                Frm.ShortcutMenu = True
                DoCmd.Close acForm, FrmName, acSaveYes
                Set Frm = Nothing
            End If
        Next i
     
    End Function
    Obviously this is designed just to change my Address form. You would need to change it to <> frmBackground

    Phil

    Comment

    • Brilstern
      New Member
      • Dec 2011
      • 208

      #3
      Thanks for the reply Phil! Checking it now. Any thoughts on why my approach is not working?

      Comment

      • Brilstern
        New Member
        • Dec 2011
        • 208

        #4
        Ok so I implemented your solution and to no avail... same result. It iterates through the code and runs it, but it still doesn't allow me to use the Shortcut Menu. Quite weird.

        Code:
        Public Function UpdateForms()
        
            'On Error Resume Next
            Dim FrmName As String
            Dim Frm As Form
            Dim i As Integer
         
            Select Case strGlobalAccess
            
                Case "Administrator", "Design"
                
                    'Search for open AccessObject objects in AllForms collection.
                    For i = 0 To CurrentProject.AllForms.Count - 1
                        
                        FrmName = CurrentProject.AllForms(i).Name
                        If FrmName <> "frmBackground" Then
                            DoCmd.OpenForm FrmName, acDesign, , , , acHidden
                            Set Frm = Forms(FrmName)
                            Frm.ShortcutMenu = True
                            DoCmd.Close acForm, FrmName, acSaveYes
                            Set Frm = Nothing
                        
                        End If
                    
                    Next i
                    DoCmd.OpenForm strHomePage
                    Exit Function
            
                Case Else
                
                    'Search for open AccessObject objects in AllForms collection.
                    For i = 0 To CurrentProject.AllForms.Count - 1
                        
                        FrmName = CurrentProject.AllForms(i).Name
                        If FrmName <> "frmBackground" Then
                            
                            DoCmd.OpenForm FrmName, acDesign, , , , acHidden
                            Set Frm = Forms(FrmName)
                            Frm.ShortcutMenu = False
                            DoCmd.Close acForm, FrmName, acSaveYes
                            Set Frm = Nothing
                        
                        End If
                    
                    Next i
                    Exit Function
                    
                End Select
                    
        End Function

        Comment

        • PhilOfWalton
          Recognized Expert Top Contributor
          • Mar 2016
          • 1430

          #5
          Manually change the value of AllowShortcut Menues an d then check if the code is changing the value of AllowShotcut Menus on all the forms to the correct setting.

          Phil

          Comment

          Working...