You are on page 1of 2

Private Sub UserForm_Activate()

Dim Ws As Worksheet

Set Ws = Worksheet("DATABASE")

txtMAX.Value = Range("A1").Value

txtNO.SetFocus

End Sub

'menyimpan data

Private Sub cmdINPUT_Clik()

Dim iRow As Long

Dim Ws As Worksheet

Set Ws = Worksheet("DATABASE")

'menentukan baris kosong pada database

iRow = Ws.Cells(Rows.Count, 1) _

.End(x1Up).Offset(1, 0).Row

'Cek untuk sebuah kode

If Trim(Me.txtNO.Value) = "" Then

Me.txtNO.SetFocus

MsgBox "TIDAK MENGOSONGKAN NOMOR URUT"

Exit Sub

End If

'menemukan nomor yang sama

Dta = Me.txtNO.Value
With Worksheet("DATABASE").Range("A5:A200")

Set C = .Find(Data, LookIn = "xIFormulas")

If C Is Nothing Then

MsgBox "CEK NOMOR URUT IS OKE"

Else

MsgBox "NOMOR URUT SUDAH ADA"

Me.txtNO.Value = ""

Me.txtNO.SetFocus

Exit Sub

End If

End With

'Copy data ke database

Ms.Cells(iRows, 1).Value = Me.txtNO.Value

Ms.Cells(iRows, 2).Value = Me.txtKK.Value

Ms.Cells(iRows, 3).Value = Me.txtNAMA.Value

Ms.Cells(iRows, 4).Value = Me.txtNIK.Value

You might also like