dynamic menu creation (1 Viewer)

Rashid

Member
Local time
Yesterday, 23:31
Joined
Sep 6, 2019
Messages
30
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:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:31
Joined
Jul 9, 2003
Messages
16,282
I've put your code in code tags, to make it easier to read.
 

MarkK

bit cruncher
Local time
Yesterday, 23:31
Joined
Mar 17, 2004
Messages
8,181
Can Any one Change this to ms access vba code ??
I write code for money. I post on here because it is my pleasure to help people learn to write better code.

If you want something done to spec, while you wait, please hire someone.

Cheers,
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:31
Joined
Feb 19, 2002
Messages
43,275
Here's a sample switchboard that has simple security. The security can be used to customize the switchboard so that different groups of users see different options. If the switchboard is not actually variable by group, then you might user the second sample which has alternate styles of form, including one that is just big buttons.


 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:31
Joined
May 7, 2009
Messages
19,243
...so give me money... that's what i want -the beatles.
 

Users who are viewing this thread

Top Bottom