By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,222 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,222 IT Pros & Developers. It's quick & easy.

Update Forms Module Logic Error?

Brilstern
100+
P: 207
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...

Expand|Select|Wrap|Line Numbers
  1. Public Function UpdateForms()
  2.  
  3.     'On Error Resume Next
  4.     Dim obj As AccessObject, dbs As Object
  5.     Set dbs = Application.CurrentProject
  6.  
  7.     Select Case strGlobalAccess
  8.  
  9.         Case "Administrator", "Design"
  10.  
  11.             'Search for open AccessObject objects in AllForms collection.
  12.             For Each obj In dbs.AllForms
  13.  
  14.                 If obj.Name <> "frmBackground" Then
  15.  
  16.                     DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
  17.                     Forms(obj.Name).ShortcutMenu = True
  18.                     DoCmd.Close acForm, obj.Name, acSaveYes
  19.  
  20.                 End If
  21.  
  22.             Next obj
  23.             DoCmd.OpenForm strHomePage
  24.             Exit Function
  25.  
  26.         Case Else
  27.             'Search for open AccessObject objects in AllForms collection.
  28.             For Each obj In dbs.AllForms
  29.  
  30.                 If obj.Name <> "frmBackground" Then
  31.                     DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
  32.                     Forms(obj.Name).ShortcutMenu = False
  33.                     DoCmd.Close acForm, obj.Name, acSaveYes
  34.                 End If
  35.  
  36.             Next obj
  37.             Exit Function
  38.  
  39.         End Select
  40.  
  41. End Function
Mar 3 '17 #1
Share this Question
Share on Google+
4 Replies


PhilOfWalton
Expert 100+
P: 1,430
This bit of code might put you on the right track

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function UpdateForms()
  3.  
  4.     'On Error Resume Next
  5.     Dim FrmName As String
  6.     Dim Frm As Form
  7.     Dim i As Integer
  8.  
  9.     For i = 0 To CurrentProject.AllForms.Count - 1
  10.         FrmName = CurrentProject.AllForms(i).Name
  11.         If FrmName = "Address" Then                ' Named form found
  12.             DoCmd.OpenForm FrmName, acDesign, , , , acHidden
  13.             Set Frm = Forms(FrmName)
  14.             Frm.ShortcutMenu = True
  15.             DoCmd.Close acForm, FrmName, acSaveYes
  16.             Set Frm = Nothing
  17.         End If
  18.     Next i
  19.  
  20. End Function
  21.  
Obviously this is designed just to change my Address form. You would need to change it to <> frmBackground

Phil
Mar 3 '17 #2

Brilstern
100+
P: 207
Thanks for the reply Phil! Checking it now. Any thoughts on why my approach is not working?
Mar 3 '17 #3

Brilstern
100+
P: 207
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.

Expand|Select|Wrap|Line Numbers
  1. Public Function UpdateForms()
  2.  
  3.     'On Error Resume Next
  4.     Dim FrmName As String
  5.     Dim Frm As Form
  6.     Dim i As Integer
  7.  
  8.     Select Case strGlobalAccess
  9.  
  10.         Case "Administrator", "Design"
  11.  
  12.             'Search for open AccessObject objects in AllForms collection.
  13.             For i = 0 To CurrentProject.AllForms.Count - 1
  14.  
  15.                 FrmName = CurrentProject.AllForms(i).Name
  16.                 If FrmName <> "frmBackground" Then
  17.                     DoCmd.OpenForm FrmName, acDesign, , , , acHidden
  18.                     Set Frm = Forms(FrmName)
  19.                     Frm.ShortcutMenu = True
  20.                     DoCmd.Close acForm, FrmName, acSaveYes
  21.                     Set Frm = Nothing
  22.  
  23.                 End If
  24.  
  25.             Next i
  26.             DoCmd.OpenForm strHomePage
  27.             Exit Function
  28.  
  29.         Case Else
  30.  
  31.             'Search for open AccessObject objects in AllForms collection.
  32.             For i = 0 To CurrentProject.AllForms.Count - 1
  33.  
  34.                 FrmName = CurrentProject.AllForms(i).Name
  35.                 If FrmName <> "frmBackground" Then
  36.  
  37.                     DoCmd.OpenForm FrmName, acDesign, , , , acHidden
  38.                     Set Frm = Forms(FrmName)
  39.                     Frm.ShortcutMenu = False
  40.                     DoCmd.Close acForm, FrmName, acSaveYes
  41.                     Set Frm = Nothing
  42.  
  43.                 End If
  44.  
  45.             Next i
  46.             Exit Function
  47.  
  48.         End Select
  49.  
  50. End Function
Mar 3 '17 #4

PhilOfWalton
Expert 100+
P: 1,430
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
Mar 4 '17 #5

Post your reply

Sign in to post your reply or Sign up for a free account.