With Mr. Mandeno's help, I have learned how to put up this Public Function. It works good so far. In the function I have the MoveFire, Movelast and the check for end of file statement . Since Without them the function is still working fine. I am wondering if it not necessary to have them there? Phucon 'Find the record and delete it. On Error GoTo ErrorHandler With SearchForm.RecordsetClone ExitDelete: ErrorHandler:
Good morning
Public Function FindFormRecord(SearchForm As Access.Form, SearchField As String, SearchValue As Variant, Optional NoMatchMessage As String = "Record not found") As Boolean
Select Case .Fields(SearchField).Type
Case dbText
SearchValue = Chr$(34) & SearchValue & Chr$(34)
Case dbLong
SearchValue = SearchValue
End Select
.MoveFirst
.MoveLast
If Not .EOF Then
.FindFirst "[" & SearchField & "] = " & SearchValue
If Not .NoMatch Then 'if found then delete the record.
If MsgBox("Deleting records!" & vbCrLf & "If you click Yes, you will not be able to undo the deleted records." & vbCrLf & _
"Proceed to delete?", vbExclamation + vbYesNo, "Delete Confirm") = vbYes Then
.Delete
.Requery
End If
Else
MsgBox NoMatchMessage
GoTo ExitDelete
End If
Else
GoTo ExitDelete
End If
End With
Exit Function
MsgBox Err.Number & vbCrLf & Err.Description
Resume ExitDelete
Resume
End Function
Posted by: saigonf7q5@yahoo.com
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (1) |
Tidak ada komentar:
Posting Komentar