Ini Berikut Listing Kodingnya :
Private Sub CmdInput_click()
'atur command saat cmdinput diklikIf Cmdinput.Caption = "&Input" Then
Cmdinput.Caption = "&Simpan"
Cmdedit.Enabled = False
Cmdhapus.Enabled = False
Cmdtutup.Caption = "&Batal"
SiapIsi
KosongkanText
Text1.SetFocus
Else
'mencegah data kosong sebelum disimpan
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Then
MsgBox "Data Belum Lengkap...!"
Else
'simpan data
Dim SQLTambah As String
nama = Text2
Text2 = Replace(Text2, "'", "''")
SQLTambah = "Insert Into Barang (KodeBrg,NamaBrg,HargaBeli,HargaJual,JumlahBrg) values " & _
"('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "','" & Text5 & "')"
Conn.Execute SQLTambah
form_activate
Call Kondisiawal
End If
End If
End Sub
Private Sub CmdEdit_Click()
'On Error Resume Next
If Cmdedit.Caption = "&Edit" Then
Cmdinput.Enabled = False
Cmdedit.Caption = "&Simpan"
Cmdhapus.Enabled = False
Cmdtutup.Caption = "&Batal"
SiapIsi
Text1.SetFocus
Else
If Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Then
MsgBox "Masih Ada Data Yang Kosong"
Else
'edit data
Dim SQLEdit As String
nama = Text2
Text2 = Replace(Text2, "'", "''")
SQLEdit = "Update Barang Set NamaBrg= '" & Text2 & "', HargaBeli='" & Text3 & "', HargaJual='" & Text4 & "',JumlahBrg='" & Text5 & "' where KodeBrg='" & Text1 & "'"
Conn.Execute SQLEdit
form_activate
Call Kondisiawal
End If
End If
End Sub
Private Sub CmdHapus_Click()
If Cmdhapus.Caption = "&Hapus" Then
Cmdinput.Enabled = False
Cmdedit.Enabled = False
Cmdtutup.Caption = "&Batal"
KosongkanText
SiapIsi
Text1.SetFocus
End If
End Sub
Private Sub CmdTutup_Click()
Select Case Cmdtutup.Caption
Case "&Tutup"
Unload Me
Case "&Batal"
TidakSiapIsi
Kondisiawal
End Select
End Sub
'buat prosedur untuk mencari kode barang
Function CariData()
Call BukaDB
RSBarang.Open "Select * From Barang where KodeBrg='" & Text1 & "'", Conn
End Function
Private Sub Text1_Keypress(Keyascii As Integer)
Keyascii = Asc(UCase(Chr(Keyascii)))
If Keyascii = 13 Then
'kode barang harus 6 digit
If Len(Text1) < 6 Then
MsgBox "Kode Harus 6 Digit"
Text1.SetFocus
Exit Sub
Else
Text2.SetFocus
End If
If Cmdinput.Caption = "&Simpan" Then
Call CariData
If Not RSBarang.EOF Then
TampilkanData
MsgBox "Kode Barang Sudah Ada"
KosongkanText
Text1.SetFocus
Else
Text2.SetFocus
End If
End If
If Cmdedit.Caption = "&Simpan" Then
Call CariData
If Not RSBarang.EOF Then
TampilkanData
Text1.Enabled = False
Text2.SetFocus
Else
MsgBox "Kode Barang Tidak Ada"
Text1 = ""
Text1.SetFocus
End If
End If
If Cmdhapus.Enabled = True Then
Call CariData
If Not RSBarang.EOF Then
TampilkanData
Dim pesan As String
pesan = MsgBox("Yakin akan dihapus", vbYesNo)
If pesan = vbYes Then
Dim SQLHapus As String
SQLHapus = "Delete From Barang where kodebrg= '" & Text1 & "'"
Conn.Execute SQLHapus
Kondisiawal
form_activate
Else
Kondisiawal
Cmdhapus.SetFocus
End If
Else
MsgBox "Data Tidak ditemukan"
Text1.SetFocus
End If
End If
End If
End Sub
Private Sub Text2_Keypress(Keyascii As Integer)
'ubah karakter jadi huruf besar
Keyascii = Asc(UCase(Chr(Keyascii)))
If Keyascii = 13 Then Text3.SetFocus
End Sub
Private Sub Text3_Keypress(Keyascii As Integer)
If Keyascii = 13 Then Text4.SetFocus
'hanya dapat diisi angka 0 - 9
If Not (Keyascii >= Asc("0") And Keyascii <= Asc("9") Or Keyascii = vbKeyBack) Then Keyascii = 0
End Sub
'harga jual jangan <= harga beli
Private Sub Text4_Keypress(Keyascii As Integer)
If Keyascii = 13 Then
If Val(Text4) <= Val(Text3) Then
MsgBox "harga jual jangan <=harga beli"
Text4 = ""
Text4.SetFocus
Exit Sub
Else
Text5.SetFocus
End If
End If
If Not (Keyascii >= Asc("0") And Keyascii <= Asc("9") Or Keyascii = vbKeyBack) Then Keyascii = 0
End Sub
Private Sub Text5_Keypress(Keyascii As Integer)
If Keyascii = 13 Then
If Cmdinput.Enabled = True Then
Cmdinput.SetFocus
ElseIf Cmdedit.Enabled = True Then
Cmdedit.SetFocus
End If
End If
If Not (Keyascii >= Asc("0") And Keyascii <= Asc("9") Or Keyascii = vbKeyBack) Then Keyascii = 0
End Sub
Kita Lanjut buat Besok ya Kawan Oia Lupa Untuk Posting Membuat Database nya yaa ya sudah kalo ada waktu Sobat PW kita buatin ya semoga masih nongkrong di Blog Sobat PW
Post a Comment