设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[宏/菜单/工具栏] 如何实现文件查找功能

[复制链接]
跳转到指定楼层
1#
发表于 2003-10-22 19:53:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在窗体中,如何实现点击按钮,即可在硬盘上搜索一个特定的数据库,并打开,并且还要链接其中特定的表,这该如何实现呢???
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2003-10-23 01:52:00 | 只看该作者
没有人知道么,那么简单点,通过点击按钮,搜索某个文件,这个该怎么实现呢??、
3#
发表于 2003-10-23 16:44:00 | 只看该作者
可以使用以下过程实现!

Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Public Sub getFileName()

    Dim OpenFile As OPENFILENAME
    Dim sFilter As String
    Dim defLoc As String
   
    defLoc = "C:\" 'where to start from
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = hWinLoc 'Me.hwnd - See note at the end of this web page
    'OpenFile.hInstance = App.hInstance 'See the note at the end of this web page
    sFilter = "Visual Basic Modules (*.bas)" & Chr(0) & "*.bas" & Chr(0) 'start the string
    sFilter = sFilter & "C++ program and header files (*.cpp, *.h)" & Chr(0) & "*.cpp;*.h" & Chr(0) 'add another multiple file type entry
    sFilter = sFilter & "erl/CGI files (*.cgi, *.pl, *.pm)" & Chr(0) & "*.cgi;*.pl;*.pm" & Chr(0)
    sFilter = sFilter & "Text files (*.txt)" & Chr(0) & "*.txt" & Chr(0) 'start the string
    sFilter = sFilter & "All files (*.*)" & Chr(0) & "*.*" & Chr(0) 'Add something that allows all files to be seen
    sFilter = sFilter & Chr(0) 'terminate the string
   
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    OpenFile.lpstrInitialDir = defLoc
    OpenFile.lpstrTitle = myTitle
    OpenFile.flags = 0
    lreturn = GetOpenFileName(OpenFile)
    If lreturn = 0 Then
        MsgBox "The User pressed the Cancel Button"
        fnSel = ""
    Else
        MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
        fnSel = Trim(OpenFile.lpstrFile)
    End If
    If InStr(fnSel, Chr(0)) > 0 Then
        fnSel = Left(fnSel, InStr(fnSel, Chr(0)) - 1) 'ditch any terminating chr(0)
    End If
    Forms!增加新文件!正文 = fnSel
    增加新文件.正文 = fnSel
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-3 03:34 , Processed in 0.092500 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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