Hi, I can create folders using a recordset and capture files I need using a recordset (I think) but I do not know how to copy files to those folders. I am hoping someone can help me with this. The area I know I am having problems with is in green.
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
'Create File Names
Dim fso, fs As Scripting.FileSystemObject
Set fso = New FileSystemObject
Set fs = New FileSystemObject
Dim rst As DAO.Recordset 'Recordset for File Folders
Dim fRst As DAO.Recordset 'Recordset for Files
Dim fld As DAO.Field 'File Folder Field
Dim fFld As DAO.Field 'File Field
'Create File Folders
Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT Main.[File No] from Main order by main.[File No]", dbOpenDynaset)
Set fld = rst("[File No]")
Set fRst = CurrentDb.OpenRecordset("SELECT Main.[File No], Main.FileLink FROM Main", dbOpenDynaset)
Set fFld = rst("[FileLink]")
Set fFile = rst("[File No]")
rst.MoveFirst
Do Until rst.EOF
MkDir ("C:\Temp\" & fld) 'Create the Direcotry
'Here I want to copy files where ffld = fFile to the current folder in the recordset.
fs.CopyFile ffld Where fFile = fld, "C:\Temp\" & fld
rst.MoveNext
Loop
rst.CLOSE
Set rst = Nothing
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
Recordsets are not my long suit, so this may not be the right approach. Any help would be appreciated - a back burner item brought to the forefront again.
Thanks
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
'Create File Names
Dim fso, fs As Scripting.FileSystemObject
Set fso = New FileSystemObject
Set fs = New FileSystemObject
Dim rst As DAO.Recordset 'Recordset for File Folders
Dim fRst As DAO.Recordset 'Recordset for Files
Dim fld As DAO.Field 'File Folder Field
Dim fFld As DAO.Field 'File Field
'Create File Folders
Set rst = CurrentDb.OpenRecordset("SELECT DISTINCT Main.[File No] from Main order by main.[File No]", dbOpenDynaset)
Set fld = rst("[File No]")
Set fRst = CurrentDb.OpenRecordset("SELECT Main.[File No], Main.FileLink FROM Main", dbOpenDynaset)
Set fFld = rst("[FileLink]")
Set fFile = rst("[File No]")
rst.MoveFirst
Do Until rst.EOF
MkDir ("C:\Temp\" & fld) 'Create the Direcotry
'Here I want to copy files where ffld = fFile to the current folder in the recordset.
fs.CopyFile ffld Where fFile = fld, "C:\Temp\" & fld
rst.MoveNext
Loop
rst.CLOSE
Set rst = Nothing
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
Recordsets are not my long suit, so this may not be the right approach. Any help would be appreciated - a back burner item brought to the forefront again.
Thanks