ComboxBox Does not Save Value

bharatvly

Board Regular
Joined
Jun 3, 2014
Messages
61
Hello Folks,

I have below code and it works absolutely perfect. However, I have one minor issue and I've been racking my head on it to fix it. What below code does is, it retrieves the ComboBox list from Access database. However, when I select any item from the list, the drop down closes and It doesn't display the selection in ComboBox.Value. You know what I mean?

When I open the dropdown it again retrieves the list which is right but doesn't save the selection in Combobox.Value. Please help!

Private Sub ComboBox4_DropButt*******()

cnn.Open "Provider = Microsoft.ACE.oledb.12.0; data source= " & ThisWorkbook.Path & "\" & "Database_SDET.accdb" & ";Jet OLEDB:Database Password=L@stMinute14;"
Qry = "SELECT [Full_Name] FROM Login_Details"
rst.Open Qry, cnn, adOpenKeyset, adLockOptimistic

rst.MoveFirst
With Admin_Page.ComboBox4
.Clear
Do
.AddItem rst![Full_Name]
rst.MoveNext
Loop Until rst.EOF
End With

rst.Close
cnn.Close

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I think you will find that the event fires again when the user makes a selection. Does this work for you?

Rich (BB code):
Dim Dropped As Boolean

Private Sub ComboBox4_DropButt*******()
    Dropped = Not Dropped
    If Dropped = True Then
        cnn.Open "Provider = Microsoft.ACE.oledb.12.0; data source= " & ThisWorkbook.Path & "\" & "Database_SDET.accdb" & ";Jet OLEDB:Database Password=L@stMinute14;"
        Qry = "SELECT [Full_Name] FROM Login_Details"
        rst.Open Qry, cnn, adOpenKeyset, adLockOptimistic
    
        rst.MoveFirst
        With Admin_Page.ComboBox4
            .Clear
            Do
                .AddItem rst![Full_Name]
                rst.MoveNext
            Loop Until rst.EOF
        End With
    
        rst.Close
        cnn.Close
    End If
End Sub
 
Upvote 0
Nope! It isn't working. I make the selection from the dropdown but it does not save the selection in Combobox's value!
 
Upvote 0
Nope! It isn't working. I make the selection from the dropdown but it does not save the selection in Combobox's value!

The code I posted worked when I tested it. The event occurs whenever the drop-down list appears or disappears. The Boolean variable should prevent the latter.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,973
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top