VBA Combo Box autocomplete issue

MistakesWereMade

Board Regular
Joined
May 22, 2019
Messages
103
I have a script for my a combobox that is in a userform (GUI). The combo box uses a formula called "DropDownList" that I made to enable a particular type of autocomplete feature to my combo box.

My program works as follows: After I start typing in the combo box and it narrows down my search, I click on the option I want and then press a command button "search" to find and open a file in a folder. When I go to the combo box again to type in a new selection, this is when my program bugs out. I also am not able to close out of the excel file that opens after I "search". I have to manually do it by force closing. I think this has something to do with it.

I've attached pictures and part of my code. Any help would be much appreciated as I just cannot figure it out.

x3BDXn9
x3BDXn9
sqm5pt.png


2m3p949.png


Code:
Dim DisableCb As Boolean


Private Sub CommandButton2_Click()


    Dim Wbk As Workbook
    Dim Pth As String
   
    Pth = Environ("Userprofile") & "\Desktop\My Files\"


    DisableCb = True


    On Error Resume Next


    Set Wbk = Workbooks.Open(Pth & Me.ComboBox1.Value)
   
    On Error GoTo 0
   
    If Wbk Is Nothing Then
        MsgBox "Workbook not found."
    End If
    
    ComboBox1.Value = ""
    
    If ComboBox1.Value = "" Then
        Dim myRange As Range
        Set myRange = ThisWorkbook.Worksheets("Data").Range("E2")
        myRange.Clear
    End If
    
    DisableCb = False


End Sub


Private Sub ComboBox1_Change()


    If DisableCb Then Exit Sub
    
    ComboBox1.RowSource = "DropDownList"
    Me.ComboBox1.DropDown
    
    Sheets("Data").Range("E2") = Me.ComboBox1.Value
    
End Sub
 
I'm not totally sure how it works, but this ShowModal Property literally fixed my entire problem. THANKS! You really helped a lot. I appreciate it Dante!
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,213,551
Messages
6,114,267
Members
448,558
Latest member
aivin

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