Code:
Public WithEvents menubtn As MSForms.Label
Public WithEvents LblBtn As MSForms.Label
Dim BtnEve() As New Class1
Private Sub LblBtn_Click()
UserForm1.Frame1.Visible = False
MyAdd = LblBtn.Name
RowNo = Val(Split(MyAdd, ",")(1))
ColNo = Val(Split(MyAdd, ",")(2))
CodeRun = Replace(Sheet1.Cells(RowNo, ColNo), " ", "")
Run CodeRun
End Sub
Private Sub LblBtn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
For Each Ctrl In UserForm1.Frame1.Controls
If TypeName(Ctrl) <> "Frame" Then Ctrl.BackColor = &H47AD70
Next
LblBtn.BackColor = &H8000&
End Sub
Private Sub menuBtn_Click()
For Each Ctrl In UserForm1.Frame1.Controls
If TypeName(Ctrl) = "Label" Then
UserForm1.Frame1.Controls.Remove (Ctrl.Name)
End If
Next
TopPos = 2
ColNo = Val(Replace(menubtn.Name, "Menu", ""))
LastRow = Sheet1.Cells(Rows.Count, ColNo).End(xlUp).Row
'Insert the Button in Frame
For RowNo = 2 To LastRow
Set SubMenu = UserForm1.Frame1.Controls.Add("Forms.Label.1")
With SubMenu
.Name = "Btn," & RowNo & "," & ColNo
.Caption = Sheet1.Cells(RowNo, ColNo)
.Font.Name = "Calibari"
.Font.Size = 11
.Left = 18
.Width = 112
.Top = TopPos
TopPos = TopPos + .Height
End With
ReDim Preserve BtnEve(LastRow - 2)
Set BtnEve(RowNo - 2).LblBtn = UserForm1.Controls("Btn," & RowNo & "," & ColNo)
Next RowNo
'For Animation of Frame
UserForm1.Frame1.Visible = True
UserForm1.Frame1.Top = 36
UserForm1.Frame1.Left = menubtn.Left - 2
TotHht = TopPos
For ani = 0 To TotHht
UserForm1.Frame1.Height = ani
UserForm1.Frame2.Height = ani
Next ani
End Sub
This is a code of excel Dynamic Menu creation.i want to create a Menu like this in my ms access form. Can Any one Change this to ms access vba code ?? Thanks in advance
Last edited by a moderator: