Kaskus

Tech

xaberiusAvatar border
TS
xaberius
[VB6] Program Coba-coba
List table (MySQL)
  1. Table jenis barang



Module (MySQL)
  1. Module Utama



List Flowchart (MySQL)
  1. Flowchart Form Jenis Barang
  2. Flowchart cari jenis barang




List Design (MySQL)
  1. Design Form Jenis Barang
  2. Design Cari Jenis Barang


List Coding (MySQL)
  1. Coding Jenis Barang


Diubah oleh xaberius 19-06-2013 16:42
0
1.9K
15
GuestAvatar border
Komentar yang asik ya
Mari bergabung, dapatkan informasi dan teman baru!
Programmer Forum
Programmer Forum
KASKUS Official
20.3KThread5.1KAnggota
Tampilkan semua post
xaberiusAvatar border
TS
xaberius
#9
Code:
Dim RsBarang As New ADODB.Recordset
Private Sub CmdAdd_Click()
'saat menekan tombol add
'txtkode diisi kode jenis barang otomatis
TxtKode = Trim(KodeAuto)

'menghapus semua isian pada field
TxtNama = ""
TxtAktif = "Y"
End Sub

Private Sub CmdCancel_Click()
'saat ditekan tombol cancel maka
'1. ambil data dari db -> grid
refreshData

'2. membersihkan semua field isian
bersih
TxtKode.SetFocus
End Sub

Sub bersih()
'prosedur berishkan field isian
TxtKode = ""
TxtNama = ""
TxtAktif = "Y"
End Sub

Private Sub CmdHapus_Click()
'saat ditekan tombol hapus
'1. muncul pertanyaan yakin dihapus?
If MsgBox("Yakin dihapus?", vbOKCancel) = vbOK Then

'2. tandai jenis barang pada db
SQL = "update jenisbarang set aktif='N',tgledit='" & FormatTgl(Date) & "' where kodejenis='" & Trim(TxtKode) & "'"
DbCon.Execute SQL

'3. lakukan prosedur tombol cancel
CmdCancel_Click
End If

End Sub

Private Sub CmdSave_Click()
'saat ditekan tombol save
'1. periksa txtkode kosong? ulangi isian kalau kosong
If Trim(TxtKode) = "" Then
MsgBox "Kode Jenis masih kosong"
TxtKode.SetFocus
Exit Sub

'2. periksa txtnama kosong? ulangi isian kalau kosong
ElseIf Trim(TxtNama) = "" Then
MsgBox "Nama Jenis Masih Kosong"
TxtNama.SetFocus
Exit Sub
End If

'3. cari data barang yang diinputkan di db
SQL = "select * from jenisBarang where kodejenis='" & Trim(TxtKode) & "'"
Set RSFind = DbCon.Execute(SQL)

If Not RSFind.EOF Then
'4. klo ada lakukan update data
SQL = "update jenisbarang set namajenis='" & Trim(TxtNama) & "',aktif='" & Trim(TxtAktif) & _
"', tgledit='" & FormatTgl(Date) & "' where kodejenis='" & Trim(TxtKode) & "'"
Else
'5. klo tidak ada lakukan insert data
SQL = "insert into jenisbarang(kodejenis,namaJenis,aktif,flag1,tglBuat,tglEdit) values ('" & _
Trim(TxtKode) & "','" & Trim(TxtNama) & "','" & Trim(TxtAktif) & "','','" & _
FormatTgl(Date) & "','" & FormatTgl(Date) & "')"
End If

DbCon.Execute SQL

'6 muncul pesan
MsgBox "Data Tersimpan"

'7. lakukan prosedur tombol cancel
CmdCancel_Click
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'saat ditekan tombol
'tombol Esc maka akan keluar dari menu jenis barang
If KeyCode = 27 Then Unload Me

'tombol F3 akan menyimpan data jenis barang
If KeyCode = vbKeyF3 Then CmdSave_Click

'tombol F8 untuk membatalkan input data jenis barang
If KeyCode = vbKeyF8 Then CmdCancel_Click

'tombol F2 untuk memulai input data jenis barang baru
If KeyCode = vbKeyF2 Then CmdAdd_Click
End Sub

Private Sub Form_Load()
'saat form diload yang dilakukan :
'1. memberishkan field isian
bersih

'2. isi data jenis barang dari db -> grid
refreshData

'3. isi kode otomatis jenis barang
TxtKode = Trim(KodeAuto)
End Sub

Sub refreshData()
'refresh data untuk ambil data dari db -> grid

' kosongkan grid
Set Grid.DataSource = Nothing

'string SQl
SQL = "select Kodejenis as 'Kode Jenis' ,namaJenis as 'Nama Jenis' from jenisBarang " & _
" order by NamaJenis"

'masukkan data dari db -> ado recordset
Set RsBarang = DbCon.Execute(SQL)

'isi datagrid dengan data dari ado recordset
Set Grid.DataSource = RsBarang
Grid.Refresh
End Sub


Private Sub Grid_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
TxtKode = Trim(Grid.Columns(0).Text)
TxtKode_LostFocus
End Sub

Private Sub TxtAktif_KeyPress(KeyAscii As MSForms.ReturnInteger)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub TxtKode_GotFocus()
'saat diklik maka blok isinya
SendKeys "{Home}+{End}"
End Sub

Private Sub TxtKode_KeyPress(KeyAscii As MSForms.ReturnInteger)
'ubah isian menjadi huruf besar
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub TxtKode_LostFocus()
'saat pindah dari txtkode
'1. meminta data jenis barang berdasarkan kode jenis yang ada pada txtkode

SQL = "select * from jenisbarang where kodejenis='" & Trim(TxtKode) & "'"
Set RSFind = DbCon.Execute(SQL)

'2. menampilkan data di field isian
If Not RSFind.EOF Then
TxtKode = RSFind!kodeJenis
TxtNama = RSFind!namajenis
TxtAktif = RSFind!Aktif

'3. menujuk ke data jenis barang di grid
If TxtAktif = "Y" Then
RsBarang.Find "[kode jenis]='" & Trim(TxtKode) & "'", , adSearchForward, 1
'If RsBarang.EOF Then Exit Sub
End If

End If
End Sub
Function KodeAuto()
'fungsi membuat kode otomatis pada kode jenis barang
'kode akan bertambah secara otomatis dari nomor kode terakhir
SQL = "Select kodeJenis from jenisbarang order by kodejenis Desc"
Set RSFind = DbCon.Execute(SQL)
If RSFind.BOF Then
KodeAuto = "JNS-0001"
Else
KodeAuto = "JNS-" & Format(CInt(Right(RSFind!kodeJenis, 4)) + 1, "0000")
End If
End Function

Private Sub TxtNama_KeyPress(KeyAscii As MSForms.ReturnInteger)
' mengubah isian menjadi huruf besar
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub


Spoiler for Sumber:
Diubah oleh xaberius 19-06-2013 14:00
0
Ikuti KASKUS di
© 2026 KASKUS, PT Darta Media Indonesia. All rights reserved.