Rename Folder and Listbox Value

Posted on 2006-05-03
Last Modified: 2008-01-09
This is an odd one, but I will do my best to ask the question correctly.
I have a program that is workflow related.  The first part of the process creates a folder with the session number(lets say 600) and the customers last name(lets say smith), so the path created looks like this; \\servername\main_folder\600smith\*.  Now everytime my employees upload a document, based on which session they are in it will put that document in the above folder.

Here comes the tricky part for me.

At stage 3 of the workflow a loan number is associated to this session so at this point I have to rename the folder to the loan number(lets say K9999) and the persons last name.  Now when this is done I also have to rename the listbox items to correspond with the new path.

So instead of  \\servername\main_folder\600smith\filename.doc it will become \\servername\main_folder\K9999-SMITH\filename.doc and this will be in both the listbox of my program and on the shared network directory.

Thanks in advance
Question by:danorme
    LVL 10

    Expert Comment

    to update a listbox, you first have to have the listindex of the item you wish to update, then, you do:

    .removeitem (INDEXNumber) 'oh btw i cant remember it completely, is it removeitem? its along the lines of remove, delete or something

    then, do a additem(NEW PATH, INDEXnumber)
    LVL 2

    Expert Comment

    --find the item you want to replace and delete it  
    For I = 0 To YourListBox.ListCount - 1
          IF ThisOneIsTheOneYouWantToReplace
               YourListBox.RemoveItem I  
          end if
    Next I

    --add new item with the updated path
    YourListBox.AddItem item, index

    hope it helps
    LVL 10

    Expert Comment

    a modification on Ceta' code:

    --add new item with the updated path
    YourListBox.AddItem item, index

    instead of that, do:
    --add new item with the updated path
    YourListBox.AddItem item, I '<-- here since from before, you are deleteing the item at I, you should insert the new one back at that place

    Author Comment

    I will issue points once I get this little thing to work.  Any code examples would be appreciated.
    LVL 10

    Accepted Solution

    ok, for example:

    say you have the 2nd item in the list as
    " \\servername\main_folder\600smith\filename.doc"

    and you want to change it to

    you do this:

    dim text as string

    list1.listindex = 1 'This is to select that item
    text = list1.text 'Text will contain the sting  \\servername\main_folder\600smith\filename.doc
    DO YOUR PROCESSING HERE, so after the processing, text should=  "\\servername\main_folder\K9999-SMITH\filename.doc"

    then, to update the list
    list1.removeitem 1
    list1.additem text, 1

    of course, in your actual code you want to swap the number 1 with a variable so you can change which one to update and such

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    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…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now