Trong Access 2007, bạn chỉ cần sử dụng Application.FileDialog
.
Dưới đây là ví dụ từ các tài liệu Access:
' Requires reference to Microsoft Office 12.0 Object Library. '
Private Sub cmdFileDialog_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Clear listbox contents. '
Me.FileList.RowSource = ""
' Set up the File Dialog. '
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow user to make multiple selections in dialog box '
.AllowMultiSelect = True
' 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 "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 selected and add it to our 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
Như mẫu nói, chỉ cần chắc chắn rằng bạn có một tham chiếu đến Microsoft Access 12.0 Object Library (dưới VBE IDE> Tools> Tài liệu tham khảo thực đơn).
Nguồn
2009-07-08 03:19:55
+1 Luôn hy vọng điều này là có thể, chìa khóa để thực hiện công việc ràng buộc muộn là đi qua các tùy chọn số thay vì msoOpenFileDialog vv Vì vậy, đơn giản nhưng một câu trả lời tuyệt vời:) –
Bạn có thể, nhưng không nên. Với sự ràng buộc trễ bạn đang mã hóa trong bóng tối .. Khi bạn thêm tham chiếu và khai báo đúng và thiết lập đối tượng đệ trình của bạn, IDE cho bạn thấy các gợi ý, trong khi với sự ràng buộc trễ nó sẽ không. – Chris
@Chris OTOH, sử dụng ràng buộc sớm có nghĩa là người dùng của bạn cũng phải có các tham chiếu được thêm vào. Điều đó có nghĩa là ràng buộc trễ là cần thiết cho một số ứng dụng. –