I am having a spot if difficulty creating a process loop using the For Each Next procedure.
I basically have a field in a table that stores a file location, This is passed to a query which has two fields. One field is the original file location, and the other is a new file path and filname based on the primary key for the record.
The trouble is that it performs the required action on the first record in the query, and then exits the loop before processing any subsequent records.
Here is the code I am trying to use, please can anyone help.
Expand|Select|Wrap|Line Numbers
- Function CopyFiles()
- Dim strImageLoc As String
- Dim strMoveToFilename As String
- Dim retval As String
- Dim strSQL As String
- Dim strText As Variant
- Dim Prefix As String
- Dim Suffix As String
- Dim db As DAO.Database, rst As DAO.Recordset
- strSQL = "SELECT qryImageCopyTo.strImageLoc, qryImageCopyTo.strMoveToFilename " _
- & "FROM qryImageCopyTo;"
- Set db = CurrentDb
- Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)
- strText = rst("strImageLoc")
- On Error Resume Next
- For Each strText In rst
- FileCopy rst("strImageLoc"), rst("strMoveToFilename")
- Next strText
- End Function
Regards
Tony