Shameem Khan
New Member
- Joined
- Aug 9, 2020
- Messages
- 13
- Office Version
- 2013
- Platform
- Windows
Hello. I have a Userform with dynamically created Commandbutton. I am using a class called “Class1” to add click events to the commandbutton.
What I am looking for is a way to delete the Button itself when I click on it. I tried adding the code to remove the button inside its own click event. Obviously its not working. Is there any way to make this happen? Please help.
Thanks in advance
Note: FR_LIST is a Frame, Userform name is UF_HOME
Code in Userform:
Code in Class1:
What I am looking for is a way to delete the Button itself when I click on it. I tried adding the code to remove the button inside its own click event. Obviously its not working. Is there any way to make this happen? Please help.
Thanks in advance
Note: FR_LIST is a Frame, Userform name is UF_HOME
Code in Userform:
VBA Code:
Dim Btncls As New Class1
Private Sub BT_ADD_Click() ‘ADD is a button inside Userform UF_HOME
‘ Some other codes here
Dim Btn as Object
Set Btn = Me.FR_LIST.Controls.Add("Forms.CommandButton.1", "BT_REM")
With Btn
.Left = 402
.Top = Slno * 15
.Width = 13
.Height = 13
.Picture = LoadPicture("C:\ Remove.jpg")
.PicturePosition = 12
End With
FR_LIST.Visible = True
Set Btncls.CmdEvents = Btn
Slno = Slno + 1
End Sub
Code in Class1:
VBA Code:
Public WithEvents CmdEvents As MSForms.CommandButton
Private Sub CmdEvents_Click()
‘ Some other codes here
UF_HOME.FR_LIST.Controls.Remove CmdEvents.Name
End Sub