Dim sambung, j As String
Dim kon As New ADODB.Connection
Dim vnim As New ADODB.Recordset
Private Sub Command1_Click()
Set rsim = New ADODB.Recordset
rsim.Open "formulir", kon, adOpenKeyset, adLockBatchOptimistic
rsim.AddNew
rsim!progdi = ps.ListIndex + 1
rsim!nim = tnim
rsim!nama = nama
rsim!tgllhr = tl
If op.Value = True Then
rsim!jk = 1
Else
rsim!jk = 0
End If
rsim!agama = agm.ListIndex + 1
rsim!alamat = alm
rsim!hp = hp
rsim.UpdateBatch adAffectAllChapters
Set dg.DataSource = rsim
End Sub
Private Sub Form_Load()
sambung = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\tgs.mdb;Persist Security Info=False"
Set kon = New ADODB.Connection
kon.Open sambung
kon.CursorLocation = adUseClient
Set rfor = New ADODB.Recordset
rfor.Open "formulir", kon, adOpenKeyset, adLockBatchOptimistic
Set dg.DataSource = rfor
ps.ListIndex = 0
tnim = ""
nama = ""
agm.ListIndex = 0
alm = ""
hp = ""
Label2.Caption = Format(Now(), "dddd, dd mmmm yyyy")
End Sub
Private Sub ps_LostFocus()
n = 1
If ps.ListIndex = 1 Then
j = "2"
ElseIf ps.ListIndex = 2 Then
j = "3"
Else
j = "1"
End If
Set rfor = kon.Execute("select * from formulir where mid(nim,5,1)='" & j & "'")
If rfor.RecordCount = 0 Then
tnim = "2" & Format(Now(), "yy") & "7" & j & "0000" & n
Else
rfor.MoveLast
n = Val(Right(rfor!nim, 5)) + 1
If n < 10 Then
tnim = "2" & Format(Now(), "yy") & "7" & j & "0000" & n & ""
ElseIf n < 100 Then
tnim = "2" & Format(Now(), "yy") & "7" & j & "000" & n & ""
ElseIf n < 1000 Then
tnim = "2" & Format(Now(), "yy") & "7" & j & "00" & n & ""
Else
tnim = "2" & Format(Now(), "yy") & "7" & j & "0" & n & ""
End If
End If
End Sub
No comments:
Post a Comment