Skip to content

Instantly share code, notes, and snippets.

@vbcupu
Created October 27, 2017 15:41
Show Gist options
  • Save vbcupu/0422f93c3e0c0f4b7fc44203283c8b96 to your computer and use it in GitHub Desktop.
Save vbcupu/0422f93c3e0c0f4b7fc44203283c8b96 to your computer and use it in GitHub Desktop.
artikel tutorial vb6 part 3
Private Sub cmdBatal_Click()
Call BersihForm
End Sub
Private Sub cmdHapus_Click()
strSQL = "Delete from Mahasiswa where NIM = '" & txtNIM.Text & "'"
Call execCmd(dbCmd, strSQL)
Call BersihForm
FillGrid
End Sub
Private Sub cmdSimpan_Click()
strSQL = "select Nim from mahasiswa where Nim = '" & txtNIM.Text & "';"
Call bukaRs(strSQL, rs)
If rs.EOF = True Or rs.BOF = True Then
strSQL = "Insert into Mahasiswa (Nim, Nama, Alamat, TempatLahir, TglLahir, Kota, IdFakultas) values " & _
"('" & txtNIM.Text & "', '" & txtNama.Text & "', '" & txtAlamat.Text & "', '" & txtTempatLahir.Text & "', '" & dtpTglLahir.Value & "', '" & txtKota.Text & "', '" & dcFakultas.BoundText & "')"
Call execCmd(dbCmd, strSQL)
Else
strSQL = "Update Mahasiswa set Nama = '" & txtNama.Text & "', Alamat = '" & txtAlamat.Text & "', TempatLahir = '" & txtTempatLahir & "', TglLahir = '" & dtpTglLahir.Value & "', Kota = '" & txtKota.Text & "', IdFakultas = '" & dcFakultas.BoundText & "' Where Nim = '" & txtNIM.Text & "'"
Call execCmd(dbCmd, strSQL)
End If
Call BersihForm
FillGrid
End Sub
Private Sub DataGrid1_Click()
If DataGrid1.ApproxCount < 1 Then Exit Sub
With DataGrid1
txtNIM.Text = .Columns("Nim").Value
txtNama.Text = .Columns("Nama").Value
txtAlamat.Text = .Columns("Alamat").Value
txtTempatLahir.Text = .Columns("TempatLahir").Text
dtpTglLahir.Value = .Columns("TglLahir").Value
txtKota.Text = .Columns("Kota").Text
dcFakultas.BoundText = .Columns("IdFakultas").Value
End With
cmdHapus.Enabled = True
End Sub
Private Sub dtpTglLahir_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then txtKota.SetFocus
End Sub
Private Sub Form_Load()
Call OpenConnection
Call BersihForm
Call IsiDataSource(dcFakultas, rs, "Select IdFakultas, NamaFakultas from Fakultas")
FillGrid
End Sub
Private Sub BersihForm()
txtNIM.Text = ""
txtNama.Text = ""
txtAlamat.Text = ""
txtKota.Text = ""
txtTempatLahir.Text = ""
dtpTglLahir.Value = Now
dcFakultas.BoundColumn = ""
cmdHapus.Enabled = False
FillGrid
End Sub
Private Sub txtAlamat_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtTempatLahir.SetFocus
End Sub
Private Sub txtCariAlamat_Change()
FillGrid
End Sub
Private Sub txtCariNama_Change()
FillGrid
End Sub
Private Sub txtKota_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then dcFakultas.SetFocus
End Sub
Private Sub txtNama_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtAlamat.SetFocus
End Sub
Private Sub txtTempatLahir_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then dtpTglLahir.SetFocus
End Sub
Public Sub FillGrid()
strSQL = "select a.Nim, a.Nama, a.TempatLahir, a.TglLahir, a.Alamat, a.Kota, b.NamaFakultas, a.IdFakultas from Mahasiswa as a inner join Fakultas as b on a.IdFakultas = b.IdFakultas where a.Nama like '%" & txtCariNama.Text & "%' and a.Alamat like '%" & txtCariAlamat.Text & "%'"
Call bukaRs(strSQL, rs)
Set DataGrid1.DataSource = rs
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment