Microsoft KB Archive/140353

= BUG: KeyAscii Behavior Different with DBCombo Control =

Article ID: 140353

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q140353



SYMPTOMS
Setting the KeyAscii parameter to 0 in a KeyPress event of a DBCombo control shows the character being typed. The expected behavior is the same as a TextBox control--characters being typed should not appear in the DBCombo control.



WORKAROUND
To work around this problem, place a TextBox control over the top of the text portion of the DBCombo control. Add code shown below to the KeyPress event of the TextBox control to accept and reject the appropriate characters. If you would like typed characters not to appear, then use the normal method of setting the KeyPress parameter of the TextBox control to 0. All other characters from the TextBox control can be passed through the DBCombo control by appending the characters to the Text property of the DBCombo control.

The following code example shows only numeric values in the TextBox control and passes those values to the Text property of the DBCombo control. Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48) Or (KeyAscii > 57) Then KeyAscii = 0 Else DBCombo1.Text = Text1.Text & Chr$(KeyAscii) End If

End Sub You can also add code to exactly mimic the functionality of an empty TextBox control. For example, you can add code to allow the user to backspace and also to ensure that changes in the DBCombo control are reflected in the TextBox control.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start Visual Basic 4.0 or if it is already running, click New Project on the File menu. Add a DBCombo and a TextBox control to the Form1 form.  Copy the following code sample to the Form1 code window: Private Sub DBCombo_KeyPress(KeyAscii As Integer) If (KeyAscii < 48) Or (KeyAscii > 57) Then KeyAscii = 0 End If     End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If (KeyAscii < 48) Or (KeyAscii > 57) Then KeyAscii = 0 End If     End Sub  Press the F5 key or click Start on the Run menu to start the program. Enter some characters in the DBCombo control. The DBCombo control shows all the characters typed. Now enter some character in the TextBox control. Note that only numbers appear in the TextBox control The code in the KeyPress event of either control should cause only numbers (0-9) to be displayed. All other characters should be rejected and should not be displayed.</ol>

Additional query words: buglist4.00 4.00 DBCombo vb4all vb4win combobox textbox

Keywords: kbbug KB140353

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.