I have a document library table , that holds all documents generated and imported for clients. The entries displayed in the clients document library is relative to that client only. The document entries in the document library don't carry the physical file only the files physical name.
I am trying to write code that will allow the user to select one to many files from a list of documents relative a Client. I display the list and the user ticks each one they want copied. Once they have completed their selection I ask for the folder they want them copied to.
Once I have the destination folder I go through the file and pick out the ticked documents and copy them to the destination folder.
I keep on getting an error 52 on the CopyFile (FileCopy) Bad file name or number
Here is the code I currently have
I hope someone can help me
Have a great day
I am trying to write code that will allow the user to select one to many files from a list of documents relative a Client. I display the list and the user ticks each one they want copied. Once they have completed their selection I ask for the folder they want them copied to.
Once I have the destination folder I go through the file and pick out the ticked documents and copy them to the destination folder.
I keep on getting an error 52 on the CopyFile (FileCopy) Bad file name or number
Here is the code I currently have
Code:
Private Sub SelectOKButt_Click()
Me.Dirty = False
Me.Refresh
Me.Requery
Dim strQryFile As String
' This is where we check if any of the documents has been selected to copy.
If DLookup("GeneralFlag", "DocumentLibrary", "GeneralFlag = -1") = False Then
MsgBox "No Documents Have been selected to be Copied"
Exit Sub
Else
Dim DestinationAddress, SourceAddress, SystemAddress As String
SystemAddress = DLookup("SysAddress", "SystemPreferences", "[SysPrefId] = 1")
SourceAddress = SystemAddress & "TOGAS\ClientMergeFiles\"
End If
' What is the destination address
'------------------------------------------------------------------------------------------------------
Dim stExportPath, Response As String
Response = MsgBox("Select the folder location for where you want to copy the files to.", vbOKOnly + vbQuestion, "Folder Location")
If Response <> vbOK Then
Exit Sub
Else
Dim DFolder As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
' Open the select folder prompt
With fd
.Title = "Select a Folder"
If .Show = -1 Then ' if OK is pressed
DFolder = .SelectedItems(1)
End If
End With
SourceAddress = SourceAddress & Me.PrecFilename
DestinationAddress = DFolder & "\"
If DFolder = "" Then ' if a folder was chosen
MsgBox "A folder has not been selected"
Exit Sub
Else
'-----------------------------------There is at least 1 document selected------------------------------------------------------------------
strQryFile = "DocumentLibrary"
'----------------------------------
Dim strQryFileSql As String
Dim strWhereStmnt As String
Dim db As Database
Dim RecCounter As Integer
Dim rs As DAO.Recordset
Dim lUserID As Long
DBEngine.SetOption dbMaxLocksPerFile, 1000000
Me.QryFile = strQryFile
Set db = CurrentDb
strWhereStmnt = " WHERE MatterId = " & Me.MatterIdFld & " AND GeneralFlag = " & -1 & ";"
strQryFileSql = "SELECT * FROM " & strQryFile & strWhereStmnt '
Set rs = db.OpenRecordset(strQryFileSql, dbOpenDynaset)
'----------------------------------------------------------------------------------------------
'----------------- The LOOP starts Here -------------------------------------------------------
RecCounter = 1
Do While Not rs.EOF
SourceAddress = SystemAddress & "TOGAS\ClientMergeFiles\"
Me.DocTransId = rs![DocId]
Me.PrecDocCodeFld = rs![PrecDocCode]
Me.TransTypeFld = rs![TransType]
Me.DescriptionFld = rs![Description]
Me.MatterNoFld = rs![MatterNo]
Me.MatterIdFld = rs![MatterId]
Me.ClientIdFld = rs![ClientId]
Me.DateCreatedFld = rs![DateCreated]
Me.UserIdFld = rs![UserId]
Me.PrecFileNameFld = rs![PrecFilename]
Me.PrecTypeFld = rs![PrecType]
Me.FolderNameFld = rs![FolderName]
Me.AttachedFld = rs![Attached]
Me.PaperLessFileSNoFld = rs![PaperLessFileSNo]
Me.LastModifiedFld = rs![LastModified]
Me.ParentFolderFld = rs![ParentFolder]
Me.RecycledFld = rs![Recycled]
Me.GeneralFlagFld = rs![GeneralFlag]
' Now copy this file to the selected destination
SourceAddress = SourceAddress & Me.PrecFilename
DestinationAddress = DFolder & "\"
On Error GoTo CopyFile_Error
FileCopy SourceAddress, DestinationAddress
'FileCopy SourceAddress, DestinationAddress
rs.MoveNext
Loop
MsgBox "You Files have been copied to " & DestinationAddress
' We have files to copy
' Get the destination address
End If
End If
CopyFile_Error:
If err.Number = 0 Then
ElseIf err.Number = 70 Then
MsgBox "The file is currently in use and therfore is locked and cannot be copied at this" & _
" time. Please ensure that no one is using the file and try again.", vbOKOnly, _
"File Currently in Use"
ElseIf err.Number = 53 Then
MsgBox "The Source File '" & SourceAddress & "' could not be found. Please validate the" & _
" location and name of the specifed Source File and try again", vbOKOnly, _
"File Currently in Use"
Else
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
err.Number & vbCrLf & "Error Source: CopyFile" & vbCrLf & _
"Error Description: " & err.Description, vbCritical, "An Error has Occurred!"
End If
End Sub
I hope someone can help me
Have a great day