My module is almost complete, but I am getting a run time error of - Application Defined or Object Defined Error on this line of code
Code:
If objRegExp.test(objFile) Then
I have these references added to my project
Code:
Visual Basic For Application
Microsoft Access 15.0 Object Library
OLE Automation
Office 15.0 Access Database Engine Object
Microsoft Scripting Runtime
And this is full syntax. What do I need to alter in order for my code to execute as I so desire?
Code:
Sub ScanTablesWriteDataToText()
Dim Fileout As Object
Dim fso As Object
Dim objFSO As Object
Dim accapp As Access.Application
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objRegExp As Object
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.pattern = "*.accdb"
objRegExp.IgnoreCase = True
Dim colFiles As Collection
Set colFiles = New Collection
RecursiveFileSearch "C:\Test\", objRegExp, colFiles, objFSO
For Each f In colFiles
Set accapp = New Access.Application
accapp.OpenCurrentDatabase (filename)
accapp.Visible = False
Set db = accapp.CurrentDb
For Each tdf In db.TableDefs
If Not (tdf.name Like "MSys*") Then
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fileout = fso.OpenTextFile("C:\datafile.txt", 8, True)
Fileout.Write CStr(filename) & "," & name & "," & connect & vbCrLf
Fileout.Close
End If
Next
Set tdf = Nothing
Set db = Nothing
Next
Set objFSO = Nothing
Set objRegExp = Nothing
End Sub
Sub RecursiveFileSearch(ByVal targetFolder As String, ByRef objRegExp As Object, _
ByRef matchedFiles As Collection, ByRef objFSO As Object)
Dim objFolder As Object
Dim objFile As Object
Dim objSubFolders As Object
Set objFolder = objFSO.GetFolder(targetFolder)
For Each objFile In objFolder.files
If objRegExp.test(objFile) Then
matchedFiles.Add (objFile)
End If
Next
Set objSubFolders = objFolder.Subfolders
For Each objSubfolder In objSubFolders
RecursiveFileSearch objSubfolder, objRegExp, matchedFiles, objFSO
Next
Set objFolder = Nothing
Set objFile = Nothing
Set objSubFolders = Nothing
End Sub