?
Solved

How to rename or add as new vb 6 combo box

Posted on 2014-10-02
12
Medium Priority
?
87 Views
Last Modified: 2014-10-06
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 ?
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40357075
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
 

Author Comment

by:isnoend2001
ID: 40357306
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
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 40357491
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:isnoend2001
ID: 40357589
thanks
never realized it that after selecting an item then, typing over the name changes the listindex to -1
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40357724
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
 

Author Comment

by:isnoend2001
ID: 40358440
Hi martin Liss
After I use the variable mintLI
How do i reset it?
0  could be a selection
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40358447
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
 

Author Comment

by:isnoend2001
ID: 40358486
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
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40358487
If you notice, while it's always set, it's only used when renaming.
0
 

Author Comment

by:isnoend2001
ID: 40365101
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
 
LVL 49

Expert Comment

by:Martin Liss
ID: 40365106
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
 

Author Comment

by:isnoend2001
ID: 40365126
thanks martinLiss
Adding to bottom of the combobox list is ok if this will work
cboBids.listindex = cboBids.listcount - 1
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question