0% found this document useful (0 votes)
40 views2 pages

Kode

The VBA code defines macros to activate a user form and submit data from the form to a database worksheet. When the form loads, it sets focus to the TxtNOMOR text box. The cmdINPUT_Click macro finds the next empty row, checks if the form number already exists, copies the form data to the database if unique, clears the form fields, and notifies the user that the data was entered. It prevents duplicate numbers and empty required fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

Kode

The VBA code defines macros to activate a user form and submit data from the form to a database worksheet. When the form loads, it sets focus to the TxtNOMOR text box. The cmdINPUT_Click macro finds the next empty row, checks if the form number already exists, copies the form data to the database if unique, clears the form fields, and notifies the user that the data was entered. It prevents duplicate numbers and empty required fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Private Sub UserForm_Activate()

Dim Ws As Worksheet
Set Ws = Worksheets(“DATABASE”)
TxtNOMOR.SetFocus
End Sub

‘menyimpan data
Private Sub cmdINPUT_Click()
Dim iRow As Long
Dim Ws As WorkSheets(“DATABASE”)

‘menemukan baris kosong pada database


iRow = Ws.Cells(Rows.Count, 1) _
.End(xlUp).offset(1, 0).Row
‘Cek untuk sebuah kode
If Trim(Me.txtNOMOR.Value) = “” Then
Me.txtNOMOR.SetFocus
MsgBox “TIDAK MENGOSONGKAN NOMOR URUT”
Exit Sub
End If

‘menemukan nomor yang sama


Data = Me.txtNOMOR.Value
With Worksheets(“DATABASE”).Range(“A3:A100.000”)
Set C = .Find(Data, LookIn:=xlFormulas)
If C Is Nothing Then
MsgBox “CEK NOMOR URUT IS OKE”
Else
MsgBox “NOMOR URUT SUDAH ADA”
Me.txtNOMOR.Value = “’
Me.txtNOMOR.SetFocus
Exit Sub
End If
End With

‘copy data ke database


Ws.Cells(iRow, 1).Value = Me.txtNOMOR.Value
Ws.Cells(iRow, 2).Value = Me.txtNAMA.Value
Ws.Cells(iRow, 3).Value = Me.txtKAMPUNG.Value
Ws.Cells(iRow, 4).Value = Me.txtRTRW.Value
Ws.Cells(iRow, 5).Value = Me.cmbKECAMATAN.Value
Ws.Cells(iRow, 6).Value = Me.cmbDESAKELURAHAN.Value
Ws.Cells(iRow, 7).Value = Me.ckLAKILAKI.Value
Ws.Cells(iRow, 8).Value = Me.ckPEREMPUAN.Value
Ws.Cells(iRow, 9).Value = Me.cmbPENDIDIKAN.Value
Ws.Cells(iRow, 10).Value = Me.cmbKESEHATAN.Value
Ws.Cells(iRow, 11).Value = Me.cmbDAYABELI.Value

‘clear data
Me.txtNOMOR.Value = ‘’
Me.txtNAMA.Value = ‘’
Me.txtKAMPUNG.Value = ‘’
Me.txtRTRW.Value = ‘’
Me.cmbKECAMATAN.Value = ‘’
Me.cmbDESAKELURAHAN.Value = ‘’
Me.ckLAKILAKI.Value = ‘’
Me.ckPEREMPUAN.Value = “
Me.cmbPENDIDIKAN.Value = ‘’
Me.cmbKESEHATAN.Value = ‘’
Me.cmbDAYABELI.Value = ‘’
Me.txtNOMOR.SetFocus
MsgBox “DATA SUDAH DI ENTRY KE DATABASE”
End Sub

Private Sub

You might also like