Monday, December 31, 2018

√ Menciptakan Master Data User Di Ms Visual Basic Dengan Database Phpmyadmin

Setelah kita menciptakan Menu di Ms Visual Basic, Sekarang kita isi Menu hidangan tersebut dengan form form. Dalam bahasan kali ini aku akan mengisi form "Master Data User".
Kita buat formnya menyerupai berikut :


Selanjutnya kita ubah "name"nya menyerupai di bawah ini :

- Pertama kita buat Sub Aktif ( fungsi saat kita pilih add maka semuanya aktif)
Sub aktif()
tkodeuser.Enabled = True
tnamauser.Enabled = True
cjabatan.Enabled = True
tpassword.Enabled = True
End Sub

- Buat Sub nonaktif ( fungsi saat form dijalankan semuanya dalam kondisi nonaktif, kecuali add)
Sub nonaktif()
tkodeuser.Enabled = False
tnamauser.Enabled = False
cjabatan.Enabled = False
tpassword.Enabled = False
cmdsave.Enabled = False
cmdedit.Enabled = False
cmdupdate.Enabled = False
cmdcancel.Enabled = False
cmddelete.Enabled = False
End Sub

- Buat sub bersih
Sub bersih()
tkodeuser.Text = ""
tnamauser.Text = ""
cjabatan.Text = ""
tpassword.Text = ""
End Sub

- Buat form-load
Private Sub Form_Load()
Call nonaktif
End Sub

- buat sub tampil :
Sub tampil()
 Call koneksi
 rsuser.Open "select*from tbuser", KON
 Set grid.DataSource = rsuser
End Sub


Silahkan copy arahan listing berikut dan pastekan sesuai name nya :

- cmdadd:
Private Sub cmdadd_Click()
Call bersih
Call aktif
tkodeuser.SetFocus
cmdsave.Enabled = True
cmdcancel.Enabled = True
cmdedit.Enabled = False
cmdupdate.Enabled = False
End Sub

- cmdsave
Private Sub cmdsave_Click()
Call koneksi
rsuser.Open "insert into tbuser values('" & tkodeuser & "','" & tnamauser & "','" & cjabatan & "','" & tpassword & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call nonaktif
End Sub

-cmdcancel :
Private Sub cmdcancel_Click()
bersih
tkodeuser.SetFocus
End Sub

- cmdedit :
Private Sub cmdedit_Click()
Call koneksi
rsuser.Open "select*from tbuser where kodeuser='" & tcari.Text & "'", KON
With rsuser
 tkodeuser.Text = .Fields("kodeuser")
 tnamauser.Text = .Fields("namauser")
 cjabatan.Text = .Fields("jabatan")
 tpassword.Text = .Fields("password")
 End With
 Call aktif
 tkodeuser.Enabled = False
 tnamauser.SetFocus
 cmdupdate.Enabled = True
End Sub

- cmdupdate :
Private Sub cmdupdate_Click()
Call koneksi
rsuser.Open "update tbuser set namauser='" & tnamauser & "',jabatan='" & cjabatan & "',password='" & tpassword & "' where kodeuser='" & tkodeuser.Text & "'", KON

MsgBox "Data Berhasil di Update", vbInformation, "Info"
bersih
Call tampil
End Sub

- cmddelete :
Private Sub cmddelete_Click()
Call koneksi
a = MsgBox("Yakin Ingin Hapus Data ini?", vbQuestion + vbYesNo, "tanya")
If a = vbYes Then
rsuser.Open "delete from tbuser where kodeuser='" & tcari.Text & "'", KON
bersih
tcari.Text = ""
End If
End Sub

- bmenu :
Private Sub Command1_Click()
fmenu.Show
End Sub

- exit :
Private Sub EXIT_Click()
a = MsgBox("Yakin Keluar", vbCritical + vbYesNo, "INFO")
If a = vbYes Then
End
End If
End Sub

- tcari (ubah declarationsnya ke change):
Private Sub tcari_Change()
Call koneksi
rsuser.Open "select*from tbuser where kodeuser like '" & tcari.Text & "'", KON
If Not tcari.Text = "" Then
Set grid.DataSource = rsuser
Else
Call tampil
End If
Call nonaktif
tcari.Enabled = True
cmdedit.Enabled = True
cmddelete.Enabled = True
End Sub

Sumber http://www.hendrisetiawan.com