Results 1 to 9 of 9

Thread: dropdown combos

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    dropdown combos

    Any 1 recalls the simpler way to not allow the user to type something of his own in a drop down box.. only the items chosen?

    Thanks in advance...

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Change the Style property to 2.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    Change the Style property
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    to 2

    When I change the style property to 2... it would work ok... The problem is that blank fields or fields with Null values would kick an error... Any workaround...

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: to 2

    Originally posted by Lafor
    When I change the style property to 2... it would work ok... The problem is that blank fields or fields with Null values would kick an error... Any workaround...
    What is the source of the data? Why can't you filter it befeore you load the combobox?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Yes

    Here is how I do it

    From a loaded recordset

    cmbMfgTextRecvd.Text = .Fields("MfgTextRecvd") & ""

    Still get the error.. I don't really want to put a blank in there...

  7. #7

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is a public function that I wrote a while ago that can handel that.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    4. ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    5.  
    6. Private Const CB_FINDSTRINGEXACT = &H158
    7. Private Const CB_FINDSTRING = &H14C
    8.  
    9. Public Function SearchCBO(ByRef cboCtl As ComboBox, ByVal sSearchCriteria As String, Optional ByVal bLIKE As Boolean) As Long
    10. '<RR 08/08/2003 - VB/OUTLOOK GURU>
    11.     On Error GoTo No_Bugs
    12.    
    13.     If bLIKE = False Then 'EXACT MATCH
    14.         SearchCBO = SendMessageStr(cboCtl.hwnd, CB_FINDSTRINGEXACT, 0&, ByVal sSearchCriteria)
    15.     Else 'LIKE MATCH
    16.         SearchCBO = SendMessageStr(cboCtl.hwnd, CB_FINDSTRING, 0&, ByVal sSearchCriteria)
    17.     End If
    18.     Exit Function
    19.    
    20. No_Bugs:
    21.    
    22.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation
    23.     Exit Function
    24.     Resume 'FOR DEBUGGING
    25. End Function
    Usage...
    VB Code:
    1. '...
    2. '...
    3. '...
    4. cmbMfgTextRecvd.ListIndex = SearchCBO(cmbMfgTextRecvd, .Fields("MfgTextRecvd") & "", False)
    If it exists it will change the combo to the item and if it doesn't then it
    will set the combo to a listindex of -1 which is no selection.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Thanks

    Thanks much to all of you.. for responding so promptly..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width