Kita buat formnya seperti berikut :
Selanjutnya kita ubah "name"nya seperti di bawah ini :
- Pertama kita buat Sub Aktif ( fungsi ketika kita pilih add maka semuanya aktif)
Sub aktif()
tkodeuser.Enabled = Truetnamauser.Enabled = True
cjabatan.Enabled = True
tpassword.Enabled = True
End Sub
- Buat Sub nonaktif ( fungsi ketika form dijalankan semuanya dalam kondisi nonaktif, kecuali add)
Sub nonaktif()
tkodeuser.Enabled = Falsetnamauser.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 nonaktifEnd Sub
- buat sub tampil :
Sub tampil()
Call koneksirsuser.Open "select*from tbuser", KON
Set grid.DataSource = rsuser
End Sub
Silahkan copy kode listing berikut dan pastekan sesuai name nya :
- cmdadd:
Private Sub cmdadd_Click()
Call bersihCall aktif
tkodeuser.SetFocus
cmdsave.Enabled = True
cmdcancel.Enabled = True
cmdedit.Enabled = False
cmdupdate.Enabled = False
End Sub
- cmdsave
Private Sub cmdsave_Click()
Call koneksirsuser.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()
bersihtkodeuser.SetFocus
End Sub
- cmdedit :
Private Sub cmdedit_Click()
Call koneksirsuser.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 koneksirsuser.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 koneksia = 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.ShowEnd 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 koneksirsuser.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
2 Komentar
pagi mas cara bikin sub aktif nya gimana ya makasih
BalasHapuspagi mas cara bikin sub aktifnya dong mas..hehe
BalasHapusmakasih