Form Data
Barang Dengan Menggunakan Database
Program yang akan dibuat adalah Program data barang
Cara menghubungkan database Ms. Access pada vb 6.0, sebagai berikut :
Buat database pada Ms. Access
Untuk menghubungkan database Ms. Access pada program vb yang telah kita buat, diperlukan toolbox Adodc dan DataGrid. cara menambahkannya yaitu : Klik kanan pada daerah toolbox >> Components >> Pilih Microsoft ADO Data Control 6.0 (OLEDB) dan Microsoft DataGridControl 6.0 (OLEDB)
Setelah toolbox Adodc dan DataGrid telah digunakan Klik kanan pada Adodc1 >> ADODC Properties >> Klik Build pada Use Connection String >> Select or enter a database name >> Tes Connection >> OK >> Record Source >> Pada Command Type pilih adCmdTable >> Apply >> OK
Tampilan Form Data
Barang
Code Program :
Private Sub CmdCari_Click()
With Adodc1.Recordset
.MoveFirst
Do While Not .EOF
If UCase(TxtCari.Text) =
UCase(.Fields(0).Value) Then
Exit Sub
End If
.MoveNext
Loop
Pesan = MsgBox("Data Tidak
Ditemukan", vbInformation + vbOKOnly, "Perhatian")
End With
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdCetak_Click()
MsgBox (ltanggal +
vbCrLf + ljam + vbCrLf + vbCrLf + "Kode Barang : " + TxtKodeBarang + vbCrLf +
"Nama Barang : " +
TxtNamaBarang + vbCrLf + "Harga Barang : Rp" + TxtHarga + vbCrLf +
"Stock Barang : " + TxtStock +
vbCrLf)
End
Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdFirst_Click()
Adodc1.Recordset.MoveFirst
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdHapus_Click()
Hapus = MsgBox("Anda Yakin Ingin
Menghapus ?", vbQuestion + vbYesNo, "Perhatian")
If Hapus = vbYes Then
Adodc1.Recordset.Delete
End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private
Sub CmdKeluar_Click()
Pesan = MsgBox("Tutup Form Data
Barang ?", vbQuestion + vbYesNo, "Question")
If Pesan = vbYes Then
End
Else
Form1.SetFocus
End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdLast_Click()
Adodc1.Recordset.MoveLast
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private
Sub CmdNext_Click()
Adodc1.Recordset.MoveNext
If
Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdPrev_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdTambah_Click()
If CmdUbah.Caption = "Ubah"
Then
CmdUbah.Caption = "Simpan"
Adodc1.Recordset.AddNew
End If
End Sub
-----------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub CmdUbah_Click()
If CmdUbah.Caption = "Ubah"
Then
CmdUbah.Caption = "Simpan"
CmdTambah.Enabled = False
CmdHapus.Enabled = False
pencarian.Enabled = False
step.Enabled = False
Databarang.Enabled = True
DataGrid1.Enabled = False
Adodc1.Recordset.Update
Else
CmdUbah.Caption = "Ubah"
CmdTambah.Enabled = True
CmdHapus.Enabled = True
pencarian = True
step.Enabled = True
Databarang.Enabled = True
DataGrid1.Enabled = True
Adodc1.Recordset.Update
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Timer1_Timer()
ljam.Caption = Time
ltanggal.Caption = Format(Date,
"dddd,d mmmm,yyyy")
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Timer2_Timer()
Timer2.Enabled = True
If (Label5.Left + Label5.Width) <= 0
Then
Label5.Left = Me.Width
End If
Label5.Left = Label5.Left - 100
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub TxtHarga_Change()
If Not IsNumeric(TxtHarga.Text) Then
TxtHarga.Text = ""
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub TxtNamaBarang_Change()
If TxtNamaBarang.Text =
"Mouse" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Mouse.jpg")
ElseIf TxtNamaBarang.Text =
"Keyboard" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Keyboard.jpg")
ElseIf TxtNamaBarang.Text =
"Monitor" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Monitor.jpg")
ElseIf TxtNamaBarang.Text =
"Speaker" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Speaker.jpg")
ElseIf TxtNamaBarang.Text =
"Printer" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Printer.jpg")
ElseIf TxtNamaBarang.Text =
"Flashdisk" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Flashdisk.jpg")
ElseIf TxtNamaBarang.Text = "Screen
Protect" Then
Image2.Picture =
LoadPicture("C:\Users\Novia A\Pictures\Barang\Screen Protect.jpg")
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub TxtStock_Change()
If Not IsNumeric(TxtStock.Text) Then
TxtHarga.Text = ""
End If
End Sub
Meski banyak kekurangan dalam program ini, semoga program ini dapat bermanfaat :)
Komentar
Posting Komentar