PC Review


Reply
Thread Tools Rate Thread

copy and rename image files based on query result

 
 
Maureen
Guest
Posts: n/a
 
      23rd Jun 2004
I have a query that creates a list of products and from this would like to
find and copy the corresponding image files. The query is selects
Inventory.ProdID (key) and Inventory.Description Inventory.ImageAvailable
from these results I would like to locate the images (these are at
c:\images\ and are named ProdID & ".jpg" )

I would like to copy the image files to c:\images\wip and rename them to
Inventory.Description & ".jpg"

*****
Below is a copy from a post (thanks Diana) that got me started getting our
image names posted into out Inventory table.

'' GET FILE NAMES FROM GRAPHICS FOLDER
''
Dim sFileDir As String
Dim rsFileInfo As ADODB.Recordset
Set rsFileInfo = New ADODB.Recordset

' create the filename field -- this is a string data type, length 255
rsFileInfo.Fields.Append "FileName", adBSTR, 255

' open the recordset
rsFileInfo.Open

' get the files in the correct directory
sFileDir = Dir("C:\graphics01\images\*.jpg") ' change the path as
necessary

Do While sFileDir <> ""
If sFileDir <> "." And sFileDir <> ".." Then
rsFileInfo.AddNew
rsFileInfo!FileName = sFileDir
' alternatively, use the next line instead to get the file
name
' minus the last four characters ".jpg"
' rsFileInfo!filename = Left(sFileDir, Len(sFileDir) - 4)
rsFileInfo.Update
Debug.Print rsFileInfo!FileName
' get the next file in the directory
sFileDir = Dir
End If
Loop
rsFileInfo.MoveFirst

''
'' COMPARE FILES TO RECORDS IN INVENTORY TABLE
''
Dim rsInv As ADODB.Recordset
Set rsInv = New ADODB.Recordset
rsInv.ActiveConnection = CurrentProject.Connection
' open recordset of inventory records that do not already show the image
is available
rsInv.Open "SELECT * FROM Inventory WHERE
(((Inventory.ImageAvailable)=False));", , adOpenKeyset, adLockOptimistic

' loop thru recordset to find matches in rsFileInfo
Do Until rsInv.EOF
Do Until rsFileInfo.EOF
' this next test assumes you have taken out the ".jpg" from the
filename
' if not, then create a variable to hold the string combo of
ProdID + .jpg
If rsInv!ProdID = rsFileInfo!FileName Then
rsInv!ImageAvailable = True
rsInv!ImageName = rsFileInfo!FileName
End If
rsFileInfo.MoveNext
Loop
rsFileInfo.MoveFirst
rsInv.MoveNext
Loop
rsFileInfo.Close
rsInv.Close
Set rsFileInfo = Nothing
Set rsInv = Nothing
*****


 
Reply With Quote
 
 
 
 
Wayne Morgan
Guest
Posts: n/a
 
      24th Jun 2004
strCurrentFile = "c:\images\" & ProdID & ".jpg"
strNewFile = "c:\images\wip\" & Inventory.Description & ".jpg"
If Dir(strCurrentFile)<>"" Then
FileCopy strCurrentFile, strNewFile
End If

You can't actually set the strNewFile and strCurrentFile this way, you will
need to do this within your recordset code so that VBA will know what
Inventory.Description and Inventory.ProdID are.

--
Wayne Morgan
Microsoft Access MVP


"Maureen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a query that creates a list of products and from this would like to
> find and copy the corresponding image files. The query is selects
> Inventory.ProdID (key) and Inventory.Description Inventory.ImageAvailable
> from these results I would like to locate the images (these are at
> c:\images\ and are named ProdID & ".jpg" )
>
> I would like to copy the image files to c:\images\wip and rename them to
> Inventory.Description & ".jpg"
>
> *****
> Below is a copy from a post (thanks Diana) that got me started getting our
> image names posted into out Inventory table.
>
> '' GET FILE NAMES FROM GRAPHICS FOLDER
> ''
> Dim sFileDir As String
> Dim rsFileInfo As ADODB.Recordset
> Set rsFileInfo = New ADODB.Recordset
>
> ' create the filename field -- this is a string data type, length 255
> rsFileInfo.Fields.Append "FileName", adBSTR, 255
>
> ' open the recordset
> rsFileInfo.Open
>
> ' get the files in the correct directory
> sFileDir = Dir("C:\graphics01\images\*.jpg") ' change the path as
> necessary
>
> Do While sFileDir <> ""
> If sFileDir <> "." And sFileDir <> ".." Then
> rsFileInfo.AddNew
> rsFileInfo!FileName = sFileDir
> ' alternatively, use the next line instead to get the file
> name
> ' minus the last four characters ".jpg"
> ' rsFileInfo!filename = Left(sFileDir, Len(sFileDir) - 4)
> rsFileInfo.Update
> Debug.Print rsFileInfo!FileName
> ' get the next file in the directory
> sFileDir = Dir
> End If
> Loop
> rsFileInfo.MoveFirst
>
> ''
> '' COMPARE FILES TO RECORDS IN INVENTORY TABLE
> ''
> Dim rsInv As ADODB.Recordset
> Set rsInv = New ADODB.Recordset
> rsInv.ActiveConnection = CurrentProject.Connection
> ' open recordset of inventory records that do not already show the
> image
> is available
> rsInv.Open "SELECT * FROM Inventory WHERE
> (((Inventory.ImageAvailable)=False));", , adOpenKeyset, adLockOptimistic
>
> ' loop thru recordset to find matches in rsFileInfo
> Do Until rsInv.EOF
> Do Until rsFileInfo.EOF
> ' this next test assumes you have taken out the ".jpg" from the
> filename
> ' if not, then create a variable to hold the string combo of
> ProdID + .jpg
> If rsInv!ProdID = rsFileInfo!FileName Then
> rsInv!ImageAvailable = True
> rsInv!ImageName = rsFileInfo!FileName
> End If
> rsFileInfo.MoveNext
> Loop
> rsFileInfo.MoveFirst
> rsInv.MoveNext
> Loop
> rsFileInfo.Close
> rsInv.Close
> Set rsFileInfo = Nothing
> Set rsInv = Nothing
> *****
>
>



 
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
code to rename image files from query MM Microsoft Access Queries 1 3rd Feb 2011 01:37 PM
Macro to copy a worksheet and rename based upon text entered in 1 edeaston Microsoft Excel Misc 5 5th Dec 2008 05:47 PM
Copy a Sheet & Rename based on Cell Value Q Sean Microsoft Excel Programming 2 7th Sep 2007 01:01 PM
using access to rename image files sarath26uk via AccessMonster.com Microsoft Access Queries 3 8th Jan 2007 11:37 PM
Delete Query based on result of select query John Finch Microsoft Access Queries 1 2nd Jul 2004 05:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:11 AM.