Hmmmm... some of this I don't fully understand, some of this is beyond my skills or it's stuff I use 3'rd party tools to handle.
I'll try to give it a go, with the following limitations:
* creating an unbound form with an unbound control, a listbox and a button
* path of the files is "c:\images" (both for the old, and the new)
* providing a listbox with the filenames in that folder
* provide a way to rename selected file with name stored in a control on your form
You'll have to either experiment with this, buy book(s), post new threads to continue...
You're saying you're a macro-user. Hope you'll convert to VBA - when you're starting to get the hang of it, there are lot's of opportunities, easier maintainence, possibility of error handling...
OK - create a new form in design view (no wizard, no recordsource)
Save it, and use for instance the name "frmTestRename"
Turn of the control vizard (button no 2 on the toolbox)
Add a listbox control (you'll find it as button no 10 on the toolbox)
In the properties of the listbox (giving the tab name first, then the property):
(some of these values should be what is stated by default, but then just use them to check)
* other - name: lstFileName
* data - Row Source Type: Value List
* data - Bound Column: 1
* format - column count: 1
* format - heigth 5cm
* format - width: 5cm
Add a command button (button no 11 on the toolbox)
In the properties of the button
* other - name: cmbRename
* format - caption: &Rename selected file
Add a text control
In the properties of the text control
* other - name: txtNewName
Save the form. Now the "interesting part" begins. The coding. There are several "unknowns" here. We don't know yet what files reside in the specified path, the list doesn't have any rowsource... That'll be the first. I've decided to populate the list when the form opens. So for the form properties, select the event tab, find the on load event (that event is supposedly better for "data" thingies than the on open event). When invoking the event, select Code Builder. The "top" and "bottom" lines show up, and we're ready to start - but first - we'll need to store the initial path somewhere. I choose to declare a module level variable. At the top of the module, first check that the following lines are present (if they're not, paste them in - especially the second one is helpful, by "demanding" that any variables must be explicitly declared):
[tt]Option Compare Database
Option Explicit[/tt]
Just below those, type the following lines:
[tt]Private mstrPath As String
' Creates a variable available as long as the form is open[/tt]
Then enter the sub Form_Load, and paste the code below.
[tt] mstrPath = "c:\images\" ' "hardcoding" path
PopulateList ' calling routine to populate list[/tt]
Here, because I need to repopulate the list whenever a file is changed, I've put the code for populating the list in a separate module. Just place the cursor belowe any existing line in the module, and paste:
[tt]Private Sub PopulateList()
Dim fs As FileSystemObject
Dim fld As Folder
Dim fls As Files
Dim fl As File
Dim strListSource As String
Me!lstFileName.RowSource = "" ' Clearing previous rowsource
Set fs = New FileSystemObject
Set fld = fs.GetFolder(mstrPath)
Set fls = fld.Files
For Each fl In fls
' Getting all files, and assigning them to listbox
strListSource = strListSource & Chr(34) & fl.Name & Chr(34) & ","
Next
' Removing last comma (,) from string
' NOTE
' Some countries regional settings uses other separators
' than comma (,), my country included, we use semicolon (

' If so, change the comma to your separator in the line
' starting with
' strListSource = strListSource &...
strListSource = Mid$(strListSource, 1, Len(strListSource) - 1)
Set fs = Nothing
Set fld = Nothing
Set fls = Nothing
Set fl = Nothing
Me!lstFileName.RowSource = strListSource
End Sub[/tt]
Explaining the object types and methods will take up to much space. I've commented some on the building of the listbox rowsource. Hit F1 to get help on whatever you wan't to know more about.
Then there's the "renaming" code. This will be almost the same as in previous post, xcept some additional testing. On the rename buttons on click event, paste the following code:
[tt] Dim fs As FileSystemObject
Set fs = New FileSystemObject
If Len(Me!lstFileName & ""

> 0 And Len(Me!txtNewName & ""

> 0 Then
' Checking if a filename is selected, and there's a value for new name
If Not fs.FileExists(mstrPath & Me!txtNewName) Then
' checking if a file with the same name alredy exist
fs.CopyFile mstrPath & Me!lstFileName, mstrPath & Me!txtNewName
' copy selected file
fs.DeleteFile mstrPath & Me!lstFileName
' deleting original file
PopulateList
' Populating the list again with new names
Else
MsgBox "A file with the that name alredy exists!", _
vbExclamation, "File exists"
End If
Else
MsgBox "You must select a file and/or" & vbCr & vbLf & _
"type a new name first!", _
vbExclamation, "Select a file!"
End If
Set fs = Nothing
[/tt]
You should perhaps add some error handling too.
Now, this probably doesn't solve your challenge, but I hope it might be considered somewhere to start
Roy-Vidar