Selasa, 15 Juli 2014

Re: [MS_AccessPros] Delete Function

 

Phucon-


The MoveFirst and MoveLast are unnecessary.

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 Jul 15, 2014, at 6:36 PM, saigonf7q5@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


Good morning

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.
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.RecordsetClone
    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

ExitDelete:
    Exit Function

ErrorHandler:
        MsgBox Err.Number & vbCrLf & Err.Description
        Resume ExitDelete
        Resume
End Function


__._,_.___

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)

Yahoo Groups
Control your view and sort preferences per Yahoo Group
You can now control your default Sort & View Preferences for Conversations, Photos and Files in the membership settings page.


.

__,_._,___

Tidak ada komentar:

Posting Komentar