Anda di halaman 1dari 31

VB

II

PERTEMUAN
PRA UTS

Cara Membuka Microsoft Access


Start

All Program

Microsoft Office

Membuat Database

File
New
Blank database
(format access
2002-2003)

Ms. Access

simpan dengan nama: penjualan.mdb

Membuat tabel
1. Barang
Field
Data
Field Size
Forma
name
Type
t
Kobar
Text
5
Pk
Nabar
Text
20
Hbeli
Currency Currency
Hjual
Currency Currency
Stok
Number Long integer
Isi data barang sebanyak 5 record
2. Pengguna
Field
Data
Field Size
Forma
name
Type
t
Userid
Text
5
Pk
Nmuser
Text
20
Password Text
10
Akses
Text
15
Isi data pengguna sebanyak 5 record dan akses = admin.
3. Faktur
Field
Data
Field Size
Forma
name
Type
t
Nofak
Text
10
Pk
Tglfak
Date/tim
e
Userid
Text
20
Total
Currency Currency
4. Detailfak
Field
Data
Field Size
Forma
name
Type
t
Nofak
Text
10
Qty
Number Long integer
Subtotal
Currency Currency
Kobar
Text
5
5. Tmpjual
Field
Data
Field Size
Forma
name
Type
t
Nofak
Text
10
Kobar
Text
5
Nabar
Text
20
Hjual
Currency Currency
Qty
Number Long integer
Subtotal
Currency Currency

VB
II

PERTEMUAN
PRA UTS

Membuat Relationship

Mengaktifkan VB
Start All Program
6.0

Microsoft Visual Studio 6.0

Microsoft Visual basic

Membuat Project
File

New project

simpan dengan nama: penjualan.pjx

Design Form Barang

VB
II

PERTEMUAN
PRA UTS

Menambahkan Komponen

Komponen yang ditambahkan:


1. Tab
2. Adodc
3. MSHFleshGrid
4. Cristal Report
Cara: Tekan CTRL + T atau klik kanan pada components sehingga
muncul kotak dialog components

VB
II

PERTEMUAN
PRA UTS

Pengkoneksian
1. Koneksi Adodc
a. Pada jendela properties pilih ConnectionString
b. Maka akan tampil jendela PropertyPages sbb.

c. Pilih use connection string


Provider Next

Build

Microsoft Jet 4.0 OLE DB

VB
II

PERTEMUAN
PRA UTS

d. Tampil jendela data link properties

e. Pada select or enter a database name klik ... (ke folder database
penjualan.mdb yang telah dibuat sebelumnya open)
f. Klik Test Connection
Ok Ok
g. Setelah itu pada jendela Properties pilih RecordSource
h. Tampil jendela Property pages

2. Koneksi MSHFlexGrid

Pada jendela Properties pilih Datasource :Adodc1

VB
II

PERTEMUAN
PRA UTS

Listing program Form barang


Dim isibrg As Boolean
Sub tabel()
Grid1.Cols = 6
Grid1.Rows = 10
Grid1.ColWidth(0) = 200
Grid1.ColWidth(1) = 500
Grid1.ColWidth(2) = 2000
Grid1.ColWidth(3) = 1500
Grid1.ColWidth(4) = 1500
Grid1.ColWidth(5) = 500
Grid1.ColAlignment(1) = 3
End Sub
Sub awal()
Adojual.RecordSource = "select * from
barang" Adojual.Refresh
tkobar.Enabled =
False
tnabar.Enabled =
False
thbeli.Enabled =
False
thjual.Enabled =
False
tstok.Enabled =
False End Sub
Sub
bersih()
tkobar =
"" tnabar
= "" thbeli
= "" thjual
= "" tstok
= "" End
Sub
Sub aktif()
tkobar.Enabled =
True
tnabar.Enabled =
True
thbeli.Enabled =
True
thjual.Enabled =

VB
PERTEMUAN
True
II
PRA UTS
tstok.Enabled =
True End Sub
Sub tampil()
tkobar.Text = Adojual.Recordset.Fields("kobar")
tnabar.Text = Adojual.Recordset.Fields("nabar")

VB
II

PERTEMUAN
PRA UTS

