Thursday, December 20, 2018

√ Menciptakan Form Jadwal Tes Tulis Aktivitas Penerimaan Karyawan Di Ms Visual Basic Dengan Database Mysql Phpmyadmin


Setelah kita melihat contoh Program Visual Basic (VB) Penerimaan karyawan gres (Employee Recruitment). Maka Selanjutnya kita Membuat Form Jadwal tes tulis aktivitas penerimaan karyawan di Ms Visual basic dengan database Mysql Phpmyadmin.



ubah namenya menyerupai dibawah ini :





- Buat sub aktif :
Sub aktif()
tnopelamar.Enabled = True
tuser.Enabled = True
tnama.Enabled = True
ctgl1.Enabled = True
ttempat1.Enabled = True
ctgl2.Enabled = True
ttempat2.Enabled = True
tcari.Enabled = True
cmdsave.Enabled = True
cmdcancel.Enabled = True
cmdedit.Enabled = True
cmdupdate.Enabled = True
cmddelete.Enabled = True
End Sub

- Buat sub nonaktif :
Sub nonaktif()
tnopelamar.Enabled = False
tnama.Enabled = False
tuser.Enabled = False
ctgl1.Enabled = False
ttempat1.Enabled = False
ctgl2.Enabled = False
ttempat2.Enabled = False
tcari.Enabled = False
cmdsave.Enabled = False
cmdcancel.Enabled = False
cmdedit.Enabled = False
cmdupdate.Enabled = False
cmddelete.Enabled = False
End Sub

- Buat sub tampil :
Sub tampil()
Call koneksi
rsjadwaltest.Open "select*from jadwaltest", KON
Set grid.DataSource = rsjadwaltest

End Sub

- buat sub bersih:
Sub bersih()
tnopelamar.Text = ""
tnama.Text = ""
ctgl1.Text = ""
ctgl2.Text = ""
ttempat1.Text = ""
ttempat2.Text = ""
End Sub

- buat form-load :

Private Sub Form_Load()
Call nonaktif
Call koneksi
Call tampil



ctgl1.Clear
ctgl2.Clear
rstanggaltest.Open "select*from tanggaltest", KON
rstanggaltest.MoveFirst
Do Until rstanggaltest.EOF
ctgl1.AddItem (rstanggaltest.Fields("tanggaltest1"))
ctgl2.AddItem (rstanggaltest.Fields("tanggaltest2"))
rstanggaltest.MoveNext
Loop

tuser.Clear

rsuser.Open "select*from tbuser", KON
rsuser.MoveFirst
Do Until rsuser.EOF
tuser.AddItem (rsuser.Fields("kodeuser"))

rsuser.MoveNext
Loop


End Sub


- Silahkan copy dan pastekan di commandbutton yg sesuai dengan namenya dibawah ini :

- cmdadd :
Private Sub cmdadd_Click()
Call aktif
Call bersih
tuser.SetFocus
cmddelete.Enabled = False
cmdedit.Enabled = False
cmdupdate.Enabled = False
End Sub

- cmdsave :
Private Sub cmdsave_Click()
Call koneksi
rsjadwaltest.Open "insert into jadwaltest values('" & tnopelamar & "','" & tnama & "','" & ctgl1 & "','" & ttempat1 & "','" & ctgl2 & "','" & ttempat2 & "','" & tuser & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call nonaktif

End Sub

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

- cmdupdate :
Private Sub cmdupdate_Click()
Call koneksi
rsjadwaltest.Open "update jadwaltest set tanggaltest1='" & ctgl1 & "',tempattest1='" & ttempat1 & "',tanggaltest2='" & ctgl2 & "',tempattest2='" & ttempat2 & "' where no_pelamar='" & tnopelamar.Text & "'", KON

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

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

- cmdedit :
Private Sub cmdedit_Click()
Call koneksi
rsjadwaltest.Open "select*from jadwaltest where no_pelamar='" & tcari.Text & "'", KON
With rsjadwaltest
tnopelamar.Text = .Fields("no_pelamar")
tnama.Text = .Fields("nama")

End With
tnopelamar.Enabled = False
tnama.Enabled = False
cmdupdate.Enabled = True
cmddelete.Enabled = True
cmdcancel.Enabled = False
End Sub

-klik 2x pada textfield "tnopelamar" dan ubah declarationnya menjadi "keypress". dan pastekan coding dibawah ini :
Private Sub tnopelamar_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call koneksi
rsdatapelamar.Open "select*from datapelamar where no_pelamar='" & tnopelamar.Text & "'", KON
If rsdatapelamar.EOF Then
MsgBox "KOde tidak ditemukan, silahkan masukan arahan lainnya !", vbCritical
Else
tnama.Text = rsdatapelamar.Fields("nama")


End If
End If
Call tampil
tnama.Enabled = False

End Sub

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

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

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

Sumber http://www.hendrisetiawan.com