renaming files using vb code

Posted on 2001-06-06
Last Modified: 2010-05-02
Dim strOldFilename as string
Dim strNewFileName as string

'now just say strNewFileName = P1S1P1

'the original filename is image1.jpj
'this file is stored in C:\database\images\
we want image.jpj to change to p1s1p1.jpg now how would I go about this using vb code. I have used a common dialog box used to select the file. eg image1.jpg.

The location of the filename can be stored in a variable.
Dim strFileName As String

With frmAssessment.dlgImage
    .FileName = ""
End With

strFileName = frmAssessment.dlgImage.FileName

Now how can I change the name of the file. Any other ideas.
Question by:Yakeni
  • 2
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6162621
NAME strOldFileName AS strNewFileName


Expert Comment

ID: 6162622
Public Sub RenameFile(ByVal strFilename As String, _
  ByVal strNewFilename As String)
  On Error GoTo PROC_ERR
  Name strFilename As strNewFilename
  Exit Sub
  MsgBox "Error: " & Err.Number & vbCrLf & _
         "Description: " & Err.Description, vbCritical
  Resume PROC_EXIT
End Sub

Accepted Solution

sharmon earned 50 total points
ID: 6162623
just can seem to hit the button fast enough:)

Author Comment

ID: 6162647
That was simple wasnt it

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 65
How does CurrentUser work? 10 31
Add a task in Outlook from access 11 35
Passing a Text Box name to a Sub 6 76
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

896 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

16 Experts available now in Live!

Get 1:1 Help Now