Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change image filenames to values in database field.

Status
Not open for further replies.

jonohara2

Programmer
Feb 4, 2008
6
GB
Hi There

I have hundreds of product images in a folder, the filename of each image is a meaningless sequence of characters - e.g xc6755r.jpg

I have a table with the product range, name, description etc and the corresponding image name (e.g xc6755r.jpg).

I've added a field to the table which contains my desired filename for the image e.g oak_bed_double.jpg.

How do i go about changing the existing image filename to the desired filename.

many thanks
 
Name As should suit. An Example:

Code:
Set rs=CurrentDB.openrecordset("tblImages")
strPath="C:\Images\"
Do While Not rs.Eof
      Name strPath & rs!OddCharsField As strPath & rs!Description
      rs.MoveNext
Loop
 
Thanks Remou

Your code helps me to change the image name in my table but i need to change the actual filename of the image located in the images directory.

e.g. c:\images\w56stdt.jpg to c:\images\oak_bed_double.jpg
 
The code Remou posted shouldn't do anything with your table's values, it specifically renames a file...

Could you show us how you're trying to implement this please?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Sorry my mistake...I run this from a form - i get error file not found. I debug and 'Name' has been given the runtime value 'frmChangeFileName' i.e the name of the form, not the new image name.

Cheers

Code:
Sub renameimage()
Set rs = CurrentDb.openrecordset("tblbeds")
strPath = "C:\Program Files\Content\bedroomgeneral_Images\"
Do While Not rs.EOF
    If rs!Image = Null Then rs.MoveNext
    Name strPath & rs!Image As strPath & rs!prodname
    rs.MoveNext
Loop
End Sub
 
Yeah, if you debug name then that's what you will get, thankfully that's not a problem [smile]

File not found indicates that it can't find the file you're trying to rename.

When you're in debug, type
Code:
?strPath & rs!Image
In the immediate window and check that is the correct path to the file.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I had a few duplicate filenames in the table so when it came to a duplicate it couldn't find the file (as it was already renamed!).

Thanks very much for your help.
 
You're welcome, glad I could help [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top