Delete a button or label

Posted on 2005-04-11
Last Modified: 2010-05-02


I have a map, and on this map, I have multiple buttons and labels. I have Delete option under Edit menu. When i click on delete, this is the skeleton that it gives to me:

Private Sub mnuEditDelete_Click()

End Sub

Since there is no can I know which button or label i delete...
cmdbutton(0), .....cmdbuttton(x)


Question by:TungVan
    LVL 23

    Expert Comment

    When you click on delete on the menu do you want it to delete all buttons and or labels or are you just trying to delete one at a time, If you created the buttons and labels as a control array then you should be able to prompt the user with an input box prompting for which one you want deleting.

    Basically make it so that the delete option in the menu is only enabled after they have clicked on one of the controls that are in the control array and then if they click on delete, then make it delete the last item they clicked on within the control array so if you had 10 buttons within a control array and then 10 labels within the control array, if they clicked on button(10) then you could have a public variable that stored the last item they clicked on ie

    Public itmStore As Integer

    Public Sub cmdButton_Click(Index As Integer)
    itmStore = Index
    End Sub

    Private Sub mnuEditDelete_Click()
    Delete cmdButton(itmStore) '< -- I am not sure of what the delete or remove command is but I am sure this will make sense
    End Sub

    The coding would be something like that but I am not sure of what the delete command would be exactly, but this should give you a good idea of what to do :)
    LVL 9

    Expert Comment

    If you mean in the VB IDE, in your properties window (I have mine on the right side of the screen) whatever object you have selected will be deleted. if you have multiple items selected then the name will obviously be displayed in the properties window.

    Author Comment



    I don't refer to VB IDE unfortunately....

    LVL 12

    Assisted Solution

    you could do something like change the color of the control to delete in it's click event, and record it's name in a form variable.

    then when your user clicks on the menu_delete, that event could hide or delete whatever control in named in the form variable.

    LVL 9

    Accepted Solution

    Try this

    please note the on error resume next. That is placed there because if you remove a control and then try to set a property of that control it will generate an error. Also note that you can not remove the label(0) because that was created at design time. you may only destroy object that you create during runtime.
    LVL 9

    Expert Comment

    Can I ask why this only rated a B?

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now