PC Review


Reply
Thread Tools Rate Thread

code to rename image files from query

 
 
MM
Guest
Posts: n/a
 
      3rd Feb 2011
I have some code to rename image files from a query so they can be
used on a web site. It works fine if no file exists but I'm having
touorble getting it to overwrite existing files. Any suggestions how
to make it overwrite existing files or move the existing ones somwhere
else?

Private Sub ImageRename_Click()
Dim dbCurr As DAO.Database
Dim rsCurr As DAO.Recordset
Dim strOrigFolder As String
Dim strOrigFile As String
Dim strNeedFolder As String
Dim strNeedFile As String
Dim strNoNeedFolder As String
Dim strNoNeedFile As String
Dim strSQL As String

' Define what folder the pictures are in.
' Note that the final slash must be there
strOrigFolder = "C:\LocalFiles\Images\"
strNeedFolder = "C:\LocalFiles\Images\web\product\"

' Define the SQL to get the data from the table.

strSQL = "SELECT [Image], [OutItem] FROM tblImages;"

Set dbCurr = CurrentDb()
Set rsCurr = dbCurr.OpenRecordset(strSQL)
Do While rsCurr.EOF = False


strOrigFile = strOrigFolder & rsCurr![Image] & ".jpg"
strNeedFile = strNeedFolder & rsCurr![OutItem] & ".jpg"


'Copy Needed files (good on February 2nd)

If (Len(Dir(strOrigFile)) > 0) And (Len(Dir(strNeedFile)) > 0) Then
Name strOrigFile As strNeedFile

Else

End If
rsCurr.MoveNext
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      3rd Feb 2011
Have you tried to KILL the strNeedFile first?

If (Len(Dir(strOrigFile)) > 0) And (Len(Dir(strNeedFile)) > 0) Then
Kill strNeedFile 'Delete the existing file
Name strOrigFile As strNeedFile
Else

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 2/2/2011 10:16 PM, MM wrote:
> I have some code to rename image files from a query so they can be
> used on a web site. It works fine if no file exists but I'm having
> touorble getting it to overwrite existing files. Any suggestions how
> to make it overwrite existing files or move the existing ones somwhere
> else?
>
> Private Sub ImageRename_Click()
> Dim dbCurr As DAO.Database
> Dim rsCurr As DAO.Recordset
> Dim strOrigFolder As String
> Dim strOrigFile As String
> Dim strNeedFolder As String
> Dim strNeedFile As String
> Dim strNoNeedFolder As String
> Dim strNoNeedFile As String
> Dim strSQL As String
>
> ' Define what folder the pictures are in.
> ' Note that the final slash must be there
> strOrigFolder = "C:\LocalFiles\Images\"
> strNeedFolder = "C:\LocalFiles\Images\web\product\"
>
> ' Define the SQL to get the data from the table.
>
> strSQL = "SELECT [Image], [OutItem] FROM tblImages;"
>
> Set dbCurr = CurrentDb()
> Set rsCurr = dbCurr.OpenRecordset(strSQL)
> Do While rsCurr.EOF = False
>
>
> strOrigFile = strOrigFolder& rsCurr![Image]& ".jpg"
> strNeedFile = strNeedFolder& rsCurr![OutItem]& ".jpg"
>
>
> 'Copy Needed files (good on February 2nd)
>
> If (Len(Dir(strOrigFile))> 0) And (Len(Dir(strNeedFile))> 0) Then
> Name strOrigFile As strNeedFile
>
> Else
>
> End If
> rsCurr.MoveNext

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use access to rename / overwrite image files. M.Jamal Microsoft Access 2 6th Aug 2008 03:45 PM
Use access to rename image files =?Utf-8?B?TWlrZQ==?= Microsoft Access 15 6th Aug 2008 01:13 PM
using access to rename image files sarath26uk via AccessMonster.com Microsoft Access Queries 3 8th Jan 2007 11:37 PM
rename jpg files revert to previous image Reelwoman Windows XP Photos 3 10th Sep 2004 11:35 PM
copy and rename image files based on query result Maureen Microsoft Access VBA Modules 1 24th Jun 2004 09:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:20 AM.