deleting a item from a list box along with the ajoining address

how do I delete an item(name) from a list box while at the same time removing the address from a lable
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

woottondConnect With a Mentor Commented:
Try using the change method - if the change method of the list box is invoked then your labels should be refreshed... should be as simple as copying the part out of your list box where it sets the labels to be equal to the address - and putting that into the change method of the list box. You delete an item - the list box refreshes, and resets the labels to be either null or the current value... something like

dim textString as String
label1.caption = textString

This question is too vague. What do you mean exactly. How is the name in the list box linked to the text in the label?

Having said all that, there only is one way of doing it. To remove an item from a list box you must use the .RemoveItem method, and to empty a label you must set its caption to ""

I get the impression I'm missing something here. Can you explain yourself further?
m97smcAuthor Commented:
i have a list box for names and a lable for addresses of those names.

When i run my program and highlight a name the corosponding address appears.

I have a delete function. However, when i wish to delete a name from the list box i can not delete the address at the same time.

I realise that there is something wrong with my code but i dont know how to fix it

please help thank you
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

If there is something wrong in your code, put your piece of code here.
m97smcAuthor Commented:
Here is my code
Should I have loop function as well.
If yes how is this done when deleting.
Thank you very much

Private Sub mnuDelete_Click()
Dim TextString As String
If MsgBox("Do you wish to delete this record?",vbYesNo) = vbYes Then
lstName.RemoveItem (lstNames.ListIndex)
lblAddress.Caption = textString
End If
A loop? To allow multiple deletes? Sure if you want to (I don't think I really understand what you mean by the loop - guess that comes with the territory)

ok - I see - you pasted my sample code in - cool - could you post your insert code? Then I could see how you initially set your label to a value - essentially thats all you have to do... reinitiallize the label to be the current value be it null or an address.
All Courses

From novice to tech pro — start learning today.