thbeli.Text =
Adojual.Recordset.Fields("hbeli")
thjual.Text =
Adojual.Recordset.Fields("hjual")
tstok.Text =
Adojual.Recordset.Fields("stok") End
Sub
Private Sub Form_Activate()
awal
tamp
il
isibrg = True
End Sub
Private Sub cmdadd_Click()
aktif bersih
tkobar.SetFo
cus End Sub
Private Sub cmdsave_Click()
With Adojual.Recordset
If isibrg = True Then
.AddNew
.Fields("kobar") = tkobar
.Fields("nabar") = tnabar
.Fields("hbeli") = Val(thbeli)
.Fields("hjual") = Val(thjual)
.Fields("stok") = Val(tstok)
.Update
Else
.Fields("kobar") = tkobar
.Fields("nabar") = tnabar
.Fields("hbeli") = Val(thbeli)
.Fields("hjual") = Val(thjual)
.Fields("stok") = Val(tstok)
.Update
End If
End With
Adojual.RecordSource = "select * from
barang" Adojual.Refresh
On Error
GoTo 0
cmdcancel_Cl
ick
End Sub

VB
PERTEMUAN
II
PRA UTS
Private Sub cmdcancel_Click()
awal

VB
II

PERTEMUAN
PRA UTS

End Sub
Private Sub cmddel_Click()
If Len(Trim(tkobar.Text)) = "" Then
Exit Sub
End If
p = MsgBox("Benar mau dihapus?", 32 +
4, "Tanya") If p = vbYes Then
Adojual.Recordset.Delete
Adojual.Refre
sh bersih
awal
Else
awal
End
If
End Sub
Private Sub cmdedit_Click()
isibrg =
False aktif
tkobar.Enabled =
False
tnabar.SetFocus
End Sub
Private Sub
cmdtop_Click()
Adojual.Recordset.Move
First tampil
End Sub
Private Sub
cmdlast_Click()
Adojual.Recordset.Mov
eLast tampil
End Sub
Private Sub cmdnext_Click()
Adojual.Recordset.MoveNext
If Adojual.Recordset.EOF Then
MsgBox "Data sudah diakhir record",
48, "Info" Adojual.Recordset.MoveLast
End If
tampil
End
Sub

1
0

VB
PERTEMUAN
II
PRA UTS
Private Sub cmdprev_Click()
Adojual.Recordset.MovePrevious

1
1

VB
II

PERTEMUAN
PRA UTS

If Adojual.Recordset.BOF Then
MsgBox "Data sudah di awal record",
48, "Info" Adojual.Recordset.MoveFirst
End If
tampil
End Sub
Private Sub SSTab1_DblClick()
Adojual.Refresh
End Sub
Private Sub cmdcari_Click()
Adojual.RecordSource = "select * from barang where kobar = '"
& tckobar & "'" Adojual.Refresh
With Adojual.Recordset
If .PageCount <> 0
Then
Adojual.Refresh
tckobar = ""
tckobar.SetFocus
Call tampil
Els
e
MsgBox "Kode " + tckobar + " tidak ada",
34, "Info" tckobar = ""
tckobar.SetFocus
Adojual.RecordSource = "select * from
barang" Adojual.Refresh
End If
End With
End Sub
Private Sub tcnabar_Change()
Adojual.RecordSource = "select * from barang where nabar like '%" &
tcnabar & "%'" Adojual.Refresh
End Sub
Private Sub cmdclose_Click()
t = MsgBox("Anda yakin mau menutup form ini?",
36, "Tanya") If t = vbYes Then
Unload Me
End If
End Sub

1
2

VB
II

PERTEMUAN
PRA UTS

Design Form Transaksi

Komponen yang ditambahkan:


5 buah Adodc, pada jendela properties lakukan koneksi untuk
ConnectionString
dan RecordSource :
Data barang ketikkan di command text (SQL) :select * from barang
Data pengguna ketikkan di command text (SQL)
:select * from
pengguna
Data faktur ketikkan di command text (SQL) :select * from faktur
Data detail ketikkan di command text (SQL) :select * from
detailfak
Data temporary ketikkan di command text (SQL)
:select * from
tmpjual
1 buah MSHFlexGrid, pada jendela properties
:dttmpjual

Datasource

1 buah Data Combo (Microsoft Data List Control 6.0 (OLEDB)), pada
jendela
properties
Rowsource: dtbarang , ListField: kobar

1
0

VB
II

PERTEMUAN
PRA UTS

Listing Program Form


Transaksi
Sub hapusgrid()
If dttmpjual.Recordset.RecordCount <=
0 Then
Exit Sub End If
dttmpjual.Recordset.Mov
eFirst
Do While Not
dttmpjual.Recordset.EOF
dttmpjual.Recordset.Delete
dttmpjual.Recordset.MoveNext
Loop
dttmpjual.Refr
esh End Sub
Private Sub Form_Activate()
hapusgrid
dttmpjual.RecordSource = "select * from
tmpjual" dttmpjual.Refresh
non
ttglfak.Text = Date
tuserid.Text =
Form3.tuser.Text
tnmuser.Text =
Form3.tnmuser.Text End Sub
Private Sub Timer1_Timer()
Text11.Text =
Time() End Sub
Sub no()
Dim urutan As String
Dim hitung As Long
dtfaktur.RecordSource = "select *
from faktur" dtfaktur.Refresh
If dtfaktur.Recordset.RecordCount
<= 0 Then urutan =
dtfaktur.Recordset.RecordCount + 1

