Suddenly Stopped Working

chellebell1689

Registered User.
Local time
Yesterday, 16:27
Joined
Mar 23, 2015
Messages
267
So I have code that uses a switch to open a specific switchboard depending on the department. It was working just fine. Then when I went to try adding code for the "On Load" on my log in form, it decided to stop working. I was trying to add code so that when the login form opens everything is hidden, and then when the admin logs in everything is shown again.

Here is the code for the switchboards:
Sub Security(SecurityLevel As Integer)
Select Case SecurityLevel
Case 1 'Admin Level
Public Sub UnHideNavPane()
DoCmd.SelectObject acTable, "MSysObjects", True
End Sub

DoCmd.ShowToolbar "Ribbon", acToolbarYes

Case 2 'Pastor Level
DoCmd.OpenForm "Pastor_Switchboard"
Forms![Pastor_Switchboard]![txtLogin] = TempLoginID
Forms![Pastor_Switchboard]![txtUser] = WorkerName

Case 3 'Gues Level
DoCmd.OpenForm "Guest_Switchboard"
Forms![Guest_Switchboard]![txtLogin] = TempLoginID
Forms![Guest_Switchboard]![txtUser] = WorkerName

Case 4 'Children's Ministry Level
DoCmd.OpenForm "Children's_Switchboard"
Forms![Children's_Switchboard]![txtLogin] = TempLoginID
Forms![Children's_Switchboard]![txtUser] = WorkerName

Case 5 'Food Pantry Level
DoCmd.OpenForm "Pantry_Switchboard"
Forms![Pantry_Switchboard]![txtLogin] = TempLoginID
Forms![Pantry_Switchboard]![txtUser] = WorkerName

Case 6 'Music Ministry Level
DoCmd.OpenForm "Music_Switchboard"
Forms![Music_Switchboard]![txtLogin] = TempLoginID
Forms![Music_Switchboard]![txtUser] = WorkerName

Case 7 'Nursery Level
DoCmd.OpenForm "Nursery_Switchboard"
Forms![Nursery_Switchboard]![txtLogin] = TempLoginID
Forms![Nursery_Switchboard]![txtUser] = WorkerName

Case 8 'Sack Lunch Saturday Level
DoCmd.OpenForm "SackLunchSat_Switchboard"
Forms![SackLunchSat_Switchboard]![txtLogin] = TempLoginID
Forms![SackLunchSat_Switchboard]![txtUser] = WorkerName

Case 9 'Secretary Level
DoCmd.OpenForm "Secretary_Switchboard"
Forms![Secretary_Switchboard]![txtLogin] = TempLoginID
Forms![Secretary_Switchboard]![txtUser] = WorkerName

Case 10 'Youth Ministry Level
DoCmd.OpenForm "Youth_Switchboard"
Forms![Youth_Switchboard]![txtLogin] = TempLoginID
Forms![Youth_Switchboard]![txtUser] = WorkerName


Case 11 'Sunday School Level
DoCmd.OpenForm "SS_Switchboard"
Forms![SS_Switchboard]![txtLogin] = TempLoginID
Forms![SS_Switchboard]![txtUser] = WorkerName

Case 12 'Home Group Level
DoCmd.OpenForm "HomeGroup_Switchboard"
Forms![HomeGroup_Switchboard]![txtLogin] = TempLoginID
Forms![HomeGroup_Switchboard]![txtUser] = WorkerName

Case 13 'Committees Level
DoCmd.OpenForm "Committees_Switchboard"
Forms![Committees_Switchboard]![txtLogin] = TempLoginID
Forms![Committees_Switchboard]![txtUser] = WorkerName


End Select
End Sub

I keep getting a "expecting an end sub" error, but there is an end sub...

Here's the code I was playing with that somehow messed this up:

Private Sub Form_Load()
Public Function HideNavPane() As Byte
DoCmd.SelectObject acTable, "MSysObjects", True
DoCmd.RunCommand acCmdWindowHide
End Function

DoCmd.ShowToolbar "Ribbon", acToolbarNo

End Function
 
You have 2 end functions, and the biggie is you can't have one sub inside another.
 
Ok, thank you. I'll check the code again, I thought they were all ended.

The switch is actually a sub for my "OnClick" for the log in button on the form. And the other code is for the "OnLoad" for the log in form.

**Edit**
I see what you're saying about the sub in sub. How would I go about rewriting that part?
 
Last edited:
Cut the function out like the "unhide" one at the top. I personally put any public functions at the top of the form module, followed by all the load, click, etc events, but that's personal preference.
 
Last edited:
Ok thank you! I do have my click & on load functions at the bottom, the other code wasn't necessary for this question.
 
Now it's not doing anything. It's not hiding the ribbon or the nav pane when the login form is loaded. (I would say it's not showing it, but since it's not hiding it, I can't say for sure if that part is working or not.) Also, it says it can't find "MSysObjects".
 
That table is usually hidden. Use a table name that isn't hidden.
 
Ok so I finally got a chance ( and remembered) to check this answer out. It works perfectly now!! Thank you so very much!!
 

Users who are viewing this thread

Back
Top Bottom