BUG: DBCombo Does Not Display the "&" Character Correctly

Last reviewed: November 19, 1997
Article ID: Q176873
The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0

SYMPTOMS

If a DBCombo control contains items with the ampersand (&) character as part of the text and if the style of the DBCombo control is dbcDropdownList, then the text will not display correctly in the text box portion (the edit area) of the control. The drop-down list area is not affected.

This problem does not occur with the styles dbcDropdownCombo or dbcSimpleCombo.

RESOLUTION

To work around this problem, simply modify the text to include an extra "&" for every "&" that is in the original text as shown in the following code:

   Private Sub DBCombo1_Click(Area As Integer)
   Dim i As Integer
   Dim s As String
   Dim c As String * 1

       If DBCombo1.Style = dbcDropdownList And Area = dbcAreaList Then
           s = DBCombo1.Text
           If InStr(s, "&") Then
               DBCombo1.Text = ""
               For i = 1 To Len(s)
                   c = Mid$(s, i, 1)
                   If c = "&" Then
                       DBCombo1.Text = DBCombo1.Text & "&&"
                   Else
                       DBCombo1.Text = DBCombo1.Text & c
                   End If
               Next
           End If
       End If

   End Sub

STATUS

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

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a sample MDB (db1.mdb) and add one table (Table1) with one text field (Field1). Add the record "&one &&two &&&three" to Table1.

  2. Start Visual Basic and create a new Standard EXE. Form1 is created by default.

  3. Add a Data control to Form1 and set the following properties:

          DatabaseName = "db1.mdb"
          RecordSource = "Table1"
    

  4. Add a DBCombo control to Form1 and set the following properties:

          RowSource = "Data1"
          ListField = "Field1"
          Style = "2 - dbcDropdownList"
    

  5. Run the project.

  6. Click the button on DBCombo1 and select the item from the list.
Keywords          : vb5all
Version           : WINDOWS:5.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.