Design Form Barang |
Sub awal()
Adodc1.RecordSource = "select * from barang"
Adodc1.Refresh
For Each Control In Me
If TypeOf Control Is TextBox Then
Control.Enabled = False
Control.Text = ""
End If
Next
txtcari.Enabled = True
cmdsave.Enabled = False
cmdedit.Enabled = False
cmddel.Enabled = False
cmdcancel.Enabled = False
End Sub
Sub aktif()
For Each Control In Me
If TypeOf Control Is TextBox Then
Control.Enabled = True
End If
Next
End Sub
Sub tampil()
txtkdbrg.Text = Adodc1.Recordset.Fields("kdbrg")
txtnmbrg.Text = Adodc1.Recordset.Fields("nmbrg")
txtharga.Text = Adodc1.Recordset.Fields("harga")
txtstok.Text = Adodc1.Recordset.Fields("stok")
End Sub
Sub bersih()
For Each Control In Me
If TypeOf Control Is TextBox Then
Control.Text = ""
End If
Next
End Sub
''Listing tombol navigasi dan pencarian:
Private Sub cmdfirst_Click()
Adodc1.Recordset.MoveFirst
tampil
cmdedit.Enabled = True
cmdadd.Enabled = True
cmddel.Enabled = True
cmdedit.SetFocus
End Sub
''Listing Tombol Fungsi:
Private Sub cmdadd_Click()
isi = True
bersih
aktif
cmdadd.Enabled = False
cmdsave.Enabled = True
cmdcancel.Enabled = True
cmdedit.Enabled = False
cmddel.Enabled = False
txtkdbrg.SetFocus
End Sub
Private Sub cmdcancel_Click()
awal
tampil
cmdadd.Enabled = True
cmdsave.Enabled = False
cmdedit.Enabled = True
cmddel.Enabled = True
cmdcancel.Enabled = True
End Sub
Private Sub cmdclose_Click()
Unload Me
'frm_menu.Show
'frm_menu.Enabled = True
End Sub
Private Sub cmdlast_Click()
Adodc1.Recordset.MoveLast
tampil
cmdedit.Enabled = True
cmdadd.Enabled = True
cmddel.Enabled = True
cmdedit.SetFocus
End Sub
Private Sub cmdsave_Click()
Adodc1.RecordSource = "select * from barang"
With Adodc1.Recordset
.AddNew
.Fields("kdbrg") = txtkdbrg.Text
.Fields("nmbrg") = txtnmbrg.Text
.Fields("harga") = txtharga.Text
.Fields("stok") = txtstok.Text
.Update
End With
Adodc1.Refresh
cmdadd.Enabled = True
awal
tampil
cmdadd.Enabled = True
cmdsave.Enabled = False
cmdedit.Enabled = True
cmddel.Enabled = True
cmdcancel.Enabled = True
End Sub
Private Sub cmdnext_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
MsgBox "Sudah di Akhir Record", vbCritical, ":: Informasi ::"
Adodc1.Recordset.MoveLast
End If
tampil
cmdedit.Enabled = True
cmdadd.Enabled = True
cmddel.Enabled = True
cmdedit.SetFocus
End Sub
Private Sub cmdback_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
MsgBox "Sudah di Awal Record", vbCritical, ":: Informasi ::"
Adodc1.Recordset.MoveFirst
End If
tampil
cmdedit.Enabled = True
cmdadd.Enabled = True
cmddel.Enabled = True
cmdedit.SetFocus
End Sub
Private Sub cmdcari_Click()
With Adodc1.Recordset
.Find "kdbrg='" & txtcari.Text & "'"
If .EOF Then
MsgBox "Kode " + txtcari.Text + " tidak ada", 34, "Info"
txtcari.Text = ""
txtnabar.Text = ""
txtcari.SetFocus
Else
Adodc1.Refresh
txtnabar.Text = .Fields("nmbrg")
End If
End With
End Sub
Private Sub cmdedit_Click()
If cmdedit.Caption = "&EDIT" Then
cmdedit.Caption = "&UPDATE"
aktif
txtkdbrg.Enabled = False
txtnmbrg.SetFocus
cmdadd.Enabled = False
cmddel.Enabled = False
cmdsave.Enabled = False
cmdcancel.Enabled = True
Else
If cmdedit.Caption = "&UPDATE" Then
Adodc1.Recordset.Fields("nmbrg") = txtnmbrg.Text
Adodc1.Recordset.Fields("harga") = txtharga.Text
Adodc1.Recordset.Fields("stok") = txtstok.Text
Adodc1.Recordset.Update
cmdedit.Caption = "&EDIT"
txtnmbrg.Enabled = False
txtharga.Enabled = False
txtstok.Enabled = False
cmdadd.Enabled = True
cmdsave.Enabled = False
cmdedit.Enabled = True
cmddel.Enabled = True
cmdcancel.Enabled = True
End If
End If
End Sub
Private Sub cmddel_Click()
If Len(Trim(txtkdbrg.Text)) = "" Then
Exit Sub
End If
p = MsgBox("Benar mo dihapus?", 32 + 4, "Tanya")
If p = vbYes Then
Adodc1.Recordset.Delete
awal
tampil
Else
awal
tampil
End If
Adodc1.RecordSource = "select * from barang"
Adodc1.Refresh
cmdadd.Enabled = True
cmdsave.Enabled = False
cmdedit.Enabled = True
cmddel.Enabled = True
cmdcancel.Enabled = True
End Sub
Private Sub SSTab1_Click(PreviousTab As Integer)
Adodc1.RecordSource = "select * from barang"
Adodc1.Refresh
End Sub
Private Sub Form_Activate()
awal
tampil
cmdadd.Enabled = True
cmdsave.Enabled = False
cmdedit.Enabled = True
cmddel.Enabled = True
cmdcancel.Enabled = True
End Sub
Private Sub txtkdbrg_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
With Adodc1.Recordset
.Find "kdbrg='" & txtkdbrg.Text & "'"
If Not .EOF Then
MsgBox "Kode " + txtcari.Text + " sudah digunakan, ganti dengan kode lain!!", 34, "Info"
txtkdbrg.Text = ""
txtkdbrg.SetFocus
Else
txtnmbrg.SetFocus
End If
End With
End If
End Sub