通用对话控制(或替代) [英] Common Dialog Control (or alternatives)

查看:69
本文介绍了通用对话控制(或替代)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Access编写一个简单的数据库系统,并且需要用户浏览目录以识别所需的文件。  以前我使用过Common Dialog Control但是这个版本(2010)似乎不支持它。


解决方案

您好,


您可以使用
Application.FileDialog Property(Access)


例如

 Private Sub cmdFileDialog_Click()

'在使用Office 2010时需要引用Microsoft Office 14.0对象库

Dim fDialog As Office.FileDialog
Dim varFile As Variant

'清除列表框内容。
Me.FileList.RowSource =""

'设置文件对话框。
设置fDialog = Application.FileDialog(msoFileDialogFilePicker)

使用fDialog

'允许用户在对话框中进行多项选择
.AllowMultiSelect = True

'设置对话框的标题。
。标题="请选择一个或多个文件"

'清除当前过滤器,并添加我们自己的过滤器。
.Filters.Clear
.Filters.Add" Access Databases"," *。MDB"
.Filters.Add" Access Projects"," * .ADP"
.Filters.Add" All Files"," *。*"

'显示对话框。如果.Show方法返回True,则
'用户选择至少一个文件。如果.Show方法返回
'False,则用户单击Cancel。
如果.Show = True则

'循环选择每个文件并将其添加到我们的列表框中。
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Next

Else
MsgBox"您在文件对话框中单击了取消。 "
结束如果
结束
结束子

问候,


Celeste


I am trying to write a simple database system using Access and need the user to browse the directories to identify required files.  Previously I have used the Common Dialog Control but this version (2010) does not seem to support it.

解决方案

Hello,

You could use Application.FileDialog Property (Access):

E.g.

Private Sub cmdFileDialog_Click() 

   ' Requires reference to Microsoft Office 14.0 Object Library as you are using Office 2010

   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

Regards,

Celeste


这篇关于通用对话控制(或替代)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