genuinemails.com

Kamis, 18 Februari 2010

Tips and trick (part 2)

Source Code for Validation Program using Visual Basic 6.o, If you tertatik Tips and Tricks with Visual Basic is Please Read below ...

Only numbers can be input in TextBoxt :

Private Sub txtNomor_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") & Chr(13) _
And KeyAscii <= Asc("9") & Chr(13) _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyDelete _
Or KeyAscii = vbKeySpace) Then
Beep
KeyAscii = 0
End If
End Sub

Only Letter :

Private Sub txtNama_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= Asc("a") & Chr(13) _
And KeyAscii <= Asc("z") & Chr(13) _
Or (KeyAscii >= Asc("A") & Chr(13) _
And KeyAscii <= Asc("Z") & Chr(13) _
Or KeyAscii = vbKeyBack _
Or KeyAscii = vbKeyDelete _
Or KeyAscii = vbKeySpace)) Then
Beep
KeyAscii = 0
End If
End Sub

All cleaning TextBox Control and Combo Box :

Sub Clear()
For Each Control In Me.Controls
If TypeOf Control Is TextBox Then
Control.Text = ""
End If
If TypeOf Control Is ComboBox Then
Control.Text = ""
End If
Next Control
End Sub

NB: if there is another key condition plus live in IFnya aja, and to disable all the buttons to stay instead of "Control.Text = Enabled" wrote

Get Auto Number :

Private Sub Auto()
Dim Urutan As String * 10
Dim Tgl As String
Dim Hitung
Set TMasuk = New ADODB.Recordset
TMasuk.Open "Select * from Masuk", Persediaan, adOpenDynamic, adLockPessimistic
'TMasuk.MoveFirst
Tgl = Format(Now, "yy/mm/dd")
With TMasuk
If .RecordCount = 0 Then
Urutan = Right(Tgl, 2) + Mid(Tgl, 4, 2) + Left(Tgl, 2) + "0001"
Else
.MoveLast
If Left(![No Masuk], 6) <> Right(Tgl, 2) + Mid(Tgl, 4, 2) + Left(Tgl, 2) Then
Urutan = Right(Tgl, 2) + Mid(Tgl, 4, 2) + Left(Tgl, 2) + "0001"
Else
Hitung = (![No Masuk]) + 1
Urutan = (Right(Tgl, 2) + Mid(Tgl, 4, 2) + Left(Tgl, 2)) + Right("0000" & Hitung, 4)
End If
End If
txtNomor = Urutan
End With
End Sub

Related Posts by Categories



Widget by Hoctro | Jack Book

Your cOmment"s Here! Hover Your cUrsOr to leave a cOmment.

BlogCatalog

My Sponsor