Sub non()
tnofak.Enabled =
False ttglfak.Enabled
= False
tuserid.Enabled =
False
tnmuser.Enabled =
False
ckobar.Enabled =
False tnabar.Enabled
= False
thjual.Enabled =
False tstok.Enabled
= False tqty.Enabled
= False
tsubtotal.Enabled =
False ttotal.Enabled
= False
tubay.Enabled =
False tukem.Enabled
= False End Sub
Sub aktif()
ckobar.Enabled =
True tqty.Enabled
= True
tubay.Enabled =
True End Sub
Sub
bersih()
tnofak =
"" ckobar
= ""
tnabar =
"" thjual =
"" tstok =
"" tqty =
""
tsubtotal =
"" ttotal =
"" tubay =
"" tukem =
"" End Sub

tnofak.Text = "F" + Format(Date, "yymm") +


Format(urutan, "000") Else
dtfaktur.Recordset.MoveLast
urutan = Val(Right(dtfaktur.Recordset!nofak, 3)) + 1
tnofak.Text = "F" + Format(Date, "yymm") +
Format(urutan, "000") End If

1
1

VB
End Sub
II

PERTEMUAN
PRA UTS

1
2

Private Sub cmdadd_Click()


akti
f no
End Sub
Private Sub ckobar_Change()
dtbarang.RecordSource = "select * from barang where kobar='"
& ckobar & "'" dtbarang.Recordset.MoveFirst
Do While Not dtbarang.Recordset.EOF
If ckobar.Text = dtbarang.Recordset!kobar Then
With
dtbarang.Recordset
tnabar.Text = !
nabar thjual.Text =
!hjual tstok.Text = !
stok
Exit
Sub
End
With
End If
dtbarang.Recordset.Move
Next tqty.SetFocus
Loop
End Sub
Private Sub tqty_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
dttmpjual.RecordSource = "select * from
tmpjual" dttmpjual.Refresh
dtbarang.RecordSource = "select * from
barang" dtbarang.Refresh
tsubtotal = Val(thjual.Text) *
Val(tqty.Text) dttmpjual.RecordSource =
"select * from tmpjual" dttmpjual.Refresh
a = MsgBox("Mau tambah data lagi?", 32
+ 4, "lagi") If a = vbYes Then
With dttmpjual.Recordset
.AddNew
.Fields("nofak") = tnofak.Text
.Fields("kobar") = ckobar.Text
.Fields("nabar") = tnabar.Text
.Fields("hjual") = thjual.Text
.Fields("qty") = Val(tqty.Text)
.Fields("subtotal") = Val(tsubtotal.Text)
.Update
End With
dttmpjual.RecordSource = "select * from

tmpjual" dttmpjual.Refresh
dtbarang.Recordset.Fields("stok") = Val(tstok.Text) - Val(tqty.Text)

ttotal.Text = Val(ttotal.Text) + Val(tsubtotal.Text)


dtbarang.Recordset.Up
date ckobar = ""
tnabar = ""
thjual =
"" tstok
=
""
tqty =
""
tsubtotal = ""
ckobar.SetFoc
us Else
With dttmpjual.Recordset
.AddNew
.Fields("nofak") = tnofak.Text
.Fields("kobar") = ckobar.Text
.Fields("nabar") = tnabar.Text
.Fields("hjual") = thjual.Text
.Fields("qty") = Val(tqty.Text)
.Fields("subtotal") = Val(tsubtotal.Text)
.Update
End With
dttmpjual.RecordSource = "select * from
tmpjual" dttmpjual.Refresh
dtbarang.Recordset.Fields("stok") = Val(tstok.Text) Val(tqty.Text) ttotal.Text = Val(ttotal.Text) +
Val(tsubtotal.Text) dtbarang.Recordset.Update
ckobar =
"" tnabar
= ""
thjual =
"" tstok
= "" tqty
= ""
tsubtotal =
"" non
tubay.Enabled = True
tubay.SetFocus
End If
dttmpjual.RecordSource = "select * from
tmpjual" dttmpjual.Refresh
End If
End Sub
Private Sub
tubay_Change() tukem
= Val(tubay) - Val(ttotal)

End Sub

Private Sub cmdsave_Click()


