2017-12-07 14 views
0

파일을 찾아보고 레코드에 첨부 할 수있는 양식이 있지만 실제로 첨부 파일을 복사하여 폴더에 넣으면 파일 경로는 다음과 같습니다. 데이터베이스에 저장됩니다. 이것은 훌륭하게 작동하지만 ... 데이터베이스를 분할하면 여러 사람이 프론트 엔드를 데스크탑으로 복사하여 거기에서 작업하게됩니다. 지금이 코드는 프런트 엔드가 이미 만들어진 경우 새 폴더를 만들거나 폴더를 사용할 위치에 설정됩니다. 따라서이 경우 실제로 사용자 데스크톱에 폴더가 만들어지며 원하는 것은 아닙니다. 모든 첨부 파일을 중앙 폴더의 서버로 옮기고 데이터베이스에서 해당 폴더의 파일을 읽으 려합니다. 여기 코드는 다음과 같습니다MS Access - 파일을 첨부/이동하는 브라우저가 올바르지 않음

여기
Private Sub cmd_LocateFile_Click() 
On Error GoTo Error_Handler 
Dim sFile As String 
Dim sFolder As String 
Dim ID As Long 
Dim sTarget As String 



sFile = FSBrowse("", msoFileDialogFilePicker, "All Files (*.*),*.*") 
If sFile <> "" Then 
    sFolder = Application.CodeProject.path & "\" & sAttachmentFolderName & "\" 
    If FolderExist(sFolder) = False Then MkDir (sFolder) 
    ID = RequestID_FK ' Set current record id. 
sTarget = sFolder & CStr(ID) & "-" & GetFileName(sFile) 
If CopyFile(sFile, sFolder & GetFileName(sTarget)) = True Then 
     Me!FullFileName.Value = sTarget 
    Else 
    End If 
End If 
Error_Handler_Exit: 
On Error Resume Next 
Exit Sub 
Error_Handler: 
MsgBox "The following error has occured" & vbCrLf & vbCrLf & _ 
     "Error Number: " & Err.Number & vbCrLf & _ 
     "Error Source: " & sModName & "\cmd_LocateFile_Click" & vbCrLf & _ 
     "Error Description: " & Err.Description & _ 
     Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _ 
     , vbOKOnly + vbCritical, "An Error has Occured!" 
Resume Error_Handler_Exit 
End Sub 

는 주석의 유효한 문자열이 아닌 코딩

'Delete the current attachment/record and the attachment file itself 
Private Sub cmd_RecDel_Click() 
On Error GoTo Error_Handler 
Dim sFile     As String 

sFile = Me.FullFileName 
'Delete the database record 
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 
'If we're here the record was deleted, so let delete the actual file from the server 
Kill sFile 

Error_Handler_Exit: 
On Error Resume Next 
Exit Sub 

Error_Handler: 
If Err.Number <> 2501 Then 
    MsgBox "The following error has occured" & vbCrLf & vbCrLf & _ 
      "Error Number: " & Err.Number & vbCrLf & _ 
      "Error Source: " & sModName & "\cmd_RecDel_Click" & vbCrLf & _ 
      "Error Description: " & Err.Description & _ 
      Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _ 
      , vbOKOnly + vbCritical, "An Error has Occured!" 
End If 
Resume Error_Handler_Exit 
End Sub 

'Open the attachment 
Private Sub cmd_ViewFile_Click() 
On Error GoTo Error_Handler 

Call ExecuteFile(Me.FullFileName, "Open") 

Error_Handler_Exit: 
On Error Resume Next 
Exit Sub 
Error_Handler: 
MsgBox "The following error has occured" & vbCrLf & vbCrLf & _ 
     "Error Number: " & Err.Number & vbCrLf & _ 
     "Error Source: " & sModName & "\cmd_ViewFile_Click" & vbCrLf & _ 
     "Error Description: " & Err.Description & _ 
     Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _ 
     , vbOKOnly + vbCritical, "An Error has Occured!" 
Resume Error_Handler_Exit 
End Sub 
+0

음, 단지 변경'sFolder = Application.CodeProject.path & "\"& sAttachmentFolderName & "을 \ "당신이 원하는 폴더에. – Andre

+0

나는 이것을 이것을 바꿀 것이지만 그것을 좋아하지 않는다. 진술의 끝에 관한 것. "sFolder = aiowima23fp1 \ 생태 과학 및 공학 \ 문화 자원 \ 신 - 문화 자원 요청 데이터베이스 &"\ "& sAttachmentFolderName &"\ " ' – Jordy

답변

0

의 나머지 부분입니다. 상수 문자열을 큰 따옴표 "mystring"

은 UNC 경로의 가정에 묶어야합니다,이 작업을해야합니다 :

sFolder = "\\aiowima23fp1\Ecological Sciences and Engineering\Cultural Resources\New - Cultural Resources Request Database\" & sAttachmentFolderName & "\" 
+0

'sFolder = ("\\ aiowima23fp1 \ 생태 과학 및 공학 \ 문화 자원 \ 신규 - 문화 자원 요청 데이터베이스 ") &"\ "& sAttachmentFolderName &"\ "'나를 위해 일하고있는 것 같습니다 – Jordy

+0

여기서 괄호'()'는 필요하지 않습니다. 답변 문자열도 잘 작동합니다. 어쨌든, 만약 그 해답이 당신의 문제를 풀었다면, 당신은 그것을 받아 들일 수 있습니다 (http://stackoverflow.com/help/someone-answers). @ 조디 – Andre