Phucon-
Don't know how you posted this, but the code is unreadable! Let's see if I can straighten it out:
'Find the record and delete it.
Public Function FindFormRecord(SearchForm As Access.Form, _
SearchField As String, SearchValue As Variant, _
Optional NoMatchMessage As String = "Record not found") As Boolean
On Error GoTo ErrorHandler
'With SearchForm.Recordset
With SearchForm.RecordsetClone
Select Case .Fields(SearchField).Type
Case dbText
SearchValue = Chr$(34) & SearchValue & Chr$(34)
Case dbLong
SearchValue = SearchValue
End Select
If Not .EOF Then
.FindFirst "[" & SearchField & "] = " & SearchValue
If Not .NoMatch Then 'if found then delete the record.
If MsgBox("You are deleting this record and all related records. " & vbCrLf & "Proceed to delete?", vbInformation + vbYesNo, "Confirm Delete") = vbYes Then
.Delete
TempVars.Add "tvYes", True
End If
Else
TempVars.Add "tvYes", False
MsgBox NoMatchMessage
GoTo ExitDelete
End If
Else
GoTo ExitDelete
End If
End With
ExitDelete:
Exit Function
ErrorHandler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume ExitDelete
End Function
Now for the difference:
RecordsetClone gets you an *exact* copy of the form's recordset, but it is not the same recordset - it's literally a "clone." It does have all the same properties and records, so that's why you can search for something in the clone and then use the Bookmark property if found to move to the found record in the actual form recordset. If you delete a record from the Clone, it disappears from the original copy.
Recordset is the exact same set of records that the form is using, and the form is sensitive to any manipulations you do. Thus, if you do a FindFirst or a MoveNext, the form display will also move in response. That won't happen if you use the RecordsetClone, which is why you end up having to sync Bookmarks.
John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
SQL Queries for Mere Mortals
(Paris, France)
On Sep 25, 2014, at 4:27 PM, saigonf7q5@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
A while ago someone (I don't remember his name and the post number) on this websiteme assisted to put up the below function, it works pretty good and I have been using it.
In the below procedure, the RecordsetClone property is used, somehow I have not yet had a clear understanding that the differences between the Recordset and the RecordsetClone. I only understand the RecordsetClone is a copy of the recordset. I have also tried, changed the RecordsetClone to Recordset to try to see if it makes any difference. However it seems to be working ok so far and give me no trouble. Can someone point me to a clear understanding how to use the 2 properties?
__._,_.___
Posted by: John Viescas <johnv@msn.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (2) |
.
__,_._,___
Tidak ada komentar:
Posting Komentar