Dear Selvi,
Coba anda ganti kode anda menjadi seperti ini:
Private Sub listView1_DblClick()
On Error GoTo ErrPesan
Dim i As Integer
Dim TempIndex As Integer
Dim strSQL As String
Dim tempKode, tempstatus As String
If listView1.ListItems.Count = 0 Then Exit Sub
If listView1.SelectedItem Is Nothing Then Exit Sub
set con = New ADODB.Connection
TempIndex = listView1.SelectedItem.Index
tempKode = listView1.SelectedItem
' Sory disini object rsfilm masih belom jelas dimana posisi kursornya
jadi anda harus memastikan bahwa rsfilm berada pada posisi yang benar
sehingga anda tidak dapat membuat statement apakah status ada.
Sebaiknya anda coba ambil data status dari
listview1.selecteditem.subitem(?) dimana sub item status tersebut ada.
'asumsi bahwa kolom status berada pada subitem 3
if listview1.SelectedItem.SubItem(3) = "ADA" Then
jawab = MsgBox("Apakah Anda yakin Data " & kode_film & _
vbCrLf & " Akan dihapus ? ", vbInformation + vbYesNo)
If jawab = vbYes Then
con.CursorLocation = adUseServer
con.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=" &
App.Path & "\rental1.mdb"
strSQL = "DELETE * FROM film where kode_film = '" & tempKode & "'"
con.BeginTrans
con.Execute strSQL
con.CommitTrans
listView1.ListItems.Remove TempIndex
MsgBox "DATA FILM TELAH DIHAPUS"
set con = Nothing
End If
Else
MsgBox "Data belum bisa dihapus " & vbCrLf & " Film Masih diPinjam
", vbInformation
End If
Exit Sub
ErrPesan:
If con.State = adStateOpen Then
con.RollBackTrans
set con = nothing
endif
MsgBox "Error !!! " & vbCrLf & Err.Description, vbExclamation
End Sub
Note:
BeginTrans
The BeginTrans method starts a new transaction.
This method can also be used to return a long value that is the level
of nested transactions. A top level transaction has a return value of
1. Each additional level increments by one.
CommitTrans
The CommitTrans method saves all changes made since the last
BeginTrans method call, and ends the current transaction.
Since transactions can be nested, all lower-level transactions must be
resolved before you can resolve higher-level transactions.
RollbackTrans
The RollbackTrans method cancels all changes made since the last
BeginTrans method call, and ends the transaction.
Since transactions can be nested, all lower-level transactions must be
resolved before you can resolve higher-level transactions.
Ok semoga dengan sedikit Script diatas dapat membatu anda
Terima Kasih dan Selamat Mencoba
Salam,
Aiska Hendra
--- In [email protected], SELVI OYE <[EMAIL PROTECTED]> wrote:
>
> para pakar VB, minta tolong dong dgn scrip berikut :
> Database acces.
> Table Film :
> -Â Â Â Â Â Â Â kode_film
> -Â Â Â Â Â Â Â judul
> -Â Â Â Â Â Â Â qty
> -Â Â Â Â Â Â Â status ( âadaâ & âkeluarâ)
> Â
> kronologisnya :
> jika judul film dgn qty 3 dan dipinjam 1 berarti tinggal 2 dgn
status âkeluarâ.
> Nah jika film akan dihapus dari database, maka akan diselecsi dgn
status âadaâ jadi jika status ada maka bisa dihapus.
> Â
> Ok, selanjutnya aku udah bikin scrip di Vb seperti ini :
> Â
> Private Sub listView1_DblClick()
> On Error GoTo ErrPesan
> Dim i As Integer
> Dim TempIndex As Integer
> Dim strSQL As String
> Dim tempKode, tempstatus As String
> Â
> Â
> Â Â Â If listView1.ListItems.Count = 0 Then
> Â Â Â Â Â Â Â Â Exit Sub
> Â Â Â End If
> Â
> Â TempIndex = listView1.SelectedItem.Index
> Â tempKode = listView1.ListItems.Item(TempIndex)
> Â
> Â Â 'Konfirmasi penghapusan record
> Â Â
> Â jawab = MsgBox("Apakah Anda yakin Data " & kode_film & _
> Â vbCrLf & " Akan dihapus ? ", vbInformation + vbYesNo)
> Â If jawab = vbNo Then Exit Sub
> Â con.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=" &
App.Path & "\rental1.mdb"
> Â If rsfilm.Fields("status") = "ADA" Then
> Â Â Â Â Â Â Â strSQL = "DELETE FROM film where kode_film = '" &
tempKode & "'"
> Â Â Â Â Â Â Â
> Â Â Â Â Â Â Â con.Execute strSQL
> Â Â Â Â Â Â Â MsgBox "DATA FILM TELAH DIHAPUS"
> Â
> Â label6.Caption = "Total Record : " & rsfilm.RecordCount
> Â i = listView1.SelectedItem.Index
> Â listView1.ListItems.Remove i
> Â End If
> Â Exit Sub
> ErrPesan:
> Â Â MsgBox "Data belum bisa dihapus " & vbCrLf & " Film Masih
diPinjam ", vbInformation
> Â End Sub
> Â
> Tapi yg ada adalah masuk ke errpesan, sehingga data tidak bisa dihapus.
> Mohon petunjuknya.
>
>
>
> ________________________________________________________
> Kunjungi halaman depan Yahoo! Indonesia yang baru!
> http://id.yahoo.com/
>
> [Non-text portions of this message have been removed]
>