Silahkan buat form user dengan name=formuser, dan silahkan ubah name yg lainnya mejad seperti dibawah ini ;
Catatan ;
A. Buat Grid/tabel seperti diatas
B. Masukkan crystal report dan beri name=cr
1. Buat Sub baru dengan nama Sub aktif dan pastekan koding berikut :
tkodeuser.Enabled = True
tnamauser.Enabled = True
tpassuser.Enabled = True
tlevel.Enabled = True
ctambah.Enabled = True
csimpan.Enabled = True
csunting.Enabled = True
cperbarui.Enabled = True
cbatal.Enabled = True
chapus.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
tnamauser.Enabled = True
tpassuser.Enabled = True
tlevel.Enabled = True
ctambah.Enabled = True
csimpan.Enabled = True
csunting.Enabled = True
cperbarui.Enabled = True
cbatal.Enabled = True
chapus.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
2. Buat Sub baru dengan nama Sub nonaktif dan pastekan koding berikut :
tkodeuser.Enabled = False
tnamauser.Enabled = False
tpassuser.Enabled = False
tlevel.Enabled = False
ctambah.Enabled = False
csimpan.Enabled = False
csunting.Enabled = False
cperbarui.Enabled = False
cbatal.Enabled = False
chapus.Enabled = False
ccari.Enabled = False
tcari.Enabled = False
ccetak.Enabled = False
tnamauser.Enabled = False
tpassuser.Enabled = False
tlevel.Enabled = False
ctambah.Enabled = False
csimpan.Enabled = False
csunting.Enabled = False
cperbarui.Enabled = False
cbatal.Enabled = False
chapus.Enabled = False
ccari.Enabled = False
tcari.Enabled = False
ccetak.Enabled = False
3. Buat Sub baru dengan nama Sub tampil dan pastekan koding berikut :
Call koneksi
rsdatauser.Open "select*from tabeluser", KON
Set grid1.DataSource = rsdatauser
rsdatauser.Open "select*from tabeluser", KON
Set grid1.DataSource = rsdatauser
4. Buat Sub baru dengan nama Sub besih dan pastekan koding berikut :
tkodeuser.Text = Clear
tnamauser.Text = Clear
tpassuser.Text = Clear
tlevel.Text = Clear
tcari.Text = Clear
tnamauser.Text = Clear
tpassuser.Text = Clear
tlevel.Text = Clear
tcari.Text = Clear
5. Buat Sub baru dengan nama Sub simpan dan pastekan koding berikut :
Call koneksi
rsdatauser.Open "insert into tabeluser values('" & tkodeuser & "','" & tnamauser & "','" & tpassuser & "','" & tlevel & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call bersih
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
rsdatauser.Open "insert into tabeluser values('" & tkodeuser & "','" & tnamauser & "','" & tpassuser & "','" & tlevel & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call bersih
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
6. Buat Sub baru dengan nama Sub perbarui dan pastekan koding berikut :
Call koneksi
rsdatauser.Open "update tabeluser set namauser='" & tnamauser & "',password='" & tpassuser & "',level='" & tlevel & "' where kodeuser='" & tkodeuser.Text & "'", KON
MsgBox "Data Berhasil di Update", vbInformation, "Info"
bersih
Call tampil
Call nonaktif
ctambah.Enabled = True
rsdatauser.Open "update tabeluser set namauser='" & tnamauser & "',password='" & tpassuser & "',level='" & tlevel & "' where kodeuser='" & tkodeuser.Text & "'", KON
MsgBox "Data Berhasil di Update", vbInformation, "Info"
bersih
Call tampil
Call nonaktif
ctambah.Enabled = True
7. Form_load pastekan koding berikut :
Private Sub Form_Load()
Me.Top = 100
Me.Left = 0
Me.Height = 6945
Me.Width = 10995
Call tampil
Call bersih
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
End Sub
Me.Top = 100
Me.Left = 0
Me.Height = 6945
Me.Width = 10995
Call tampil
Call bersih
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
End Sub
8. Double klik pada ctambah dan pastekan koding berikut :
Call koneksi
Call bersih
Call aktif
rsdatauser.Open "select*from tabeluser order by kodeuser desc", KON
With rsdatauser
If .BOF And .EOF Then
tkodeuser.Text = "USR" + "01"
Else
tkodeuser.Text = "USR" + Right(Str(Val(Right(.Fields("kodeuser"), 2)) + 101), 2)
End If
End With
tkodeuser.Enabled = False
tnamauser.SetFocus
cbatal.Enabled = True
csunting.Enabled = False
cperbarui.Enabled = False
chapus.Enabled = False
Call tampil
tpassuser.Enabled = True
tlevel.Enabled = True
ctambah.Enabled = False
Call bersih
Call aktif
rsdatauser.Open "select*from tabeluser order by kodeuser desc", KON
With rsdatauser
If .BOF And .EOF Then
tkodeuser.Text = "USR" + "01"
Else
tkodeuser.Text = "USR" + Right(Str(Val(Right(.Fields("kodeuser"), 2)) + 101), 2)
End If
End With
tkodeuser.Enabled = False
tnamauser.SetFocus
cbatal.Enabled = True
csunting.Enabled = False
cperbarui.Enabled = False
chapus.Enabled = False
Call tampil
tpassuser.Enabled = True
tlevel.Enabled = True
ctambah.Enabled = False
9. Double klik pada csimpan dan pastekan koding berikut :
If tkodeuser.Text = "" Or tnamauser.Text = "" Or tlevel.Text = "" Or tpassuser.Text = "" Then
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tnamauser.Text) < 3 Then
MsgBox "Nama user harus lebih dari 2 karakter", vbCritical
tnamauser.SetFocus
ElseIf Len(tpassuser.Text) < 3 Then
MsgBox "Password harus lebih dari 2 karakter", vbCritical
tpassuser.SetFocus
Else
Call simpan
End If
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tnamauser.Text) < 3 Then
MsgBox "Nama user harus lebih dari 2 karakter", vbCritical
tnamauser.SetFocus
ElseIf Len(tpassuser.Text) < 3 Then
MsgBox "Password harus lebih dari 2 karakter", vbCritical
tpassuser.SetFocus
Else
Call simpan
End If
10. Double klik pada csunting dan pastekan koding berikut :
Call koneksi
rsdatauser.Open "select*from tabeluser where kodeuser ='" & tcari.Text & "'", KON
With rsdatauser
tkodeuser.Text = .Fields("kodeuser")
tnamauser.Text = .Fields("namauser")
tpassuser.Text = .Fields("password")
tlevel.Text = .Fields("level")
End With
Call aktif
tlevel.Enabled = False
tkodeuser.Enabled = False
ctambah.Enabled = False
csimpan.Enabled = False
chapus.Enabled = False
csunting.Enabled = False
rsdatauser.Open "select*from tabeluser where kodeuser ='" & tcari.Text & "'", KON
With rsdatauser
tkodeuser.Text = .Fields("kodeuser")
tnamauser.Text = .Fields("namauser")
tpassuser.Text = .Fields("password")
tlevel.Text = .Fields("level")
End With
Call aktif
tlevel.Enabled = False
tkodeuser.Enabled = False
ctambah.Enabled = False
csimpan.Enabled = False
chapus.Enabled = False
csunting.Enabled = False
11. Double klik pada cperbarui dan pastekan koding berikut :
If tkodeuser.Text = "" Or tnamauser.Text = "" Or tlevel.Text = "" Or tpassuser.Text = "" Then
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tnamauser.Text) < 3 Then
MsgBox "Nama user harus lebih dari 2 karakter", vbCritical
tnamauser.SetFocus
ElseIf Len(tpassuser.Text) < 3 Then
MsgBox "Password harus lebih dari 2 karakter", vbCritical
tpassuser.SetFocus
Else
Call perbarui
End If
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tnamauser.Text) < 3 Then
MsgBox "Nama user harus lebih dari 2 karakter", vbCritical
tnamauser.SetFocus
ElseIf Len(tpassuser.Text) < 3 Then
MsgBox "Password harus lebih dari 2 karakter", vbCritical
tpassuser.SetFocus
Else
Call perbarui
End If
12. Double klik pada chapus dan pastekan koding berikut :
Call koneksi
a = MsgBox("Yakin Ingin Hapus Data ini?", vbQuestion + vbYesNo, "tanya")
If a = vbYes Then
rsdatauser.Open "delete from tabeluser where kodeuser='" & tcari.Text & "'", KON
MsgBox "Data telah terhapus", vbInformation
bersih
tcari.Text = ""
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
End If
Call tampil
a = MsgBox("Yakin Ingin Hapus Data ini?", vbQuestion + vbYesNo, "tanya")
If a = vbYes Then
rsdatauser.Open "delete from tabeluser where kodeuser='" & tcari.Text & "'", KON
MsgBox "Data telah terhapus", vbInformation
bersih
tcari.Text = ""
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
End If
Call tampil
13. Double klik pada cbatal dan pastekan koding berikut :
Call bersih
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
Call nonaktif
ctambah.Enabled = True
ccari.Enabled = True
tcari.Enabled = True
ccetak.Enabled = True
14. Double klik pada ccari dan pastekan koding berikut :
Call koneksi
rsdatauser.Open "select*from tabeluser where kodeuser='" & tcari.Text & "'", KON
If rsdatauser.EOF Then
MsgBox "Data Tidak Ditemukan", vbCritical
Call bersih
tcari.SetFocus
Else
With rsdatauser
tkodeuser.Text = .Fields("kodeuser")
tnamauser.Text = .Fields("namauser")
tpassuser.Text = .Fields("password")
tlevel.Text = .Fields("level")
End With
Call nonaktif
tkodeuser.Enabled = False
csunting.Enabled = True
chapus.Enabled = True
cbatal.Enabled = True
If tkodeuser.Text = "USR01" Then
chapus.Enabled = False
tlevel.Enabled = False
End If
End If
rsdatauser.Open "select*from tabeluser where kodeuser='" & tcari.Text & "'", KON
If rsdatauser.EOF Then
MsgBox "Data Tidak Ditemukan", vbCritical
Call bersih
tcari.SetFocus
Else
With rsdatauser
tkodeuser.Text = .Fields("kodeuser")
tnamauser.Text = .Fields("namauser")
tpassuser.Text = .Fields("password")
tlevel.Text = .Fields("level")
End With
Call nonaktif
tkodeuser.Enabled = False
csunting.Enabled = True
chapus.Enabled = True
cbatal.Enabled = True
If tkodeuser.Text = "USR01" Then
chapus.Enabled = False
tlevel.Enabled = False
End If
End If
15. Double klik pada ccetak dan pastekan koding berikut (sesuaikan link penyimpanannya) :
cr.ReportFileName = "D:\Belajar MVB\user.rpt"
cr.WindowState = crptMaximized
cr.RetrieveDataFiles
cr.Action = 1
cr.WindowState = crptMaximized
cr.RetrieveDataFiles
cr.Action = 1
0 Komentar