Solved

How to rename or add as new vb 6 combo box

Posted on 2014-10-02
12
79 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
  • 6
  • 6
12 Comments
 
LVL 45

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 45

Accepted Solution

by:
Martin Liss earned 500 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
 

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 45

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 45

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 45

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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now