Dim sql As String
Sub hapus()
NPM.Text = ""
NAMA.Text = ""
CMDPROSES(1).Caption = "&SIMPAN"
aktifcmd True, False, False, False, True
End Sub
Private Sub CMDREPREST_Click()
Adodc1.Refresh
End Sub
Private Sub DataGrid1_Click()
NPM.Text = DataGrid1.Columns(0)
NPM_keypress 13
End Sub
Private Sub Form_Load()
opendb
hapus
End Sub
Sub aktifcmd(l0 As Boolean, l1 As Boolean, l2 As Boolean, l3 As Boolean, l4 As Boolean)
CMDPROSES(0).Enabled = l0
CMDPROSES(1).Enabled = l1
CMDPROSES(2).Enabled = l2
CMDPROSES(3).Enabled = l3
CMDPROSES(4).Enabled = l4
End Sub
Sub hapusdb()
sql = "delete from MAHASISWA where NPM='" & NPM.Text & "'"
db.BeginTrans
db.Execute sql, adCmdTable
db.CommitTrans
End Sub
Private Sub cmdproses_click(index As Integer)
Select Case index
Case 0
hapus
NPM.SetFocus
Case 1
If CMDPROSES(1).Caption = "&SIMPAN" Then
simpandb True
Else
simpandb False
End If
hapus
NPM.SetFocus
Adodc1.Refresh
Case 2
hapusdb
hapus
NPM.SetFocus
Adodc1.Refresh
Case 3
hapus
NPM.SetFocus
Case 4
Unload Me
End Select
End Sub
Private Sub NPM_keypress(keyascii As Integer)
If keyascii = 13 Then
sql = "select*from MAHASISWA where NPM='" & NPM.Text & "'"
If rs.State = adStateOpen Then rs.Close
rs.Open sql, db, adOpenDynamic, adLockOptimistic
If rs.RecordCount <> 0 Then
showdb
CMDPROSES(1).Caption = "&EDIT"
aktifcmd False, True, True, True, False
Else
CMDPROSES(1).Caption = "&SIMPAN"
aktifcmd False, True, True, True, False
End If
NAMA.SetFocus
End If
End Sub
Sub showdb()
With rs
NAMA.Text = !NAMA
End With
End Sub
Sub simpandb(log As Boolean)
If log Then
sql = "INSERT INTO MAHASISWA(NPM,NAMA)" & _
"values('" & NPM.Text & _
"','" & NAMA.Text & "')"
Else
sql = "UPDATE MAHASISWA SET NAMA='" & NAMA.Text & "'," & _
"where NPM='" & NPM.Text & "'"
End If
db.BeginTrans
db.Execute sql, adCmdTable
db.CommitTrans
hapus
End Sub
Tidak ada komentar:
Posting Komentar