D
Dale
Hello
I have a table of imported word docs, I am opening a recordset of this table
and trying to find a no match against a directory of files which if no match
is true will convert the file to html (prior to importing). I can't seem to
get the rs.findfirst to work, seems to hang. If I remove the findfirst
syntax, the code works fine so I'm pretty sure its this piece thats not
working. I've remarked out the error handling to capture any errors but
none seem to be returned. I'd appreciate any assistance. thanks in advance
for any and all comments.
Public Function fCountFiles(strDir As String, Optional varFileType As
Variant) As Long
'Loops through directory looks for word doc files only
' A function to count the number of files in a directory (excluding
directories)
' Accepts:
' strDir - the directory to count the files in, i.e. "C:\Folder\"
' varFileType (optional) - a file extension if you only wish to count
certain file types, i.e. "exe"
' Returns:
' The number of files in the directory
'On Error GoTo E_Handle
Dim rs As Recordset
Dim strFile As String
Dim strSQL As String
Dim lngCount As Long
Set rs = CurrentDb.OpenRecordset("tblimportedfiles", dbOpenDynaset)
strFile = Dir(strDir, vbNormal)
Do While strFile <> ""
rs.FindFirst "filename='" & strFile & "'"
If rs.NoMatch Then
If Not IsMissing(varFileType) Then
If Right(strFile, Len(varFileType)) = varFileType Then lngCount = lngCount +
1
Else
lngCount = lngCount + 1
End If
strFile = Dir
If strFile Like "*.doc" Then
Call OpenWordDoc(strDir, strFile)
End If
End If
Loop
fCountFiles = lngCount
'fExit:
'Exit Function
rs.Close
'E_Handle:
'MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
'Resume fExit
End Function
I have a table of imported word docs, I am opening a recordset of this table
and trying to find a no match against a directory of files which if no match
is true will convert the file to html (prior to importing). I can't seem to
get the rs.findfirst to work, seems to hang. If I remove the findfirst
syntax, the code works fine so I'm pretty sure its this piece thats not
working. I've remarked out the error handling to capture any errors but
none seem to be returned. I'd appreciate any assistance. thanks in advance
for any and all comments.
Public Function fCountFiles(strDir As String, Optional varFileType As
Variant) As Long
'Loops through directory looks for word doc files only
' A function to count the number of files in a directory (excluding
directories)
' Accepts:
' strDir - the directory to count the files in, i.e. "C:\Folder\"
' varFileType (optional) - a file extension if you only wish to count
certain file types, i.e. "exe"
' Returns:
' The number of files in the directory
'On Error GoTo E_Handle
Dim rs As Recordset
Dim strFile As String
Dim strSQL As String
Dim lngCount As Long
Set rs = CurrentDb.OpenRecordset("tblimportedfiles", dbOpenDynaset)
strFile = Dir(strDir, vbNormal)
Do While strFile <> ""
rs.FindFirst "filename='" & strFile & "'"
If rs.NoMatch Then
If Not IsMissing(varFileType) Then
If Right(strFile, Len(varFileType)) = varFileType Then lngCount = lngCount +
1
Else
lngCount = lngCount + 1
End If
strFile = Dir
If strFile Like "*.doc" Then
Call OpenWordDoc(strDir, strFile)
End If
End If
Loop
fCountFiles = lngCount
'fExit:
'Exit Function
rs.Close
'E_Handle:
'MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
'Resume fExit
End Function