Recordset findfirst

  • Thread starter Thread starter Dale
  • Start date Start date
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
 
Try the following modification to your code

Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblimportedfiles")


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Thanks John, no difference though...dlookup doesn't give me the desired
results either. I'm importing from a folder that users keep adding to...I
was looking for a way not to import all the files each time, but looks like
that will be my current option. I'll append the new records through a query
instead of attempting to filter the import files.
Not as elegant but it will work.
 
Back
Top