dtfaktur.RecordSource = "select *
from faktur" dtfaktur.Refresh
dttmpjual.RecordSource = "select *from tmpjual"
dttmpjual.Refresh
dtdetail.RecordSource = "select * from
detailfak" dtdetail.Refresh
With dtfaktur.Recordset
.AddNew
.Fields("nofak") = tnofak.Text
.Fields("tglfak") = ttglfak.Text
.Fields("userid") = tuserid.Text
.Fields("total") = ttotal.Text
.Update End With
dttmpjual.Recordset.Mov
eFirst n = 1
While Not dttmpjual.Recordset.EOF
dtdetail.Recordset.AddNew
dtdetail.Recordset.Fields("nofak") =
dttmpjual.Recordset.Fields("nofak")
dtdetail.Recordset.Fields("kobar") =
dttmpjual.Recordset.Fields("kobar")
dtdetail.Recordset.Fields("qty") =
dttmpjual.Recordset.Fields("qty")
dtdetail.Recordset.Fields("subtotal") =
dttmpjual.Recordset.Fields("subtotal")
dtdetail.Recordset.Update
dttmpjual.Recordset.Move
Next n = n + 1
Wend
bersih
hapusgr
id
dttmpjual.RecordSource = "select *from
tmpjual" dttmpjual.Refresh
non
End Sub
Private Sub cmdcancel_Click()
If tstok <> "" Then
dtbarang.Recordset.Fields("stok") = dtbarang.Recordset.Fields("stok") +
Val(tstok.Text)
dtbarang.Recordset.Update
End
If
bersi
h

non
hapusgrid
dttmpjual.RecordSource = "select * from
tmpjual" dttmpjual.Refresh
End Sub

Private Sub cmdclose_Click()


If tstok <> "" Then
dtbarang.Recordset.Fields("stok") = dtbarang.Recordset.Fields("stok") +
Val(tstok.Text)
dtbarang.Recordset.Update
End If
dttmpjual.RecordSource = "select * from
tmpjual" dttmpjual.Refresh
Unload Me
End Sub

Design Form Login

Listing Program Form Login


Private Sub cmdlogin_Click()
Adologin.RecordSource = "select password from
pengguna" Adologin.Refresh
With Adologin.Recordset
.Find ("password = '" &
Trim(tpwd) & "'") If .EOF Then
MsgBox " Password anda salah", vbCritical +
vbYesNo, "Info" tpwd = ""
tpwd.SetFocus
Else
Form2.Sho
w
Form3.Hid
e End If
End With
End Sub

Private Sub tuser_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Adologin.RecordSource = "select userid,nmuser from
pengguna" Adologin.Refresh
Adologin.Recordset.Find ("userid = '" &
Trim(tuser) & "'") If Adologin.Recordset.EOF
Then
MsgBox " User ID anda salah", vbCritical +
vbYesNo, "Info" tuser = ""
tuser.SetFocus
Else
tnmuser.Text = Adologin.Recordset.Fields("nmuser")
tnmuser.Enabled =
False tpwd.SetFocus
End If
End If
End
Sub
Private Sub cmdclose_Click()
t = MsgBox("Anda yakin mau menutup form ini?",
36, "Tanya") If t = vbYes Then
Unload Me
End If
End Sub

MEMBUAT LAPORAN DENGAN CRYSTAL REPORT


Start All Program Crystal Report Tools
Maka akan tampil Jendela :

Pilih Choose an Expert :Standart

Crystal Report

OK

Tampil Jendela Standart report Expert, klik Database muncul


jendela Data explorer, klik Find Database File ADD

Lalu ke C:\LAB O
MALAM\NIM\penjualan.mdb. Hasil:

D
Lalu Klik ADD. Hasil:

lalu Klik Close.

Hasil:

Klik Next>>
Klik
ADD ALL. Hasil:

Lalu Klik Finish


Klik
tab Design. Hasil:

Tambahkan Judul Laporan dan Percantik design laporan barang


Save dengan nama :reportbarang
Hasil:

Start all Program Microsoft Visual Studia 6.0 Microsoft


Visual basic 6.0. File Open Project Buka Project
penjualan.vbp
Tekan CTRL+T sehingga muncul kotak dialog Component seperti
dibawah ini:

2
0

2
1

Di Properties Form barang, lakukan beberapa settingan sbb.

C:\LABO
MALAM\NIM\reportb
arang Lalu Klik OK

Listing Untuk Command cetak

2
2

MEMBUAT MENU UTAMA


1. Aktifkan Microsoft Visual Basic 6.0
2. Buka Project penjualan.vbp
3. Buka Form baru untuk menu utama

4. Pada menu bar pilih:

5.

Akan tampil jendela sbb:

6.

Design Menu Utama sbb:

2
3

7.

Hasil sbb:

8.

Listing Program:

9.

Design lah Form Menu Utama sehingga terlihat lebih cantik.

2
4

Anda mungkin juga menyukai