How to make textbox accept only P,R,I,D,E characters? (1 Viewer)

swaroop1012

Registered User.
Local time
Today, 16:49
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.
 

John Big Booty

AWF VIP
Local time
Tomorrow, 03:49
Joined
Aug 29, 2005
Messages
8,263
Do you want the text box to only accept a single character from your list, or any combination of characters from your list?
 

DCrake

Remembered
Local time
Today, 16:49
Joined
Jun 8, 2005
Messages
8,632
If the user can only select on the characters then why not use a combo box instead?
 

swaroop1012

Registered User.
Local time
Today, 16:49
Joined
Nov 21, 2008
Messages
19
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.
 

Kryst51

Singin' in the Hou. Rain
Local time
Today, 11:49
Joined
Jun 29, 2009
Messages
1,898
Hi Crake,

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

Cheers.

What about multiple combo boxes?
 

DCrake

Remembered
Local time
Today, 16:49
Joined
Jun 8, 2005
Messages
8,632
Use a BeforeUpdate/AfterUpdate validation check on the user input or use the KeyPress event to examine the keycode pressed.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 16:49
Joined
Sep 12, 2006
Messages
15,613
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:

Kryst51

Singin' in the Hou. Rain
Local time
Today, 11:49
Joined
Jun 29, 2009
Messages
1,898
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.
 

swaroop1012

Registered User.
Local time
Today, 16:49
Joined
Nov 21, 2008
Messages
19
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.
 

Kryst51

Singin' in the Hou. Rain
Local time
Today, 11:49
Joined
Jun 29, 2009
Messages
1,898
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. :)
 

swaroop1012

Registered User.
Local time
Today, 16:49
Joined
Nov 21, 2008
Messages
19
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

  • db1.zip
    185.7 KB · Views: 117

missinglinq

AWF VIP
Local time
Today, 12:49
Joined
Jun 20, 2003
Messages
6,423
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
 

Kryst51

Singin' in the Hou. Rain
Local time
Today, 11:49
Joined
Jun 29, 2009
Messages
1,898
I tried missinglinq's code in your db, it works perfectly to just allow the letters! Awesome! Much better than how I was thinking.
 

missinglinq

AWF VIP
Local time
Today, 12:49
Joined
Jun 20, 2003
Messages
6,423
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
 

DCrake

Remembered
Local time
Today, 16:49
Joined
Jun 8, 2005
Messages
8,632
Di dyou say that you have nearly finished it and was adding bells and whistles?:rolleyes:

David
 

usr_X

Registered User.
Local time
Today, 11:49
Joined
Jun 9, 2009
Messages
26
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

Top Bottom