本文介绍了如何使用单击按钮找到文件名并从MS Access 2007中的文件路径启动它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我是VBA访问数据库的新手,我的后台编程语言一直专注于C#



我有一个任务是启动一个特定的文件名(所有文件)在doc,xls等中,当用户点击每个特定文件名的按钮时,从相同的目录路径。



我一直在谷歌搜索并使用不同的方法仍然它好像不起作用。



我试过这个:

Please I am new in VBA access database and my background programming language has been focused on C#

I have a task to launch a specific file name (all files in doc, xls, etc) from the same directory path when the user click on a button for each specific file name.

I have been googling and used different approach still it seemed not to work.

I tried this:

Private Sub FileMsReports_Click()

Dim f As Object

Set f = Application.FileDialog(3)

f.AllowMultiSelect = True

If f.Show Then
    For i = 1 To f.SelectedItems.Count
        sFile = FileName(f.SelectedItems(i), sPath)
        MsgBox sPath & "---" & sFile
    Next
End If
End Sub

Public Function FileName(ByVal strPath As String, sPath) As String
    sPath = Left(strPath, InStrRev(strPath, "\"))
    FileName = Mid(strPath, InStrRev(strPath, "\") + 1)

End Function





我最终得到了一个文件对话框,但实际上并不是我的主管要我做的事情!

我仍​​然不喜欢编程的一年,现在这是我的实习地点的任务。



我需要有人帮助我并指导如何去关于这个。



提前谢谢。



I ended up getting a file dialog show up but it is not actually what my supervisor wanted me to do!
I am still like less a year in programming and right now this is a task giving to me for the place of my Practicum.

Please I need someone to help me out and direction on how to go about this.

Thanks in advance.

推荐答案



  1. []来存储文件名

  1. Create table[^] to store file names
CREATE TABLE MyFiles (MyFile CHAR);



  • []并将其放在ListBox控件上
  • 删除Button控件并创建 OnClick 事件
  • [] MyFiles table
  • 转到 []并创建新程序 EnumMyFiles

  • Create new form[^] and drop on it ListBox control
  • Drop a Button control and create OnClick event
  • Bind ListBox[^] with MyFiles table
  • Go to form module[^] and create new procedure EnumMyFiles
  • Private Sub EnumMyFiles()
    'body of the procedure
    End Sub



  • EnumMyFiles 程序体内:


    • 使用清除ListBox [] property

    • Inside the body of EnumMyFiles procedure:

      • Clear ListBox using RowSource[^] property
      • Listbox.RowSource = ""
        



      • 从表中删除所有数据(怎么样?见点号。 5 - 最后一句)
      • DELETE * FROM MyFiles;



      • 定义存储初始目录的变量 - []
      • 使用 []功能。
      • 使用 []方法

      • define variable to store initial directory - this databse path[^]
      • loop through the collection of files using Dir function (VB)[^] function.
      • Insert each file name which corresponds to the extension into database using DoCmd.RunSQL[^] method
      • DoCmd.RunSQL "INSERT INTO MyFiles (MyFile) VALUES('" & sFileName & "');"




        LisBox.RowSource = "MyFiles"



      • 内部 Button_Click 过程调用 EnumMyFiles procedure

      • Inside Button_Click procedure call EnumMyFiles procedure
      • Privare Sub Button_Click()
            EnumMyFiles
        End Sub



      • 保存更改并对其进行测试

      • 这篇关于如何使用单击按钮找到文件名并从MS Access 2007中的文件路径启动它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-27 22:38