PM message from Profowo on me, (DocAElstein) :
VBA USERFORM NOT LOADING GIVING ERROR MESSAGE 13
Thank you for you reply on my last post for help.I need you urgent help the error I have.You can get the excel sheet and information to view the user-form on the platform,I could not attach it here
.I have Error 13
Thank you in advance sir
Below is the control names and properties and codes I created--Please find attached
Frame1 is having the menu & submenus inside
Menu1 is main menu has inside lbl as Dashboard
Menu2 is main menu has inside lbl as Employee_Main as property name and Employee as caption name
Menu3 is main menu has inside lbl as Payroll_Main as property name and Payroll as Caption name
Menu 4 is main has inside lbl as Reports_Main as property name and Reports an Caption name
Menu5 is main menu has inside lbl as Settings_Main as property name and Settings as caption name
Menu1 (has no submenu)
Frame2 property name has menu2 inside with submenus named
E_sMenu1. Caption as Add New
E_sMenu2 caption as Edit
E_sMenu3 caption as Disciplinary
E_sMenu4 caption as leave management
Frame3 as property name has menu3 inside with submenus named
P_sMenu1 created payroll as caption name
P_sMenu2 process payroll as caption name
P_sMenu3 loan deductions as caption name
P_sMenu4 salary review as caption name
P_sMenu5 payslip as caption name
Frame4 as property name has menu4 inside with submenus named
R_sMenu1 payroll report as caption name
R_sMenu2 employee report as caption name
R_sMenu3 deduction report as caption name
R_sMenu4 PAYE report as caption name
R_sMenu5 Pension report as caption name
R_sMenu6 NHF report as caption name
Frame5 as property name has menu5 inside with submenus named
S_sMenu1 setup as caption
S_sMenu2. Other setting as caption
4 pane Beside each menu named
Pane1
Pane2
Pane3
Pane4
Drop Arrow up & down Arrow for each main menu 2 to main menu 5 are as below
Img_DpUp. Img_DpDown
Img_DpUp Img_DpDown
Img_DpUp Img_DpDown
Img_DpUp Img_DpDown
Code:
Option Explicit
Private IsEmployeeExpanded As Boolean
Private IsPayrollExpanded As Boolean
Private IsReportsExpanded As Boolean
Private IsSettingsExpanded As Boolean
Public Sub SetMenuEvents(menuFrame As MSForms.Frame, _
dpUp As MSForms.CommandButton, _
dpUDown As MSForms.CommandButton, _
subMenus As Collection, _
ByRef IsExpanded As Boolean, _
framesBelow As Collection, _
pane As MSForms.frame)
On Error GoTo ErrorHandler
Debug.Print "IsExpanded Initial State: " & IsExpanded
Debug.Print "Submenus Count: " & subMenus.Count
Debug.Print "Frames below Count: " & FrameBelow.Count
Debug.Print "Pane visible: " & pane.Visible
'toggle visibility based on IsExpanded state
If IsExpanded Then
'Hide subMenus
Dim ctrl As MSForms.Control
For Each ctrl In subMenus
ctrl.visible = False
Next ctrl
pane.visible = False 'Hide the pane associated with this menu
dpUp.visible = False
DpDown.visble = True
IsExpanded = False
Else
'Show subMenu
For Each ctrl In subMenu
ctrl.visible = True
Next ctrl
pane.visible = True 'Show the pane associated with this menu
dpUp.visible = True
DpDown.visble = False
IsExpanded = True
End If
'Adjust frame below based on expansion state
Dim frm As MSForms.frame
Dim offset As Long
offset = IIf(IsExpanded, 100, -100) 'adjust this value as neededfor spacing
For Each frm In framesBelow
frm.Top = frm.Top + offset
Next frm
ErrorHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error in SetMenuEvents"
End Sub
Code:
Private Sub UserForm_Initialize()
' Initialize expand/collapse states
IsEmployeeExpanded = False
IsPayrollExpanded = False
IsReportsExpanded = False
IsSettingsExpanded = False
' Initialize each menu's submenus and set hover effects
InitializeMenu
' Add hover effects for all main menus
AddHoverEffect menu1
AddHoverEffect Frame2
AddHoverEffect Frame3
AddHoverEffect Frame4
AddHoverEffect Frame5
' Hide all submenus initially
ToggleVisibility Frame2, False
ToggleVisibility Frame3, False
ToggleVisibility Frame4, False
ToggleVisibility Frame5, False
End Sub
Code:
Private Sub InitializeMenu()
' Initialize each menu with its submenus, frames that are positioned below it, and panes
Dim employeeSubMenus As Collection
Dim payrollSubMenus As Collection
Dim reportsSubMenus As Collection
Dim settingsSubMenus As Collection
Set employeeSubMenus = New Collection
employeeSubMenus.Add Me.E_sMenu1
employeeSubMenus.Add Me.E_sMenu2
employeeSubMenus.Add Me.E_sMenu3
employeeSubMenus.Add Me.E_sMenu4
Set payrollSubMenus = New Collection
payrollSubMenus.Add Me.P_sMenu1
payrollSubMenus.Add Me.P_sMenu2
payrollSubMenus.Add Me.P_sMenu3
payrollSubMenus.Add Me.P_sMenu4
payrollSubMenus.Add Me.P_sMenu5
Set reportsSubMenus = New Collection
reportsSubMenus.Add Me.R_sMenu1
reportsSubMenus.Add Me.R_sMenu2
reportsSubMenus.Add Me.R_sMenu3
reportsSubMenus.Add Me.R_sMenu4
reportsSubMenus.Add Me.R_sMenu5
reportsSubMenus.Add Me.R_sMenu6
Set settingsSubMenus = New Collection
settingsSubMenus.Add Me.S_sMenu1
settingsSubMenus.Add Me.S_sMenu2
' Set up frames to move
Dim framesBelowEmployee As Collection, framesBelowPayroll As Collection, framesBelowReports As Collection
Set framesBelowEmployee = New Collection
framesBelowEmployee.Add Me.Frame3
framesBelowEmployee.Add Me.Frame4
framesBelowEmployee.Add Me.Frame5
Set framesBelowPayroll = New Collection
framesBelowPayroll.Add Me.Frame4
framesBelowPayroll.Add Me.Frame5
Set framesBelowReports = New Collection
framesBelowReports.Add Me.Frame5
' Configure each menu and submenu with panes
SetMenuEvents Me.Frame2, Me.Img_DpUp, Me.Img_DpDown, employeeSubMenus, IsEmployeeExpanded, framesBelowEmployee, Me.Pane2
SetMenuEvents Me.Frame3, Me.Img_DpUp, Me.Img_DpDown, payrollSubMenus, IsPayrollExpanded, framesBelowPayroll, Me.Pane3
SetMenuEvents Me.Frame4, Me.Img_DpUp, Me.Img_DpDown, reportsSubMenus, IsReportsExpanded, framesBelowReports, Me.Pane4
SetMenuEvents Me.Frame5, Me.Img_DpUp, Me.Img_DpDown, settingsSubMenus, IsSettingsExpanded, New Collection, Me.Pane5 ' No frames below Setting
End Sub
Code:
' Module to handle hover effect
Public Sub AddHoverEffect(ctrl As Control, Optional hoverColor As Long = &HFFDD99, Optional defaultColor As Long = &HFFFFFF)
ctrl.BackColor = defaultColor
ctrl.OnMouseMove = "HoverEffect", hoverColor
End Sub
Code:
Public Sub RemoveHoverEffect(ctrl As Control, Optional defaultColor As Long = &HFFFFFF)
ctrl.BackColor = defaultColor
End Sub
Code:
' Module for handling dropdown menu visibility
Public Sub ToggleVisibility(frame As frame, visible As Boolean)
Dim ctrl As Control
For Each ctrl In frame.Controls
If TypeName(ctrl) = "Label" Then
ctrl.visible = visible
End If
Next ctrl
End Sub
Code:
' Main Menu Hover Events
Private Sub Menu1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
HoverEffect Menu1, &HFFDD99
End Sub
Code:
Private Sub Frame2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
HoverEffect Frame2, &HFFDD99
End Sub
Code:
Private Sub Frame3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
HoverEffect Frame3, &HFFDD99
End Sub
Code:
Private Sub Frame4_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
HoverEffect Frame4, &HFFDD99
End Sub
Code:
Private Sub Frame5_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
HoverEffect Frame5, &HFFDD99
End Sub
Code:
' Arrow Button Click Events
Private Sub DpDown_Employee_Click()
ToggleVisibility Frame2, True
End Sub
Code:
Private Sub DpUp_Employee_Click()
ToggleVisibility Frame2, False
End Sub
Code:
Private Sub DpDown_Payroll_Click()
ToggleVisibility Frame3, True
End Sub
Code:
Private Sub DpUp_Payroll_Click()
ToggleVisibility Frame3, False
End Sub
Code:
Private Sub DpDown_Reports_Click()
ToggleVisibility Frame4, True
End Sub
Code:
Private Sub DpUp_Reports_Click()
ToggleVisibility Frame4, False
End Sub
Code:
Private Sub DpDown_Setting_Click()
ToggleVisibility Frame5, True
End Sub
Code:
Private Sub DpUp_Setting_Click()
ToggleVisibility Frame5, False
End Sub
Code:
Public Sub HoverEffect(ctrl As Control, hoverColor As Long)
ctrl.BackColor = hoverColor
End Sub
Code:
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
' Reset to default colors when not hovering
RemoveHoverEffect menu1
RemoveHoverEffect Frame2
RemoveHoverEffect Frame3
RemoveHoverEffect Frame4
RemoveHoverEffect Frame5
End Sub
Bookmarks