Hello Everyone,
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.
[code=vb]Function CopyFiles()
Dim strImageLoc As String
Dim strMoveToFilena me 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. strMoveToFilena me " _
& "FROM qryImageCopyTo; "
Set db = CurrentDb
Set rst = db.OpenRecordse t(strSQL, dbOpenSnapshot)
strText = rst("strImageLo c")
On Error Resume Next
For Each strText In rst
FileCopy rst("strImageLo c"), rst("strMoveToF ilename")
Next strText
End Function[/code]
I am new to using loops, so I have probably made a real Newbie error.
Regards
Tony
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.
[code=vb]Function CopyFiles()
Dim strImageLoc As String
Dim strMoveToFilena me 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. strMoveToFilena me " _
& "FROM qryImageCopyTo; "
Set db = CurrentDb
Set rst = db.OpenRecordse t(strSQL, dbOpenSnapshot)
strText = rst("strImageLo c")
On Error Resume Next
For Each strText In rst
FileCopy rst("strImageLo c"), rst("strMoveToF ilename")
Next strText
End Function[/code]
I am new to using loops, so I have probably made a real Newbie error.
Regards
Tony
Comment