Solved

How to rename or add as new vb 6 combo box

Posted on 2014-10-02
12
82 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 46

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 46

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 46

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 46

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 46

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now