【问题标题】:Read file using MS Access使用 MS Access 读取文件
【发布时间】:2014-08-05 08:41:05
【问题描述】:

我正在开发 ms access 2013,但发现了一些错误。我正在尝试从文本文件中读取数据,但它显示错误。我到处搜索,但没有复制问题。请帮我解决这个问题。

代码

    Set fs = Application.FileSearch   'Get Error on this line
    With fs
    Debug.Print CABPath
        .LookIn = CABPath
        .SearchSubFolders = True
        .FileName = ConFileNm
        If .Execute() > 0 Then
            For FileNum = 1 To .FoundFiles.Count
             Next
        End If
    End With

错误说明

Run-time error 2455:
You entered an expression that has an invalid reference to the property FileSearch

【问题讨论】:

  • 能否也向我们提供错误描述?还有抛出此错误的 LOC。
  • 是的,请立即检查已编辑的问题
  • 你最后把这个排序了吗?
  • 那么您能否将帮助您的人标记为答案,以便其他人可以从中受益?
  • @PaulFrancis 准确答案不在列表中

标签: ms-access file-io vba ms-access-2013


【解决方案1】:

Application.FileSearch,自 2007 版本起已停用。所以它不能在 2013 年使用。你有一些替代品,比如 Scripting.FileSystem 对象。本站有一些解释和替代方案:http://www.mrexcel.com/forum/excel-questions/268046-application-filesearch-gone-excel-2007-alternatives.html

希望这会有所帮助!祝你好运。

【讨论】:

    【解决方案2】:

    还有多种解决方法可以通过 google 找到;

    Function GetFiles(MatchString As String, StartDirectory As String, Optional DrillSubfolders As Boolean = False) As Variant
    
        Dim Results() As Variant
    
        ReDim Results(0 To 0) As Variant
    
        CheckFiles Results, MatchString, StartDirectory, DrillSubfolders
    
        If UBound(Results) > 0 Then
            GetFiles = Results
        Else
            GetFiles = ""
        End If
    
    End Function
    
    Sub CheckFiles(ByRef Results As Variant, MatchString As String, StartDir As String, Drill As Boolean)
    
        Dim fso As Object
        Dim fld As Object
        Dim sf As Object
        Dim fil As Object
    
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fld = fso.GetFolder(StartDir)
    
        For Each fil In fld.Files
            If LCase(fil.Name) Like LCase(MatchString) Then
                If LBound(Results) > 0 Then
                    ReDim Preserve Results(1 To UBound(Results) + 1)
                Else
                    ReDim Results(1 To 1)
                End If
                Results(UBound(Results)) = fil.Name
            End If
        Next
    
        If Drill Then
            For Each sf In fld.SubFolders
                CheckFiles Results, MatchString, sf.Path, Drill
            Next
        End If
    
        Set fil = Nothing
        Set sf = Nothing
        Set fld = Nothing
        Set fso = Nothing
    
    End Sub
    

    你可以通过这样的方式在你的表单中调用它;

    Dim FileList As Variant
        Dim Counter As Long
    
        FileList = GetFiles("*.jpeg", "c:\folder\subfolder", True)
        ' to NOT look in subfoldres:
        'FileList = GetFiles("*.jpeg", "c:\folder\subfolder", True)
    
        If IsArray(FileList) Then
            With DoCmd
                .SetWarnings False
                For Counter = LBound(FileList) To UBound(FileList)
                    .RunSQL "INSERT INTO [mytable] (FilePath) VALUES ('" & _
                        FileList(Counter) & "')"
                Next
                .SetWarnings True
            End With
        End If
    

    注意:通过 google 找到的代码:http://www.experts-exchange.com/Database/MS_Access/Q_28027899.html

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 1970-01-01
      • 1970-01-01
      • 2010-10-18
      • 2016-07-18
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      相关资源
      最近更新 更多