craigewens
asked on
Adjusting the ComboBox list contents automatically
I have a small program used as a Mate/Demate log for connectors at work. The list of all the connectors is quite big and varied so all i need is some additions to this coding (below) to shorten the drop down list to all then entries that match whats been typed in so far.
For example if i type in a 5 first then click the drop down arrow i would only like to see the entries starting with a 5, but then iff i add a 9 to the 5 making the box say 59 i would then like the drop down box to reduce its contents to the entries starting 59.
I have seen this done on may programs and web pages so i know it is possible i just cant find how to do it in the VB help files :(
Here is an extract of some of the coding i have already done.
Private Sub Partbox_STATUS(enable As Boolean)
Select Case enable
Case False
Partbox.Visible = False
PartLabel.Visible = False
Partbox.Enabled = False
Partbox.Text = ""
Portbox_STATUS (False)
Case True
Dim name As String
Dim clock As String
Dim counter As Integer
Dim endloop As Integer
Dim check As Integer
endloop = 0
counter = 1
Partbox.Clear
Do
counter = counter + 1
part = Sheets(projectbox.Text).Ra nge(rowCol (counter, 1))
port = Sheets(projectbox.Text).Ra nge(rowCol (counter, 2))
If Len(Trim(port)) Then
If Len(Trim(part)) Then
Partbox.AddItem Trim(part)
End If
Else
endloop = 1
End If
Loop Until endloop
Sheets(projectbox.Text).Se lect
Range("E2").Select
Partbox.Visible = True
PartLabel.Visible = True
Partbox.Enabled = True
Partbox.SetFocus
End Select
End Sub
Private Sub partbox_Change()
If Partbox.MatchFound Then
Portbox_STATUS (True)
End If
End Sub
Private Sub partbox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case Is = 13, Is = 9
Partbox.Text = UCase(Partbox.Text)
If Partbox.MatchFound Then
Portbox_STATUS (True)
portbox.SetFocus
Else
found = -1
For loopcount = 0 To Partbox.ListCount - 1
If Trim(Partbox.List(loopcoun t)) = Trim(UCase(Partbox.Text)) Then
found = loopcount
End If
Next loopcount
If found >= 0 Then
Partbox.ListIndex = found
Portbox_STATUS (True)
Else
Partbox.Text = ""
Portbox_STATUS (False)
End If
End If
End Select
End Sub
Private Sub partbox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Partbox.Text = ""
End Sub
Private Sub partbox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Portbox_STATUS (False)
End Sub
I have looked at the MatchEntry properties options for the ComboBox and selecting anything other than MatchEntryNone make the program select the first match (if i hit 5 then it selects the first entry starting with a 5 and goes onto the next box).
Pls could anyone suggest anything??.
Thanks.
For example if i type in a 5 first then click the drop down arrow i would only like to see the entries starting with a 5, but then iff i add a 9 to the 5 making the box say 59 i would then like the drop down box to reduce its contents to the entries starting 59.
I have seen this done on may programs and web pages so i know it is possible i just cant find how to do it in the VB help files :(
Here is an extract of some of the coding i have already done.
Private Sub Partbox_STATUS(enable As Boolean)
Select Case enable
Case False
Partbox.Visible = False
PartLabel.Visible = False
Partbox.Enabled = False
Partbox.Text = ""
Portbox_STATUS (False)
Case True
Dim name As String
Dim clock As String
Dim counter As Integer
Dim endloop As Integer
Dim check As Integer
endloop = 0
counter = 1
Partbox.Clear
Do
counter = counter + 1
part = Sheets(projectbox.Text).Ra
port = Sheets(projectbox.Text).Ra
If Len(Trim(port)) Then
If Len(Trim(part)) Then
Partbox.AddItem Trim(part)
End If
Else
endloop = 1
End If
Loop Until endloop
Sheets(projectbox.Text).Se
Range("E2").Select
Partbox.Visible = True
PartLabel.Visible = True
Partbox.Enabled = True
Partbox.SetFocus
End Select
End Sub
Private Sub partbox_Change()
If Partbox.MatchFound Then
Portbox_STATUS (True)
End If
End Sub
Private Sub partbox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case Is = 13, Is = 9
Partbox.Text = UCase(Partbox.Text)
If Partbox.MatchFound Then
Portbox_STATUS (True)
portbox.SetFocus
Else
found = -1
For loopcount = 0 To Partbox.ListCount - 1
If Trim(Partbox.List(loopcoun
found = loopcount
End If
Next loopcount
If found >= 0 Then
Partbox.ListIndex = found
Portbox_STATUS (True)
Else
Partbox.Text = ""
Portbox_STATUS (False)
End If
End If
End Select
End Sub
Private Sub partbox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Partbox.Text = ""
End Sub
Private Sub partbox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Portbox_STATUS (False)
End Sub
I have looked at the MatchEntry properties options for the ComboBox and selecting anything other than MatchEntryNone make the program select the first match (if i hit 5 then it selects the first entry starting with a 5 and goes onto the next box).
Pls could anyone suggest anything??.
Thanks.
ASKER
Ummmm im sorry to say but most of what you just wrote sounded like:
Blahh blahh blah VB projects Blaa Blaaah.... sorry :)
I'll explain a little more....The data (partbox) is all currently in column A of an excel sheet, beside the part number in column B is a list of the relative ports on that particular part (portbox), so the user selects the project (projectbox) which moves to the correct excel sheet, then they are presented with the partbox combo box to select a part, on selecting a part they then get the portbox combo box with all the ports for their selected part.
The coding im after will/should allow the user to choose the part they require from a slightly reduced list depening on them typing in a few of the starting letters/numbers of the parts particular id number.
Hope that makes a little more sence.
Craig.
Blahh blahh blah VB projects Blaa Blaaah.... sorry :)
I'll explain a little more....The data (partbox) is all currently in column A of an excel sheet, beside the part number in column B is a list of the relative ports on that particular part (portbox), so the user selects the project (projectbox) which moves to the correct excel sheet, then they are presented with the partbox combo box to select a part, on selecting a part they then get the portbox combo box with all the ports for their selected part.
The coding im after will/should allow the user to choose the part they require from a slightly reduced list depening on them typing in a few of the starting letters/numbers of the parts particular id number.
Hope that makes a little more sence.
Craig.
IT sounds like you need to filter your list right before your additem.
If I understand your question correctly try the following.
--------------------------
x = len(partbox) 'set x equal to number of characters in partbox.
If Len(Trim(port)) Then
If Len(Trim(part)) Then
if left(part, x) = partbox.text then
Partbox.AddItem Trim(part)
end if
End If
Else
endloop = 1
End If
--------------------------
The left(part, x) should compare the first x characters of part with the text in partbox and then add item if it matches.
I see were you set Portbox_STATUS but not Partbox_STATUS?
Later...
ASKER
Thx for the idea, but what would happen if the length of the data in partbox varies from 1 to like 100??, i'm trying not to introduce possible crash situations in future use.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
like sql statements - "select * from <table> where <field1> like "5*"
or
"select * from <table> where <field1> like "59*"
and so on.
This is the way I do these types of things for my ASP and VB projects. Just a thought. Maybe you cannot in your situation but it might work for you.