How to rename or add as new vb 6 combo box

Form level variable
Dim mstrCboText As String
Combo Style 0 Dropdown combo

Private Sub cboBids_Click()
If Me.cboBids.ListIndex <> -1 Then
  mstrCboText = cboBids.Text' put the text into variable
End If
End Sub

Private Sub cboBids_LostFocus()

If Me.cboBids.ListIndex <> -1 Then
  mstrCboText <> cboBids.Text' 


End If 

If Me.cboBids.ListIndex <> -1 Then
     If mstrCboText <> cboBids.Text Then
             Select Case MsgBox("Do you want to rename mstrCboText to cboBids.Text click ""Yes""" _
                                & vbCrLf & "To add as as new Catagory click ""No""" _
                                & vbCrLf & "To cancel click""Cancel""" _
                                , vbYesNoCancel Or vbQuestion Or vbDefaultButton1, App.Title)
             
                Case vbYes
             
                Case vbNo
             
                Case vbCancel
                   cboBids.Text = mstrCboText ' put back the original text
             End Select 

End If

Open in new window


How to do the vbyes(rename) and make it selected ?
How to do the vbNo (Add as a new item and make it selected ?
isnoend2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Can you try again to explain what it is that you want to do? Are you just trying to change an item in the combobox?
0
isnoend2001Author Commented:
An existing item is selected and then typed over I am trying to either replace or add a new item and make it selected
0
Martin LissOlder than dirtCommented:
Option Explicit

Dim mstrCboText As String
Private mintLI As Integer
Private Sub Form_Load()
cboBids.AddItem "This"
cboBids.AddItem "is"
cboBids.AddItem "a"
cboBids.AddItem "test"
End Sub


Private Sub cboBids_Click()
If Me.cboBids.ListIndex <> -1 Then
    mintLI = cboBids.ListIndex
    mstrCboText = cboBids.Text ' put the text into variable
End If
End Sub

Private Sub cboBids_LostFocus()

If Me.cboBids.ListIndex <> -1 Then
  'mstrCboText <> cboBids.Text


End If


If mstrCboText <> "" Then
     If mstrCboText <> cboBids.Text Then
             Select Case MsgBox("Do you want to rename '" & mstrCboText & "' to '" & cboBids.Text & "'? " _
                                & vbCrLf & vbCrLf _
                                & "Click ""Yes"" to rename the entry" & vbCrLf _
                                & "Click ""No"" to add as a new Catagory " & vbCrLf _
                                & "Click""Cancel"" to ignore the change" _
                                , vbYesNoCancel Or vbQuestion Or vbDefaultButton1, App.Title)
             
                Case vbYes
                    cboBids.List(mintLI) = cboBids.Text
                    cboBids.ListIndex = mintLI
                Case vbNo
                    cboBids.AddItem cboBids.Text
                Case vbCancel
                   cboBids.Text = mstrCboText ' put back the original text
             End Select
    End If
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

isnoend2001Author Commented:
thanks
never realized it that after selecting an item then, typing over the name changes the listindex to -1
0
Martin LissOlder than dirtCommented:
To be honest I didn't either until I tried it. I also didn't realize that I posted my test data:) In any case I'm glad I could help.
0
isnoend2001Author Commented:
Hi martin Liss
After I use the variable mintLI
How do i reset it?
0  could be a selection
0
Martin LissOlder than dirtCommented:
You don't need to reset it since it is always set to the ListIndex of the selected entry. And I don't know if you are concerned about 0 - that only means that the first item was clicked.
0
isnoend2001Author Commented:
Thanks had a thought process going where i needed to check it's value. Don't remember what it was
I think it had something to do with  differentiate, between renaming and just adding as new
0
Martin LissOlder than dirtCommented:
If you notice, while it's always set, it's only used when renaming.
0
isnoend2001Author Commented:
Hi MartinLiss
Finally am getting to using this. In looking at the code it does not look as though
adding as new the new item is not selected. I think adding items puts them at the bottom of the list,
maybe cboBids.listindex = cboBids.listcount - 1
I will try
0
Martin LissOlder than dirtCommented:
By default new items are added at the bottom of the combobox list. You can change that behavior in two ways.

1) Set the Sorted property of the combobox to True, or
2) Use code like this Combo1.AddItem "bbb", 1 which would add "bbb" as the second item in the list.
0
isnoend2001Author Commented:
thanks martinLiss
Adding to bottom of the combobox list is ok if this will work
cboBids.listindex = cboBids.listcount - 1
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.