How to make textbox accept only P,R,I,D,E characters?

swaroop1012

Registered User.
Local time
Today, 18:47
Joined
Nov 21, 2008
Messages
19
Hi all,

I have a database where there is a text box in which the user has to enter only P,R,I,D,E characters. Is it possible to do that.

Thanks in advance.
 
Do you want the text box to only accept a single character from your list, or any combination of characters from your list?
 
If the user can only select on the characters then why not use a combo box instead?
 
Hi Crake,

the user has to select multiple valuse which is not possible with combo box.

Cheers.

What about multiple combo boxes?
 
Use a BeforeUpdate/AfterUpdate validation check on the user input or use the KeyPress event to examine the keycode pressed.
 
with such a small selection, you could have a multi-select LIST BOX.

alternatively you could just have some buttons/check boxes, one for each letter
 
Last edited:
i dont think it is possible..even it is possible, it makes the form look bad and i think its not a good procedure.

I think my thought was that if you had a table that had fields, each field contains one character. And another table that included each option, then link that table to the fields in the other table through combo boxes on a form, then users could select their combination quite easily, Also, I bet you could do some kind of coding that made the cursor jump to the next combo box after a letter was entered, like a lot of websites that require you to enter phone numbers or social security numbers that have a fixed number of digits.
 
I think my thought was that if you had a table that had fields, each field contains one character. And another table that included each option, then link that table to the fields in the other table through combo boxes on a form, then users could select their combination quite easily, Also, I bet you could do some kind of coding that made the cursor jump to the next combo box after a letter was entered, like a lot of websites that require you to enter phone numbers or social security numbers that have a fixed number of digits.

Hi Kryst,

The problem is i almost finished with the database and now just trying to tweak it for better user satisfaction. if u want i will send u the database to have a look at.

Cheers.
 
The problem is i almost finished with the database and now just trying to tweak it for better user satisfaction. if u want i will send u the database to have a look at.

Oh, OK, No Problem. I don't know a lot of complex ways to do things, so I try to think of simplified ways. I would be happy to look at the database. :)
 
Oh, OK, No Problem. I don't know a lot of complex ways to do things, so I try to think of simplified ways. I would be happy to look at the database. :)

Hi Kryst,

here is the copy of database as an attachment

Cheers.
 

Attachments

This will allow the letters listed to be entered and allow the user to move within the textbox using the arrow keys, delete key, etc:

Code:
Private Sub YourTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
 Select Case KeyCode
  Case vbKeyP, vbKeyR, vbKeyI, vbKeyD, vbKeyE, vbKeyLeft, vbKeyRight, vbKeyReturn, vbKeyDelete, vbKeyBack, vbKeySpace
   KeyCode = KeyCode
  Case Else
   KeyCode = 0
  End Select
End Sub
 
I tried missinglinq's code in your db, it works perfectly to just allow the letters! Awesome! Much better than how I was thinking.
 
Don't know your exact needs, but if you should need to separate the given letters with a comma (,) you'll need to add the Keycode for a comma (44) to the allowed keys. Never have found the vbConstant for a comma.

Code:
Case 44, vbKeyP, vbKeyR, vbKeyI, vbKeyD, vbKeyE, vbKeyLeft, vbKeyRight, vbKeyReturn, vbKeyDelete, vbKeyBack, vbKeySpace
 
Di dyou say that you have nearly finished it and was adding bells and whistles?:rolleyes:

David
 
If you wanted to limit the input to an exact string:

Code:
Private Sub txtInputTest_KeyPress(KeyAscii As Integer)

Dim strLimitInputTo As String
Dim intConvert As Integer

lblResults.Caption = "ASCII = " & KeyAscii

strLimitInputTo = "P,R,I,D,E"

If Len(txtInputTest.Text) < Len(strLimitInputTo) Then
   intConvert = Asc(Mid$(strLimitInputTo, Len(txtInputTest.Text) + 1, 1))
End If

Select Case KeyAscii
   Case 8, intConvert
      KeyAscii = KeyAscii
   Case Else
      KeyAscii = 0
End Select

End Sub

Also, the ASCII codes http://msdn.microsoft.com/en-us/library/4z4t9ed1(VS.80).aspx and the VB 6.0 key code constants (which I *believe* are the same for VBA) http://msdn.microsoft.com/en-us/library/0z084th3.aspx.

Have a nice day. Sincerely, Usr_X
 

Users who are viewing this thread

Back
Top Bottom