2013-12-11 2 views
0

파일 대화 상자를 여는 버튼을 만들려고합니다. 그런 다음 데이터베이스가있는 폴더로 복사 할 이미지를 선택할 수 있습니다. 나는이 코드로 작업 해왔다.하지만 나는 filecopy 명령에 갇혀있다. 제대로 포맷 할 수 없다. 나는 경로를 만드는 특정 폴더를 선택하기 위해 데이터베이스의 경로와 몇 개의 폴더를 사용한 후 마지막으로 콤보 상자를 사용합니다 (데이터베이스가 이동되고 콤보 상자가 범주를 기반으로 이미지를 정렬하면 끊어지지 않도록) . 여기에 제가 사용 해본 코드가 있습니다. 고마워.MS-ACCESS "파일 대화 상자에서 vba를 통해 파일 복사 중

Private Sub Command156_Click() 

    Dim fDialog As Office.FileDialog 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 
    Dim varFile As Variant 



    ' Set up the File Dialog. ' 
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 
    fd.InitialFileName = [Application].[CurrentProject].[Path] 
    With fDialog 

     ' Allow user to make multiple selections in dialog box ' 
     .AllowMultiSelect = False 

     ' Set the title of the dialog box. ' 
     .Title = "Please select a Image" 

     ' Clear out the current filters, and add our own.' 
     .Filters.Clear 
     .Filters.Add "All Files", "*.*" 

     ' Show the dialog box. If the .Show method returns True, the ' 
     ' user picked at least one file. If the .Show method returns ' 
     ' False, the user clicked Cancel. ' 
     If .Show = True Then 

    filecopy([.SelectedItems],[GetDBPath] & "\Images\Equipment\" & Combo153) 

     Else 

     End If 
    End With 
End Sub 
+0

그래서 문제/귀하의 질문은 무엇입니까? – JohnFx

+0

괄호'(','['및']')를 제거합니다. 구문은'FileCopy SourceFile, DestinationFile'입니다. –

답변

1

나는이 질문에 here 대답했다하지만 여기

당신은 변경해야 할 수 있습니다

Sub Locate_File() 
    Dim fDialog As Office.FileDialog 
    Dim file_path As String 
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 

    With fDialog 
    'Set the title of the dialog box. 
    .Title = "Please select one or more files" 

    'Clear out the current filters, and add our own. 
    .Filters.Clear 
    .Filters.Add "All Files", "*.*" 

    'Show the dialog box. If the .Show method returns True, the 
    'user picked at least one file. If the .Show method returns 
    'False, the user clicked Cancel. 
    If .Show = True Then 
     file_path = .SelectedItems(1) 
     Copy_file file_path,Combo153 
    Else 
     MsgBox "You clicked Cancel in the file dialog box." 
    End If 
    End With 
End 

Sub Copy_file(old_path As String, file_name As String) 
    Dim fs As Object 
    Dim images_path As String 
    images_path = CurrentProject.Path & "\Images\Equipment\" 
    Set fs = CreateObject("Scripting.FileSystemObject") 
    fs.CopyFile old_path, images_path & file_name 
    Set fs = Nothing 
End 

개념이다 위해 나는 다시 게시거야, 그리고 당신이 마이크로 소프트 오피스 12.0 개체가 필요합니다 FileDialog가 작동하는 라이브러리. FileDialog 코드의 대부분은 Microsoft에서 가져 왔습니다.

0

Siddharth가 제안한 제안을 사용하여 여분의 대괄호를 제거하고 몇 가지 조정을 수행했습니다. 코드가 작동했습니다. 나는 engineersmnky 방법을 시도했으나 통로가 올바르게 생성되지 않았습니다. 코드 자체를 해결하려면 유일한 오류는 파일 복사의 대상 부분에, 파일 이름이 없었다이었다, 그래서 파일 이름을 얻으려면

Dir(Trim(.SelectedItems.Item(1) 

를 사용하고 마지막에 식은. 이 코드의 나머지 부분은 원하는 다른 사용자를위한 것입니다.

Private Sub Command156_Click() 

    Dim fDialog As Office.FileDialog 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 
    Dim varFile As Variant 



    ' Set up the File Dialog. ' 
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 
    fd.InitialFileName = Application.CurrentProject.Path 
    With fDialog 

     ' Allow user to make multiple selections in dialog box ' 
     .AllowMultiSelect = False 

     ' Set the title of the dialog box. ' 
     .Title = "Please select a Image" 

     ' Clear out the current filters, and add our own.' 
     .Filters.Clear 
     .Filters.Add "All Files", "*.*" 

     ' Show the dialog box. If the .Show method returns True, the ' 
     ' user picked at least one file. If the .Show method returns ' 
     ' False, the user clicked Cancel. ' 
     If .Show = True Then 
     ' This section takes the selected image and copy's it to the generated path' 
     ' the string takes the file location, navigates to the image folder, uses the combo box selection to decide the file category, then uses the name from the filedialog to finish the path' 
    FileCopy .SelectedItems(1), Application.CurrentProject.Path & "\Images\Equipment\" & Combo153 & "\" & Dir(Trim(.SelectedItems.Item(1))) 


     Else 

     End If 
    End With 
End Sub 
관련 문제