Rabu, 14 Desember 2011

Membuat Record set Di VB 6.0

Buat lah Form Dengan Lay-Out Sbb:

Atur properti untuk Kontrol - kontrol Sbb:



Kontrol
Properti
Nilai
Form1
Caption
Formulir Data Barang
Data1
Name
Caption
Connect
DatabaseName
RecordsetType
RecordSource
dbPembelian
Database Pembelian
Acces
C:\ase\pembelian.mdb
0-Table
Barang
Label1
Caption
Kode Barang
Label2
Caption
Nama
Label3
Caption
Satuan
Label4
Caption
Harga satuan
Text1
Name
DataField
DataSource
Text
Txtkode
Kode
Dbpembelian
Kosongkan
Text2
Name
DataField
DataSource
Text
Txtnama
Nama
Dbpembelian
Kosongkan
Text3
Name
DataField
DataSource
Text
Txtsatuan
Satuan
Dbpembelian
Kosongkan
Text4
Name
DataField
DataSource
Text
Txtharga
Harga
Dbpembelian
Kosongkan
Command1
Nama
Caption
ToolTypeText
CmdTop
Top
Top
Command2
Nama
Caption
ToolTypeText
CmdPrevious
Previous
Previous
Command3
Nama
Caption
ToolTypeText
CmdNext
Next
Next
Command4
Nama
Caption
ToolTypeText
CmdLast
Last
Last
Command5
Nama
Caption
ToolTypeText
CmdNew
New
New
Command6
Nama
Caption
ToolTypeText
CmdSave
Save
Save
Command7
Nama
Caption
ToolTypeText
CmdUndo
Undo
Undo
Command8
Nama
Caption
ToolTypeText
CmdEdit
Edit
Edit
Commsand9
Nama
Caption
ToolTypeText
CmdDel
Delete
Delete
Command10
Nama
Caption
ToolTypeText
CmdFind
Find
Find
Command11
Nama
Caption
ToolTypeText
CmdExit
Exit
Exit




Tulis Kode Program sebagai brikut
Dim tambah As Boolean
Sub nonaktif()
Dim ctl As Control
For Each ctl In FormBrg
If TypeName(ctl) = "textbox" Then
ctl.Locked = True
End If
If TypeName(ctl) = "combobox" Then
ctl.Locked = True
End If
Next
End Sub

Private Sub CmdDel_Click()
Del = MsgBox("Record ini dihapus ?", 36, "Konfirmasi")
If Del = 6 Then
dbPembelian.Recordset.Delete
dbPembelian.Recordset.MoveNext
If dbPembelian.Recordset.EOF Then
dbPembelian.Recordset.MoveLast
End If
End If
End Sub

Private Sub CmdEdit_Click()
dbPembelian.Recordset.Edit
aktif
End Sub

Private Sub CmdExit_Click()
Unload Me
End Sub

Private Sub CmdFind_Click()
Dim mkode As String * 6
mkode = InputBox("ketik Kode barangnya :", "Pencarian Data Barang")
msyarat = "kode=" '& mkode &"'"
dbPembelian.Recordset.Index = "KodeBrg"
dbPembelian.Recordset.Seek "=", mkode
If dbPembelian.Recordset.NoMatch Then
MsgBox "Record kode Barang" + cr + "Tidak ada", 16, "Informasi"
End If
End Sub

Private Sub CmdLast_Click()
dbPembelian.Recordset.MoveLast
MsgBox "Sudah di akhiri record", 16, "Informasi"
End Sub

Private Sub CmdNew_Click()
tambah = True
dbPembelian.Recordset.AddNew
kosong
aktif
End Sub

Private Sub CmdNext_Click()
dbPembelian.Recordset.MoveNext
If dbPembelian.Recordset.EOF Then
dbPembelian.Recordset.MoveLast
MsgBox "Sudah di akhir record", 16, "Informasi"
End If
End Sub

Private Sub CmdPrevious_Click()
dbPembelian.Recordset.MovePrevious
If dbPembelian.Recordset.BOF Then
dbPembelian.Recordset.MoveFirst
MsgBox "Sudah di awal record", 16, "Informasi"
End If
End Sub


Private Sub CmdSave_Click()
If tambah = True Then
dbPembelian.Recordset.Update
Else
dbPembelian.Recordset.Update
End If
nonaktif
End Sub

Private Sub CmdTop_Click()
dbPembelian.Recordset.MoveFirst
MsgBox "sodah di awal record", 16, "Informasi"
End Sub

Private Sub CmdUndo_Click()
dbPembelian.Recordset.CancelUpdate
dbPembelian.Recordset.MoveLast
nonaktif
End Sub

Private Sub Form_Load()
nonaktif
tambah = False
End Sub

Sub kosong()
Dim ctl As Control
For Each ctl In FormBrg
If TypeName(ctl) = "textbox" Then
ctl.Text = ""
End If
If TypeName(ctl) = "combobox" Then
ctl.Text = ""
End If
Next
End Sub

Sub aktif()
Dim ctl As Control
For Each ctl In FormBrg
If TypeName(ctl) = "textbox" Then
ctl.Locked = False
End If
If TypeName(ctl) = "combobox" Then
ctl.Locked = False
End If
Next
End Sub


Jalankan Aflikasi tersebut dengan menekan F5

Simpan Program di atas dengan nama LAT01.

0 komentar:

Posting Komentar