Selasa, 20 Agustus 2013

Error Message "Could Not Update; Currently Locked"

Error Message "Could Not Update; Currently Locked" muncul ketika terjadi Update data pada tabel di Vb 6 dengan menggunakan database MS Access.

Agar error tersebut tidak terjadi maka tambahkan syntax berikut saat Open recordsetnya
' Begin a new transaction.
    con.BeginTrans
'=============
  'OPEN TABLE
'=============
' Close the transaction.
   con.CommitTrans

Misal Con adalah Connection dan Rs adalah Recordsetnya.

 ' Begin a new transaction.
    con.BeginTrans
       With rs
                ' Specify the lock type for the table.
                .LockType = adLockOptimistic
                .CursorType = adOpenKeyset

                 ' Open a recordset for table1  table.
                .Open "select * from Table1 where UserD='" & strUser & "' And Nama='" & strNama & "' and Passwd='" & strPwd & "'", con
                If .EOF Then
                    .AddNew
                    .Fields(0) = strUser
                    .Fields(1) = strNama
                    .Fields(2) = cntr
                    
                Else
                    .Fields(0) = strUser
                    .Fields(1) = strNama
                    .Fields(2) = cntr
                    
                End If
                .Update
                .Close
            End With
        
           Set rs = Nothing
           
           ' Update the Table1 table through SQL command.
           con.Execute "UPDATE Table1 SET STATUS='1' WHERE UserD='" & strUser & "' And Nama='" & strNama & "' and Passwd='" & strPwd & "'"
           
   con.CommitTrans