Advertisement
endarfernandes

Kodingan lengkap autonumber

Nov 26th, 2016
2,205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim datauser As ADODB.Recordset
  2. Dim kodeid  As ADODB.Recordset
  3. Private Sub AutoNomor()
  4.     Set kodeid = conn.Execute("select * from mahasiswa order by idmahasiswa desc")
  5.         With kodeid
  6.             If .EOF Then
  7.                 txtnim.Text = "MHS" & "001"
  8.             Else
  9.                 txtnim.Text = "MHS" & Right(Str(Val(Right(.Fields(0), 3)) + 1001), 3)
  10.             End If
  11.         End With
  12. End Sub
  13. Sub aktif()
  14.     txtnama.Enabled = True
  15.     txtjurusan.Enabled = True
  16.     txtnohp.Enabled = True
  17. End Sub
  18. Sub nonaktif()
  19.     txtnim.Enabled = False
  20.     txtnama.Enabled = False
  21.     txtjurusan.Enabled = False
  22.     txtnohp.Enabled = False
  23. End Sub
  24. Sub bersih()
  25.     txtnim.Text = ""
  26.     txtnama.Text = ""
  27.     txtjurusan.Text = ""
  28.     txtnohp.Text = ""
  29. End Sub
  30.  
  31. Private Sub cmdinput_Click()
  32.     If cmdinput.Caption = "INPUT" Then
  33.         aktif
  34.         cmdinput.Caption = "SIMPAN"
  35.         txtnama.SetFocus
  36.         AutoNomor
  37.     ElseIf cmdinput.Caption = "SIMPAN" Then
  38.         Set datauser = New ADODB.Recordset
  39.         query = "insert into mahasiswa values ('" & txtnim.Text & "', '" & txtnama.Text & "','" & txtjurusan.Text & "','" & txtnohp.Text & "')"
  40.         conn.Execute query
  41.         Set datauser = New ADODB.Recordset
  42.         datauser.Open "select * from mahasiswa", conn
  43.         Set DataGrid1.DataSource = datauser
  44.         MsgBox "Data Berhasil Disimpan"
  45.     End If
  46. End Sub
  47.  
  48. Private Sub Form_Load()
  49.     bersih
  50.     nonaktif
  51.     Set datauser = New ADODB.Recordset
  52.     datauser.Open "select * from mahasiswa", conn
  53.     Set DataGrid1.DataSource = datauser
  54. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement