Anda di halaman 1dari 5

Buat Database : Kampus Buat table mahasiswa Name Type NIM * Text Nama Text Alamat Text Jns_Kelamin

Text Desain Form

Size 10 20 30 10

Tambahkan Adodc lalu koneksikan ke database dan tabelnya Coding: Sub bersih(a As Form) Dim b As Object For Each b In a If TypeOf b Is TextBox Then b.Text = "" If TypeOf b Is OptionButton Then b.Value = False Lat VB2 Lab B AAE & DWI

Next End Sub Sub pasif(a As Form) Dim b As Object For Each b In a If TypeOf b Is TextBox Then b.Enabled = False If TypeOf b Is OptionButton Then b.Enabled = False Next End Sub Sub aktif(a As Form) Dim b As Object For Each b In a If TypeOf b Is TextBox Then b.Enabled = True If TypeOf b Is OptionButton Then b.Enabled = True Next End Sub Sub nim() With Adodc1.Recordset If .RecordCount <= 0 Then txtnim.Text = Format(Date, "yyyymm") + "001" Else Dim a As Integer .MoveLast a = Val(Right(!nim, 3)) + 1 txtnim.Text = Format(Date, "yyyymm") + Format(a, "000") End If End With End Sub Sub tampil() With Adodc1.Recordset txtnim.Text = !nim txtnama.Text = !Nama txtalamat.Text = !Alamat If !Jns_Kelamin = "Pria" Then opPria.Value = True Else opWanita.Value = True End If End With End Sub Private Sub Form_Load() bersih Me pasif Me Lat VB2 Lab B AAE & DWI

cmdinput.Enabled = True cmdsave.Enabled = False cmdcancel.Enabled = False cmdfind.Enabled = True cmdedit.Enabled = False cmddel.Enabled = False End Sub Sub nim() With Adodc1.Recordset If .RecordCount <= 0 Then txtnim.Text = Format(Date, "yyyymm") + "001" Else Dim a As Integer .MoveLast a = Val(Right(!nim, 3)) + 1 txtnim.Text = Format(Date, "yyyymm") + Format(a, "000") End If End With End Sub Private Sub cmdinput_Click() aktif Me nim txtnim.Enabled = False txtnama.SetFocus cmdinput.Enabled = False cmdsave.Enabled = True cmdcancel.Enabled = True cmdfind.Enabled = False End Sub Private Sub cmdsave_Click() With Adodc1.Recordset .Find "NIM='" & txtnim.Text & "'" If .EOF Then .AddNew !nim = txtnim.Text !Nama = txtnama.Text !Alamat = txtalamat.Text If opPria.Value = True Then !Jns_Kelamin = opPria.Caption Else !Jns_Kelamin = opWanita.Caption End If .Update Else Lat VB2 Lab B AAE & DWI

!Nama = txtnama.Text !Alamat = txtalamat.Text If opPria.Value = True Then !Jns_Kelamin = opPria.Caption Else !Jns_Kelamin = opWanita.Caption End If .Update End If End With Form_Load End Sub Private Sub cmdcancel_Click() Form_Load End Sub Private Sub cmdfind_Click() cari = InputBox("Input NIM yang dicari") With Adodc1.Recordset .Find "NIM ='" & cari & "'" If Not .EOF Then tampil cmdfind.Enabled = False cmdinput.Enabled = False cmdedit.Enabled = True cmddel.Enabled = True cmdcancel.Enabled = True Else MsgBox "NIM tidak ditemukan", vbOKOnly + vbInformation Form_Load End If End With End Sub Private Sub cmdedit_Click() aktif Me txtnim.Enabled = False cmdsave.Enabled = True cmddel.Enabled = False cmdedit.Enabled = False End Sub Private Sub cmddel_Click() Adodc1.Recordset.Delete Form_Load End Sub Lat VB2 Lab B AAE & DWI

Private Sub cmdfirs_Click() Adodc1.Recordset.MoveFirst tampil End Sub Private Sub cmdprev_Click() With Adodc1.Recordset .MovePrevious If .BOF Then .MoveFirst MsgBox "Awal Record", vbInformation + vbOKOnly End If tampil End With End Sub Private Sub cmdnext_Click() With Adodc1.Recordset .MoveNext If .EOF Then .MoveLast MsgBox "Akhir Record", vbInformation + vbOKOnly End If tampil End With End Sub Private Sub cmdlast_Click() Adodc1.Recordset.MoveLast tampil End Sub

Lat VB2

Lab B AAE & DWI

Anda mungkin juga menyukai