Sunday, December 30, 2018

√ Menciptakan Master Data Pelamar Di Microsoft Visual Basic (Vb) Dengan Database Phpmyadmin

Setelah kita melihat contoh Program Visual Basic (VB) Penerimaan karyawan gres (Employee Recruitment). Maka Selanjutnya kita membuat  Master Data Pelamar Pada Microsoft Visual Basic (VB) dengan Database Phpmyadmin.Buat menyerupai form di bawah ini :




Dan selanjutnya beri name seperti di bawah ini :




- Pertama kita buat sub aktif :

Sub aktif()
tnopelamar.Enabled = False
tnama.Enabled = True
talamat.Enabled = True
tnohp.Enabled = True
tcari.Enabled = True
cmdsave.Enabled = True
End Sub

- Buat Sub Nonaktif :
Sub nonaktif()
tnopelamar.Enabled = False
tnama.Enabled = False
talamat.Enabled = False
tnohp.Enabled = False
tcari.Enabled = False
cmdsave.Enabled = False
cmdedit.Enabled = False
cmdupdate.Enabled = False
cmdcancel.Enabled = False
cmddelete.Enabled = False
End Sub

- Buat Sub Tampil :
Sub tampil()
Call koneksi
rsdatapelamar.Open "select*from datapelamar", KON
Set grid.DataSource = rsdatapelamar
End Sub

- Buat Form Load :
Private Sub Form_Load()
Call nonaktif
End Sub

- Buat Sub Bersih :

Sub bersih()
tnopelamar.Text = ""
tnama.Text = ""
talamat.Text = ""
tnohp.Text = ""
End Sub

Silahkan copy dan pastekan sesuai dengan namenya arahan listing dibawah ini :

- cmdadd :
Private Sub cmdadd_Click()
Call koneksi
Call bersih
Call aktif
rsdatapelamar.Open "select*from datapelamar order by no_pelamar desc", KON
With rsdatapelamar
If .BOF And .EOF Then
tnopelamar.Text = "DP" + "001"
Else
tnopelamar.Text = "DP" + Right(Str(Val(Right(.Fields("no_pelamar"), 3)) + 1001), 3)
End If
End With
tnama.SetFocus
cmdcancel.Enabled = True
End Sub

- cmdcancel :
Private Sub cmdcancel_Click()
Call bersih
Call nonaktif
cmdadd.Enabled = tru
End Sub

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

- cmdedit :
Private Sub cmdedit_Click()
Call koneksi
rsdatapelamar.Open "select*from datapelamar where no_pelamar='" & tcari.Text & "'", KON
With rsdatapelamar
tnopelamar.Text = .Fields("no_pelamar")
tnama.Text = .Fields("nama")
talamat.Text = .Fields("alamat")
tnohp.Text = .Fields("no_hp")
End With
tnopelamar.Enabled = False
tnama.SetFocus
cmdupdate.Enabled = True
End Sub

- cmdsave :
Private Sub cmdsave_Click()
Call koneksi
rsdatapelamar.Open "insert into datapelamar values('" & tnopelamar & "','" & tnama & "','" & talamat & "','" & tnohp & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call bersih
Call nonaktif
End Sub

- cmdupdate :
Private Sub cmdupdate_Click()
Call koneksi
rsdatapelamar.Open "update datapelamar set nama='" & tnama & "',alamat='" & talamat & "',no_hp='" & tnohp & "' where no_pelamar='" & tnopelamar.Text & "'", KON

MsgBox "Data Berhasil di Update", vbInformation, "Info"
bersih
Call tampil
cmdadd.Enabled = True
cmdsave.Enabled = False
cmdupdate.Enabled = False
cmdedit.Enabled = False
cmddelete.Enabled = False
End Sub

- tcari (ubah declarationsnya ke "change"):
Private Sub tcari_Change()
Call koneksi
rsdatapelamar.Open "select*from datapelamar where no_pelamar like '" & tcari.Text & "'", KON
If Not tcari.Text = "" Then
Set grid.DataSource = rsdatapelamar
Else
Call tampil
End If
cmdadd.Enabled = False
cmdsave.Enabled = False
cmdupdate.Enabled = False
cmdedit.Enabled = True
cmddelete.Enabled = True
End Sub

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

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

Sumber http://www.hendrisetiawan.com