Gambarnya
Ketika saya ketikkan 1 di textbox nomor induk, dan dienter akan keluar di textbox ID akan terisi ID selanjutnya.
Private Sub an()
Dim Urut As
Integer, titik As String, id As String
Dim Hitung As String, jum As String, tmbhtitik As
String
If rs.State Then
rs.Close
eksekusiSQL =
"select Count(id) as id from terapi1 where induk = '" &
txtinduk.Text & "'"
rs.Open
eksekusiSQL, cn, adOpenKeyset, adLockOptimistic
'Set rs =
cn.Execute
Urut = txtinduk.Text
titik = "."
With
rs
If rs.EOF Then
Else
Hitung = rs.Fields(0)
jum = Hitung + 1
tmbhtitik = txtinduk + titik
id = tmbhtitik + jum
txtid.Text = id
txtterapi.SetFocus
If txtinduk.Text = "0" Then
Hitung = (rs.Fields!id)
id = (Hitung)
txtid = id
txtterapi.SetFocus
End If
End If
End
With
End Sub
Lalu jangan lupa:
Private Sub txtinduk_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If rs.State Then rs.Close
eksekusiSQL = "select induk,id,kls_terapi, hal from terapi1 " & _
" where id = '" & txtinduk.Text & "'"
rs.Open eksekusiSQL, cn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
txtinduk = rs.Fields!id
Call an
Else
If txtinduk.Text <> 0 Then
txtid.Text = txtinduk.Text
txtinduk.Text = 0
End If
'MsgBox "Maaf nomor induk tidak ada dalam database!"
End If
End If
If Not ((KeyAscii >= 48) And (KeyAscii <= 57) Or KeyAscii = 8) Then
KeyAscii = 0
End If
End Sub
0 komentar:
Posting Komentar