设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1776|回复: 4
打印 上一主题 下一主题

[模块/函数] 【转载 / 源码】打开文件对话框

[复制链接]
跳转到指定楼层
1#
发表于 2005-8-11 04:13:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在Access运行的时候,打开一个文件,或者更改一个文件的路径,你可能会需要用到打开文件的对话框,之前很多人都使用API来做到,事实上还有更简单的办法。

以下代码需要引用“Microsoft Office 1x.0 Object Library”

Private Sub cmdAddFiles_Click()

    'Declare a FileDialog object variable.

    Dim myFileDialog As FileDialog



    'Declare a variant to hold each file selected.

    Dim vFileSelected As Variant



    'Create a FileDialog object as an Open dialog window.

    Set myFileDialog = Application.FileDialog(msoFileDialogOpen)



    'If the user didn’t press Cancel, process each selection.

    If myFileDialog.Show = –1 Then

        For Each vFileSelected In myFileDialog.SelectedItems

            lstFiles.AddItem vFileSelected

        Next vFileSelected

    Else

        'The user pressed Cancel.

        MsgBox “No files selected.”

    End If

    'Set the myFileDialog object variable to Nothing.    Set myFileDialog = Nothing

End Sub

以上代码来源:《Microsoft® Access VBA Programming for the Absolute Beginner 》Second Edition

[此贴子已经被作者于2005-9-21 22:49:33编辑过]

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-8-11 04:28:00 | 只看该作者
XP以上才能用,不通用,所以别人才用 API 的
3#
发表于 2005-8-12 07:44:00 | 只看该作者
谢谢!很有用![em05]
4#
发表于 2005-12-29 06:05:00 | 只看该作者
在ACCESS2000中不能用
5#
发表于 2009-4-18 09:31:34 | 只看该作者
谢谢分享。收藏。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-24 13:44 , Processed in 0.089586 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表