Advertisement
ba5tz

Rapih Rapih

Jul 13th, 2019
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.31 KB | None | 0 0
  1. Private Sub TombolTambah_Click()
  2. Dim iRow As Long
  3. DIm Path As String: Path = ThisWorkbook.Path & "\FotoSiswa\"
  4. Dim Ws As Worksheet: Set Ws = Worksheets("Sheet1")
  5.  
  6. iRow = Ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
  7.  
  8. If WorksheetFunction.CountIf(Ws.Range("B2", Ws.Cells(iRow - 1, 2)), Me.TextBox1.Value) > 0 Then
  9.     MsgBox "No Induk Sudah ada dalam Database, Silakan Lakukan edit jika ada kesalahan", vbCritical
  10.     Exit Sub
  11. End If
  12.  
  13. If CheckKosong then
  14.     With Ws
  15.         .Cells(iRow, 2).Value = TextBox1.Value
  16.         .Cells(iRow, 3).Value = TextBox2.Value
  17.         .Cells(iRow, 4).Value = TextBox3.Value
  18.         .Cells(iRow, 5).Value = TextBox4.Value
  19.         .Cells(iRow, 6).Value = TextBox5.Value
  20.         .Cells(iRow, 7).Value = TextBox6.Value
  21.         .Cells(iRow, 8).Value = TextBox7.Value
  22.         .Cells(iRow, 9).Value = Path & Me.TextBox1.Value & ".jpg"
  23.         Set myPict = Ws.Cells(iRow, 10).Parent.Pictures.Insert(Ws.Cells(iRow, 9).Value)
  24.         myPict.Top = Ws.Cells(iRow, 10).Top
  25.         myPict.Width = Ws.Cells(iRow, 10).Width
  26.         myPict.Height = Ws.Cells(iRow, 10).Height
  27.         myPict.Left = Ws.Cells(iRow, 10).Left
  28.         myPict.Placement = xlMoveAndSize
  29.     end With   
  30.        
  31.     SavePicture UserForm1.Image1.Picture, Path & UserForm1.TextBox1.Value & ".jpg"
  32.  
  33.     MsgBox "Data berhasil ditambahkan ", vbInformation, "Info"
  34.     Call BERSIHKAN
  35.     Call ListDSiswa
  36. end if
  37. End Sub
  38.  
  39. Function CheckKosong() as boolean
  40. Dim Pesan as string
  41. If Trim(Me.TextBox1.Value) = vbNullString Then
  42.     TextBox1.SetFocus
  43.     pesan = "Silakan Masukan No Induk"
  44.     CheckKosong = False
  45. elseIf Trim(Me.TextBox2.Value) = vbNullString Then
  46.     TextBox2.SetFocus
  47.     Pesan = "Silakan Masukan NIS"
  48.     CheckKosong = False
  49. elseIf Trim(Me.TextBox3.Value) = vbNullString Then
  50.     TextBox3.SetFocus
  51.     Pesan = "Silakan Masukan NAMA"
  52.     CheckKosong = False
  53. ElseIf Trim(Me.TextBox4.Value) = vbNullString Then
  54.     TextBox4.SetFocus
  55.     Pesan = "Silakan Masukan Jenis Kelamin"
  56.     CheckKosong = False
  57. ElseIf Trim(Me.TextBox5.Value) = vbNullString Then
  58.     TextBox5.SetFocus
  59.     Pesan = "Silakan Masukan Tempat Lahir"
  60.     CheckKosong = False
  61. ElseIf Trim(Me.TextBox6.Value) = vbNullString Then
  62.     TextBox6.SetFocus
  63.     Pesan = "Silakan Masukan Tanggal Lahir"
  64.     CheckKosong = False
  65. ElseIf Trim(Me.TextBox7.Value) = vbNullString Then
  66.     TextBox7.SetFocus
  67.     Pesan = "Silakan Masukan Kelas"
  68.     CheckKosong = False
  69. else
  70.     checkKosong = True
  71. End If
  72. msgbox Pesan
  73. end Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement