If not in combo list, then add to the list 
Author Message
 If not in combo list, then add to the list

hi
I have a combo box (not bound, i coded it myself) which
lists the towns from one of my tables.
this table (tblALLtowns) contains the fields "townID"
and "townname"

What i would like to do is to have the combo box to act
like a Memery of towns. SO when a user is typing in the
town name and the town name is already in the combo box,
then it will auto expand the town name and if the user
hits enter it will select the whole town name.
e.g.  
user puts in "Fl" and a match "fleet" comes out

i know that this is easy to do in access simply selecting
the auto expand property. But i have no clue how to do it
in Visual Basic 6.0.

ALSO

the second part to my problem is that if the town is not
in the list (the memory so to speak) i would i like to
make it  so that when then hit enter, the town is
permanently put into the combo.

this is possible in access 2002. so i imageon that visual
basic should be able to do it SOMEHOW.

thanks for any help

-james



Tue, 26 Apr 2005 06:38:18 GMT  
 If not in combo list, then add to the list
Here's the logic for is it in the list?

For X = 0 To Combo1.ListCount-1
    If Combo1.list(x) = Combo1.Text Then Goto onlist
Next X

Combo1.Additem Combo1.Text

onlist:

On the keypress event for the combobox:

For X = 0 To Combo1.ListCount -1

If Pos = instr(Combo1.List(x), Combo1.Text) Then Combo1.Text =
Combo1.List(x):Exit For

Next

HTH


Quote:
> hi
> I have a combo box (not bound, i coded it myself) which
> lists the towns from one of my tables.
> this table (tblALLtowns) contains the fields "townID"
> and "townname"

> What i would like to do is to have the combo box to act
> like a Memery of towns. SO when a user is typing in the
> town name and the town name is already in the combo box,
> then it will auto expand the town name and if the user
> hits enter it will select the whole town name.
> e.g.
> user puts in "Fl" and a match "fleet" comes out

> i know that this is easy to do in access simply selecting
> the auto expand property. But i have no clue how to do it
> in visual basic 6.0.

> ALSO

> the second part to my problem is that if the town is not
> in the list (the memory so to speak) i would i like to
> make it  so that when then hit enter, the town is
> permanently put into the combo.

> this is possible in access 2002. so i imageon that visual
> basic should be able to do it SOMEHOW.

> thanks for any help

> -james




Tue, 26 Apr 2005 12:45:57 GMT  
 If not in combo list, then add to the list
hmm
im finding it hard to construct any sort of code from that
Quote:
>-----Original Message-----
>Here's the logic for is it in the list?

>For X = 0 To Combo1.ListCount-1
>    If Combo1.list(x) = Combo1.Text Then Goto onlist
>Next X

>Combo1.Additem Combo1.Text

>onlist:

>On the keypress event for the combobox:

>For X = 0 To Combo1.ListCount -1

>If Pos = instr(Combo1.List(x), Combo1.Text) Then
Combo1.Text =
>Combo1.List(x):Exit For

>Next

>HTH



>> hi
>> I have a combo box (not bound, i coded it myself) which
>> lists the towns from one of my tables.
>> this table (tblALLtowns) contains the fields "townID"
>> and "townname"

>> What i would like to do is to have the combo box to act
>> like a Memery of towns. SO when a user is typing in the
>> town name and the town name is already in the combo
box,
>> then it will auto expand the town name and if the user
>> hits enter it will select the whole town name.
>> e.g.
>> user puts in "Fl" and a match "fleet" comes out

>> i know that this is easy to do in access simply
selecting
>> the auto expand property. But i have no clue how to do
it
>> in visual basic 6.0.

>> ALSO

>> the second part to my problem is that if the town is
not
>> in the list (the memory so to speak) i would i like to
>> make it  so that when then hit enter, the town is
>> permanently put into the combo.

>> this is possible in access 2002. so i imageon that
visual
>> basic should be able to do it SOMEHOW.

>> thanks for any help

>> -james

>.



Tue, 26 Apr 2005 23:15:39 GMT  
 If not in combo list, then add to the list
Goto?? AHHHHHH!!!! Just messing with you Richard. James, here's a
clarification for you, minus the Goto.

Private Function IsInList(ByRef cbx as ComboBox, ByVal NewValue as String)
as Boolean
  For X = 0 To cbx.ListCount-1
    If cbx.list(x) = NewValue Then
      IsInList = True
      Exit Function
    End If
  Next X
End Sub

Private Sub AddNewTown(ByRef cbx as ComboBox, ByVal NewValue as String)
  ''''''Insert Code here to save it to your database

  cbx..Additem Combo1.Text  'Adds Town to the list
End Sub

Private Sub Combo1_KeyPress(keyascii As Integer)
  Dim X as Integer

  If keyascii = vbKeyEnter Then
    For X = 0 To Combo1.ListCount -1
      If Left(Combo1.List(X), Len(Combo1,Text)) = Combo1.Text Then
         Combo1.Text = Combo1.List(x)
         Exit For
      End If
    Next X
  Else
     If Not IsInList(Combo1, Combo1.Text) Then Call AddNewTown(Combo1,
Combo1.Text)
  End If
End Sub

There it is on a silver platter...



Wed, 27 Apr 2005 03:33:20 GMT  
 If not in combo list, then add to the list
wow you legend
im gunna give this a go!


Wed, 27 Apr 2005 06:22:37 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Adding the alphabet in a list box or combo list

2. Fill Combo List using Criteria selected in another Combo List

3. Fill Combo List using Criteria selected in another Combo List

4. Add-ins not listing in add-in manager

5. Listing all tables or queries in a list/combo box

6. How to list macro names in a combo box or a list box

7. How to list macro names in a combo box or a list

8. How to list macro names in a combo box or a list

9. Rebuild select list for combo/list box

10. Use list from excel or access to populate combo/list box

11. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

12. Updating a combo box list W/limit to list selected

 

 
Powered by phpBB® Forum Software