PC Review


Reply
Thread Tools Rate Thread

Automatically Delete records from Recordset

 
 
Booga_Boy via AccessMonster.com
Guest
Posts: n/a
 
      6th Jun 2007
I wrote a macro to populate a text box on a form (continuous records) with
the contents of a directory by modifying the Access Help example of
"FileSearch." However, I want to populate the text box only with files that
*don't* already exist in the underlying query. I keep getting a run-time
error of "No current record" (No. 3021) when the macro gets to the "rst.
delete" line. Any way around this, or any way to modify the macro to
automatically delete a new record if it already exists? Code is below:

Query Name: qryGeneral
Field Name: file
Text Box: txtFile

Dim Length
Dim CurrentFile
Dim rst As Recordset
Dim strCriteria As String

Set fs = Application.FileSearch
Set rst = CurrentDb.OpenRecordset("qryGeneral")
strCriteria = "[file]=" & "'" & txtFile & "'"

With fs
.NewSearch
.SearchSubFolders = True
.MatchTextExactly = True
.LookIn = "C:\Documents and Settings\MyPath"
.FileName = "*.xls"
If .Execute = 0 Then
Exit Sub
End If
If .Execute(SortBy:=msoSortbyFileName, SortOrder:
=msoSortOrderAscending) > 0 Then
For I = 1 To .foundfiles.Count
CurrentFile = .foundfiles(I)
Length = Len(CurrentFile)
CurrentFile = Right(CurrentFile, Length - 53)
rst.AddNew
rst!file = CurrentFile
rst.Update
If DCount("file", "qryGeneral", strCriteria) > 0 Then
rst.Delete
End If
Next
End If
End With

rst.Close
Me.Requery

End Sub

--
Message posted via http://www.accessmonster.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically Delete Records from a Table =?Utf-8?B?Rmlsbw==?= Microsoft Access VBA Modules 2 2nd Nov 2007 12:11 AM
A Way to automatically delete records =?Utf-8?B?RG9taW5pYw==?= Microsoft Access VBA Modules 24 9th Nov 2005 06:44 PM
Delete old records automatically? =?Utf-8?B?amVyaWRib2htYW5u?= Microsoft Access 5 5th Aug 2005 05:51 PM
automatically delete records w/duplicate address in excel =?Utf-8?B?UFVTSA==?= Microsoft Excel Misc 1 24th May 2005 12:48 PM
How do u automatically delete records after a set peroid of time =?Utf-8?B?ZmlzaGthYm9i?= Microsoft Access 2 19th Mar 2005 06:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:09 AM.