???? ID: 824272 - ????? ???????: 17 ??????? 2011 - ??????: 3.0

How to display and to use the File dialog box in Microsoft Access

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
?? ???? Microsoft Access ??????? (.mdb) ?? ???? Microsoft Access ?? ??? ???? ????????? (.adp)?

?????: ?????? ???????? ??????, ?????????????? ?? multiuser ???? ???
???? Microsoft Access 2002 ??????? ?? ??? ?? ???? ??, ?????279508  (http://support.microsoft.com/kb/279508/ ) .
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

This article discusses how to use the newFileDialogmethod in Microsoft Access to display the built-in????dialog box and to determine the files that the user selects.

???:TheFileDialogmethod works only in the full retail version of Microsoft Access. This method does not work in a Microsoft Access run-time application.

???? ???????

In earlier versions of Microsoft Access, you may display the file dialog box by using either the Microsoft??????? ?????ActiveX control or by making calls to the Windows API.

?? ????? ??FileDialogmethod in Microsoft Office Access 2003, you can display the????dialog box that is used by Microsoft Access and to determine the files that the user selects. TheSelectedItems?? ??????FileDialogobject contains the paths to the files that are selected by the user. By using aFor-Eachloop, you can enumerate this collection and then display each file. The following example loops through theItemsSelectedcollection and then displays files in the list box.

Microsoft ???????????? ?????? ???? ???????? ?? ??? ??? ???? ??, ???? ??? ??? ?? ?????? ?? ?????????? ??? ??? ?????? ???? ?? ????.. ?????? ???????? ?????? ?? ???? ????? ???????? ?? ??? ???????? ????? ??? ?? ???? ?? ????? ???? ???.. ?? ??? ????? ?? ?? ?? ????? ?? ?? ??? ???????????? ???? ?? ?? ??????? ?? ?????? ??? ????? ????? ???????????? ?? ????? ?? ???? ???? ?? ??? ???? ?? ??? ??.. Microsoft ?????? ???????? ?? ????? ????????? ?? ???????????? ?? ?????? ??? ?????? ?? ???? ???, ??, ?? ?? ???????? ?? ???? ??????? ?????????? ?? ?????? ???? ?? ??? ???????? ??????????????? ?? ?????? ?? ???????????? ????? ?? ??? ??????? ???? ??????..
  1. Microsoft Access ??????? ?????
  2. ????? ??????? Northwind.mdb ??????
  3. ??????? ????? ??? ????? ????????????? ???????????????.
  4. ???? ??? ??? ??? ????? ????Create form in Design view.
  5. Add the following controls to the form:
    	Command button
    	--------------------------
    	Name: cmdFileDialog
    	Caption: Add Files
    	OnClick: [Event Procedure]
    
    	List box
    	-------------------------
    	Name: FileList
    	RowSourceType: Value List
    
  6. ????? ????????????? ??,???:to open the module of the form in the Microsoft Visual Basic Editor.
  7. ????? ????????????? ??,??????.
  8. ?????References-DatabaseName????? ????? ???,Microsoft Office 11.0 Object Library???????? ?? ????? ?? ??? ????? ????, ?? ???? ???OK.
  9. Add the following code to the module of the form:
    Option Compare Database
    Option Explicit
          
    Private Sub cmdFileDialog_Click()
    
    ' This requires a reference to the Microsoft Office 11.0 Object Library.
    
       Dim fDialog As Office.FileDialog
       Dim varFile As Variant
    
       ' Clear the list box contents.
       Me.FileList.RowSource = ""
    
       ' Set up the File dialog box.
       Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
       With fDialog
          ' Allow the user to make multiple selections in the dialog box.
          .AllowMultiSelect = True
                
          ' Set the title of the dialog box.
          .Title = "Select One or More Files"
    
          ' Clear out the current filters, and then add your own.
          .Filters.Clear
          .Filters.Add "Access Databases", "*.MDB"
          .Filters.Add "Access Projects", "*.ADP"
          .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
             ' Loop through each file that is selected and then add it to the list box.
             For Each varFile In .SelectedItems
                Me.FileList.AddItem varFile
             Next
          Else
             MsgBox "You clicked Cancel in the file dialog box."
          End If
       End With
    End Sub
    			
  10. ??????? ?? ??? ??? ??????Form1, and then close it.
  11. In the Database window, selectForm1?? ????-????? ????, ?? ???? ????????to open the form in the Form view.
  12. ????? ????,??????? ??????. TheSelect One or More Files????? ?????,.
  13. Select one or more files, and then clickOK, ?? ????? ???????? ????.
??? ?? ?? ?? ???? ?????? ?? ??? ????, ?? ?? ?? ????? ????? ??? ???? ????? ????? ????? ?? ???? ?? ??? ?????? ????, ?? ????? ???? ?? ?? ???? ??? ????? ??????? ?? ???? ?????? ????.

??????

?? ???? ?? ???? ???? ????? ????? ???, Visual Basic ?????? ???, ?? ???? ??? ???? ??????? ?? ??? ????? ????Microsoft Visual Basic ??????????? ???????????, ??????filedialog ?????????????????? ?? ????????? ??? ??? ????? ???, ?? ???? ??? ????? ??????? ??????? ???????? ?? ??????

???? ???? ???? ??:
  • Microsoft Office Access 2003
??????: 
kbprogramming kbfile kbcode kbusage kbhowto kbmt KB824272 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:824272  (http://support.microsoft.com/kb/824272/en-us/ )