Looping throughform and do FileCopy?

Descecrator

Registered User.
Local time
Today, 16:54
Joined
Oct 18, 2005
Messages
11
I've got a problem. The database-user can search through the database and the results are displayed in a subform. There's a button attachted to that subform and when that button is pressed, the files, which are linked to the found records and saved outside the database, have to be copied to an other folder. So how do I make I loop for copying those files?

I've got the following code behind the button (but it doesn't work):

Private Sub Command56_Click()
Dim rst As Recordset
Dim strBnaam As String

Set rst = CurrentDb.OpenRecordset("[Forms]![frmZoekVast]![qryZoekVast subform]")
With rst
Do While Not (rst.EOF)
.MoveFirst
strBnaam = rst!Tpon
FileCopy "\\NLFS006\A110154$\Stage Bidteam\Systeem\Teksten\" & strBnaam & ".doc", "C:\TempOfferteTraject\" & strBnaam & ".doc"
.MoveNext
Loop
End With
End Sub

Can somebody help me plz :( ??? THNX!

Greetz
 
Hi -
As written, with rst.movefirst at the top of the loop, you'll never get past the first record.

Try this variation and see if it helps:
Code:
.....
Set rst = CurrentDb.OpenRecordset("[Forms]![frmZoekVast]![qryZoekVast subform]")
rst.MoveFirst
Do While Not rst.EOF
   strBnaam = rst!Tpon
   FileCopy "\\NLFS006\A110154$\Stage Bidteam\Systeem\Teksten\" & strBnaam & ".doc", "C:\TempOfferteTraject\" & strBnaam & ".doc"
   rst.MoveNext
Loop
rst.close
.....
HTH - Bob
 
THNX! You've been a big help, I have the following code now:

Private Sub Command56_Click()
Dim strBnaam As String
Dim strDir As String
Dim intDir As Integer
strDir = "C:\TempOfferteTraject"
intDir = (fIsFileDIR(strDir, vbDirectory))
If intDir = 0 Then
MkDir strDir
End If

With [Forms]![frmZoekVast]![qryZoekVast subform].Form.RecordsetClone
If (.RecordCount) Then
.MoveFirst
Do While Not .EOF
strBnaam = .Fields("Tpon").Value
FileCopy "\\NLFS006\A110154$\Stage Bidteam\Systeem\Teksten\" & strBnaam & ".doc", "C:\TempOfferteTraject\" & strBnaam & ".doc"
.MoveNext
Loop
End If
.Close
End With
MsgBox ("De bestanden zijn gekopieerd!")
End Sub

Greetz
 

Users who are viewing this thread

Back
Top Bottom