Private Sub TNR_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKey0 To vbKey9
' OK
Case Else
' Not allowed
KeyAscii = 0
Beep
End Select
End Sub
Private Sub TNR_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKey0 To vbKey9
' OK
Case Else
' Not allowed
KeyAscii = 0
Beep
End Select
End Sub
NICE!
But i f i cut and paste, the code dont controll lenght and numeric value....
Private Sub CommandButton2_Click()
Dim i As Long
Dim f As Boolean
Me.TextBox1.SetFocus
DoEvents
If Len(Me.TNR.Text) <> 10 Then
Me.TNR.Text = ""
Me.LAZIONI1.Caption = "NUMERO ASSEGNO 10 CIFRE!"
DoEvents
Sleep (800)
Me.LAZIONI1.Caption = ""
Me.TNR.SetFocus
DoEvents
Else
For i = 1 To 10
If Not IsNumeric(Mid(Me.TNR.Text, i, 1)) Then
f = True
Exit For
End If
Next i
If f Then
Me.TNR.Text = ""
Me.LAZIONI1.Caption = "NUMERO ASSEGNO 10 CIFRE!"
DoEvents
Sleep (800)
Me.LAZIONI1.Caption = ""
Me.TNR.SetFocus
DoEvents
Else
Sql = "SELECT * FROM TOT_ASSEGNI_5000 WHERE TOT_ASSEGNI_5000.NR_ASS='" & Me.TNR.Text & "'"
Set RS = New ADODB.Recordset
RS.CursorLocation = adUseClient
RS.Open Sql, CNN1, adOpenStatic, adLockReadOnly
If Not RS.EOF Then
Erase strDBRows()
strDBRows = RS.GetRows()
RS.Close
Set RS = Nothing
Else
Me.LAZIONI1.Caption = "NR. ASSEGNO: " & Me.TNR.Text & " NON TROVATO!"
Me.TNR.Text = ""
DoEvents
Sleep (800)
Me.LAZIONI1.Caption = ""
Me.TNR.SetFocus
DoEvents
End If
End If
End If
End Sub
Private Sub CommandButton2_Click()
Dim i As Long
Dim f As Boolean
Me.TextBox1.SetFocus
DoEvents
If Len(Me.TNR.Text) <> 10 Then
Me.TNR.Text = ""
Me.LAZIONI1.Caption = "NUMERO ASSEGNO 10 CIFRE!"
DoEvents
Sleep (800)
Me.LAZIONI1.Caption = ""
Me.TNR.SetFocus
DoEvents
Else
For i = 1 To 10
If Not IsNumeric(Mid(Me.TNR.Text, i, 1)) Then
f = True
Exit For
End If
Next i
If f Then
Me.TNR.Text = ""
Me.LAZIONI1.Caption = "NUMERO ASSEGNO 10 CIFRE!"
DoEvents
Sleep (800)
Me.LAZIONI1.Caption = ""
Me.TNR.SetFocus
DoEvents
Else
Sql = "SELECT * FROM TOT_ASSEGNI_5000 WHERE TOT_ASSEGNI_5000.NR_ASS='" & Me.TNR.Text & "'"
Set RS = New ADODB.Recordset
RS.CursorLocation = adUseClient
RS.Open Sql, CNN1, adOpenStatic, adLockReadOnly
If Not RS.EOF Then
Erase strDBRows()
strDBRows = RS.GetRows()
RS.Close
Set RS = Nothing
Else
Me.LAZIONI1.Caption = "NR. ASSEGNO: " & Me.TNR.Text & " NON TROVATO!"
Me.TNR.Text = ""
DoEvents
Sleep (800)
Me.LAZIONI1.Caption = ""
Me.TNR.SetFocus
DoEvents
End If
End If
End If
End Sub