Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / October 2007

Tip: Looking for answers? Try searching our database.

Recordset findfirst

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dale - 04 Oct 2007 14:01 GMT
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
John Spencer - 04 Oct 2007 14:47 GMT
Try  the following modification to your code

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

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Hello
> I have a table of imported word docs, I am opening a recordset of this
[quoted text clipped - 51 lines]
> 'Resume fExit
> End Function
Dale - 05 Oct 2007 04:53 GMT
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.

> Try  the following modification to your code
>
[quoted text clipped - 55 lines]
>> 'Resume fExit
>> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.