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...
Printable View
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...
Change the Style property to 2.
Change the Style property
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?Quote:
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...
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...
Do something like
VB Code:
If .Fields("MfgTextRecvd") > "" Then cmbMfgTextRecvd.AddItem .Fields("MfgTextRecvd") End If
Here is a public function that I wrote a while ago that can handel that.
Usage...VB Code:
Option Explicit Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Private Const CB_FINDSTRINGEXACT = &H158 Private Const CB_FINDSTRING = &H14C Public Function SearchCBO(ByRef cboCtl As ComboBox, ByVal sSearchCriteria As String, Optional ByVal bLIKE As Boolean) As Long '<RR 08/08/2003 - VB/OUTLOOK GURU> On Error GoTo No_Bugs If bLIKE = False Then 'EXACT MATCH SearchCBO = SendMessageStr(cboCtl.hwnd, CB_FINDSTRINGEXACT, 0&, ByVal sSearchCriteria) Else 'LIKE MATCH SearchCBO = SendMessageStr(cboCtl.hwnd, CB_FINDSTRING, 0&, ByVal sSearchCriteria) End If Exit Function No_Bugs: MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation Exit Function Resume 'FOR DEBUGGING End Function
If it exists it will change the combo to the item and if it doesn't then itVB Code:
'... '... '... cmbMfgTextRecvd.ListIndex = SearchCBO(cmbMfgTextRecvd, .Fields("MfgTextRecvd") & "", False)
will set the combo to a listindex of -1 which is no selection.
HTH
Thanks much to all of you.. for responding so promptly..