Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

PERTEMUAN III

FORM MODEL AUTO NUMBER


Langkah-langkah membuat Form Model Auto Number.
1. Buka project PROGRAM DASAR
2. Buat form baru dengan cara klik menu Project kemudian pilik Add Form
3. Tambahkan beberapa objek kemudian setting seperti instruksi berikut:
Objek
Form 1

Frame 1

Frame2

Label1

Label2

Label3

Label4

Item
(Name)
Caption
Height
Width
Caption
Height
Left
Top
Widht
Caption
Height
Left
Top
Widht
BorderStyle
Height
Left
Top
Widht
BorderStyle
Height
Left
Top
Widht
BorderStyle
Height
Left
Top
Widht
BorderStyle
Height
Left
Top
Widht

Properties
Model2AutoNumber
Model Auto Kode
5835
6120
(Kosongkan)
1815
120
600
5655
(Kosongkan)
735
120
2400
5655
1 Fixed Singel
345
129
240
1005
1 Fixed Singel
345
129
600
1005
1 Fixed Singel
345
129
960
1005
1 Fixed Singel
345
129
1320
1005

Label5

Label6

Text1

Text2

Text3

Text4

Text5

Command1

BorderStyle
Height
Left
Top
Widht
Alignment
BorderStyle
FrontSize
Height
Left
Top
Widht
(Name)
Height
Left
Text
Top
Width
(Name)
Height
Left
Text
Top
Width
(Name)
Height
Left
Text
Top
Width
(Name)
Height
Left
Text
Top
Width
(Name)
Height
Left
Text
Top
Width
(Name)
Caption
Height

1 Fixed Singel
345
3120
960
1005
2 - Center
0 None
14
495
0
0
5895
Text1
350
1200
(Kosongkan)
240
1250
Text1
350
1200
(Kosongkan)
600
4260
Text3
350
1200
(Kosongkan)
960
1250
Text4
350
4200
(Kosongkan)
960
1250
Text5
350
1200
(Kosongkan)
1320
1250
CmdInput
&Input
375

Command2
Command3
Command4
Data Grid

Left
Top
Width
(Name)
Caption
Left
(Name)
Caption
Left
(Name)
Caption
Left
Height
Left
Top
Widht

120
240
1000
CmdEdit
&Edit
1200
CmdHapus
&Hapus
2280
CmdTutup
&Tutup
3360
1845
120
3240
5655

4. Buka Kode Editor form (klik 2x pada form) dan isi dengan kode berikut:
Dim mvBookMark As Variant
Private Sub form_activate()
Call BukaDB
Conn.CursorLocation = adUseClient
RSBarang.Open select * from barang, Conn
With RSBarang
If Not (.BOF And .EOF) Then
mvBookMark =.Bookmark
End If
End With
Set DataGrid 1.DataSource = RSBarang.DataSource
End Sub

Sub Form_Load()
batasi jumlah karakter
Text1.MaxLength = 6
Text2.MaxLength = 30
Text3.MaxLength = 8
Text4.MaxLength = 8
Text5.MaxLength = 4
Kondisiawal
End Sub

5. Buka kode editor Command Input (klik 2x pada Input) dan isi dengan kode berikut:
Private Sub CmdInput_click()
If Cmdinput.Caption = &Input Then
Cmdinput.Caption = &Simpan
Cmdedit.Enabled = False
Cmdhapus.Enabled =False
Cmdtutup.Caption = &Batal
SiapIsi
KosongkanText
Call AutoNomor
Text1.Enabled = False
Text2.SetFocus
Else
If Text1 = Or Text2 = Or Text3 = Or Text4 = Or Text5 = Then
MsgBox Data Belum Lengkap!
Else
Dim SQLTambah As String
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
6. Buka kode editor Command Edit (klik 2x pada Edit) dan isi dengan kode berikut:

Private Sub CmdEdit_Click()


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
Dim SQLEdit As String
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
7. Buka kode editor Command Hapus (klik 2x pada Hapus) dan isi dengan kode berikut:
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

8.

Private Sub CmdTutup_Click()


Select Case CmdTutup.Caption
Case &Tutup
Unload Me
Case &Batal
TidakSiapIsi
Kondisiawal
End Select
EndSub

9.

Function CariData()
Call BukaDB
RSBarang.Open Select * From Barang Where KodeBrg= & Text1 7 , Conn
End Function
Private Sub Text1_Keypress(Keyascii As Integer)
Keyascii = Asc(UCase(Chr(Keyascii)))
If Keyascii = 13 Then
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
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_activite
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)
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
If Not (Keyascii >= Asc(0) And Keyascii <= Asc (9) Or Keyascii =
vbKeyBack) Then Keyascii = 0
End Sub

Private Sub Text4_Keypress(Keyascii As Integer)


If Keyascii = 13 Then
If Val (Text4) <= Val (Text3) Then
Msg Box harga jual jangan lebih kecil dari 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
Elself 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
Private Sub AutoNomor()
Call BukaDB
RSBarang.Open (Select * from Barang Where KodeBRG In (Select
Max(KodeBrg)From Barang)Order By Kode Brg Desc), Conn
RSBarang.Requery
Dim Urutan As String * 6
Dim Hitung As Ling
With RSBarang
If.EOF Then
Urutan = BRG + 001
Text1 = Ururtan
Else
Hitung = Right(!kodebrg, 3) + 1
Urutan = BRG + Right (000 & Hitung,3)
End If
Text1 = Urutan
End With
End Sub

Private Sub TampilkanData()


With RSBarang
If Not RSBarang.EOF Then
Text2 = RSBarang!namabrg
Text3 = RSBarang!HargaBeli
Text4 = RSBarang!HargaJual
Text5 = RSBarang!Jumlahbrg
End If
End With
End Sub
Private Sub Kondisiawal()
Kosongkan Text
TidakSiapIsi
Cmdinput.Caption = & Input
Cmdedit.Caption = &Edit
Cmdhapus.Caption = &Hapus
Cmdtutup.Caption = &Tutup
Cmdinput.Enabled = True
Cmdedit.Enabled = True
Cmdhapus.Enabled = True
End Sub
Private Sub KosongkanText()
Text1 =
Text2 =
Text3 =
Text4 =
Text5 =
End Sub
Private Sub SiapIsi()
Text1.Enabled =True
Text2.Enabled =True
Text3.Enabled =True
Text4.Enabled =True
Text5.Enabled =True
End Sub

Private Sub SiapIsi()


Text1.Enabled =False
Text2.Enabled =False
Text3.Enabled =False
Text4.Enabled =False
Text5.Enabled =False
End Sub

10. Simpan Form dengan nama MODEL2AUTONUMBER

You might also like