Mengelak data diedit secara tidak sengaja

Submitted by admin on Sat, 06/14/2014 - 01:59

Salah satu cara yang mudah adalah seperti berikut (Access 2007) : 

  • Buka Form dengan format Design
  • Buka property pada Field yang hendak diubah dan buat:
    • Lock > Yes
    • On key Down > click Event Procedure & masukan kod di bawah ... cth kita nak ubah Filed 'Nama'
Private Sub Nama_KeyDown(KeyCode As Integer, Shift As Integer)
'If the field is not flagged for editing, prompt the user
'for confirmation about unlocking the control.
    If fEditNama = False Then
        If MsgBox("Do you want to change the Nama for this property?", _
                  vbYesNo + vbQuestion + vbDefaultButton2, _
                  "Please Confirm:") = vbYes Then

            'If the response is Yes, unlock the field
            'and flag it as being edited.
            Me!Nama.Locked = False
            fEditPropertyNama = True
        End If
    End If
End Sub