السلام عليكم
باختصار لدي نموذج يحوي على ارقام فحسب ولايمكن للمستخدم ان يدخل اي حرف به ولكن الكود الذي حصلت عليه يمنع حتى التعديل بزر BACKSPACE او غيرة من ازرار التعديل
فكيف نسمح للمستاخدم بالقيام بالامرين
ادخال الارقام مع امكانية التعديل بطبيعة الحال باستخدام BACKSPCE
هذا الكود يمنع المستخدم من ادخال اي زر في لوحة المفاتيح عدا الأرقام
Private Sub LNobox_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End Subوحصلت على كود ولكن لم ينجح
اذا كان بالامكان المحاولة في تطبيقة في نموذج بسيط
هذا الكود يفترض به ان يقوم بالواجب ولكن لم استطع من استدعاء الموديل في النموذج رغم البساطة
Public Function LimitUnboundTextBox(KeyAscii As Integer, TextBoxSizeLimit As Integer, Optional InputType As String = "Optional: Default=All Chars or enter A for Alpha Only, I for Integer Only") 'Author: Allan L Taylor ' 'Purpose: To limit the number of characters/digits that can be entered into a unbound textbox and ' allows the selection of the input type ie All Chars, Alpha Only or Integer Only ' 'Version 1 ' 'Example usage:- ' 'Private Sub TextBoxName_KeyPress(KeyAscii As Integer) ' ' LimitTextBoxSize KeyAscii, 12 'Alpha Numeric input by default with max length of 12 chars ' LimitTextBoxSize KeyAscii, 4, "A" 'Alpha input only with max length of 4 chars ' LimitTextBoxSize KeyAscii, 8, "I" 'Integer input only with max length of 8 digits ' 'End Sub Dim cntActiveControl As Control Dim txtTextBoxContent As String On Error GoTo ErrorDetected 'Get active control Set cntActiveControl = Screen.ActiveControl 'Get the control text txtTextBoxContent = cntActiveControl.Text 'Check for backspace being pressed If KeyAscii = 8 Then Exit Function End If If InputType = "I" Then 'Integer only If KeyAscii < 48 Or KeyAscii > 57 Then MsgBox "Input is restricted to a numeric integer only (values '0 to 9')", vbOKOnly, "User Input Warning" KeyAscii = 0 Exit Function End If ElseIf InputType = "A" Then 'Alha only If (KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii <= 122) Then 'do nothing Else MsgBox "Input is restricted to a Alpha chars only (values 'a to z' or 'A to Z')", vbOKOnly, "User Input Warning" KeyAscii = 0 Exit Function End If End If 'Warn user the last possible character has been entered If Len(txtTextBoxContent) = TextBoxSizeLimit - 1 Then Beep End If 'check length is < max limit If Len(txtTextBoxContent) < TextBoxSizeLimit Then 'Append typed character into the textbox txtTextBoxContent = Left(txtTextBoxContent, cntActiveControl.SelStart) 'Find text box insertion point txtTextBoxContent = txtTextBoxContent & Chr$(KeyAscii) 'Add new char/digit txtTextBoxContent = txtTextBoxContent & Mid(txtTextBoxContent, cntActiveControl.SelStart + 1 + cntActiveControl.SelLength) 'where applicable place remaining text on end of insertion point Else MsgBox "Input size is restricted to " & TextBoxSizeLimit & IIf(InputType = "I", " digits", " chars"), vbOKOnly, "User Input Warning" KeyAscii = 0 End If Exit Function ErrorDetected: MsgBox Err.Number & " - " & Err.Description, vbCritical, "Unexpected Error Occurred, Operation Aborted" End Function
شكرا جزيلا
وبارك الله فيك