Sabtu, 28 Januari 2012

Tugas Dari Modul Halaman 9

Nama : Pandia Gunawan Situmorang

Npm : 1002292



Program Listing

Private Sub cmdproses_Click(Index As Integer)

Select Case Index

Case 0

Call hapus

kode.SetFocus

rubahcmd Me, False, True, True, True

Adodc1.Refresh

Case 1

If cmdproses(1).Caption = "&Simpan" Then

Call prosesdb(0)

Else

Call prosesdb(1)

End If

Case 2

X = MsgBox("Are you sure delete guys ??", vbQuestion + vbYesNo, "Barang")

If X = vbYes Then prosesdb 2

Call hapus

kode.SetFocus

Case 3

Call hapus

kode.SetFocus

Case 4

Unload Me

MsgBox "thanks guys", vbInformation, "Keluar"

End Select

End Sub

Private Sub Command1_Click()

Adodc1.Refresh

End Sub

Sub hapus()

kode.Enabled = True

clearform Me

Call rubahcmd(Me, True, False, False, False)

cmdproses(1).Caption = "&Simpan"

End Sub

Sub prosesdb(log As Byte)

Select Case log

Case 0

SQL = "insert into barang(Kode,Nama,Harga)" & _

"values('" & kode.Text & _

"','" & nama.Text & _

"','" & harga.Text & "')"

Case 1

SQL = "update barang set Nama='" & nama.Text & "'," & _

"Harga='" & harga.Text & "'" & _

"where Kode='" & kode.Text & "'"

Case 2

SQL = "delete from barang where Kode='" & kode.Text & "'"

End Select

MsgBox "Pemrosesan RECORD Database telah berhasil ....!", vbInformation, "Data Barang"

db.BeginTrans

db.Execute SQL, adCmdTable

db.CommitTrans

Call hapus

Adodc1.Refresh

kode.SetFocus

End Sub

Sub tampilbarang()

On Error Resume Next

kode.Text = rs!kode

nama.Text = rs!nama

harga.Text = rs!harga

End Sub

Private Sub Form_Load()

Call opendb

Call hapus

End Sub

Private Sub kode_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then

If kode.Text = "" Then

MsgBox "Masuk Kode Barang Bro!", vbInformation, "Kode Barang"

kode.SetFocus

Exit Sub

End If

SQL = "select*from barang where Kode='" & kode.Text & "'"

If rs.State = adStateOpen Then rs.Close

rs.Open SQL, db, adOpenDynamic, adLockOptimistic

If rs.RecordCount <> 0 Then

tampilbarang

Call rubahcmd(Me, False, True, True, True)

cmdproses(1).Caption = "&Edit"

kode.Enabled = False

Else

X = kode.Text

Call hapus

kode.Text = X

Call rubahcmd(Me, False, True, False, True)

cmdproses(1).Caption = "&Simpan"

End If

nama.SetFocus

End If

End Sub

Program Listing yang dibuat di dlm modul

Public db As New ADODB.Connection

Public rs As New ADODB.Recordset

Public rs1 As New ADODB.Recordset

Sub opendb()

If db.State = adStateOpen Then db.Close

db.CursorLocation = adUseClient

db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\jaringan\data2.mdb;Persist Security Info=False"

End Sub

Sub clearform(f As Form)

Dim ctl As Control

For Each ctl In f

If TypeOf ctl Is TextBox Then ctl.Text = ""

If TypeOf ctl Is ComboBox Then ctl.Text = ""

Next

End Sub

Sub rubahcmd(f As Form, L0 As Boolean, L1 As Boolean, L2 As Boolean, L3 As Boolean)

f.cmdproses(0).Enabled = L0

f.cmdproses(1).Enabled = L1

f.cmdproses(2).Enabled = L2

f.cmdproses(3).Enabled = L3

End Sub


ne lah Hasil Program nya :

Semoga Bermanfaat Untuk Anda yang membaca blog ne :)





2 komentar:

  1. I just came across your blog and found it be really helpful in my evaluation.Hey buddy that was a gud post lot of quality stuff and essential information
    BMW 135i AC Compressor

    BalasHapus