Unselect Listbox value if user selects NO to Msgbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
I am using the code below.

I make a selection from my ComboBox which then populates the Listbox.
Normally when i then make a Listbox select i would say YES to the Msgbox that has just popped up.

Occioanly the user would be selecting NO of which the closes the Msgbox.
Now at this point the Listbox selection is still in a select state / blue in color,see screenshot

Please advise what code i need to add so when the MsgBox is closed the Listbox value isnt selected.
I did try this but nothing happed,so i assume its wrong

Rich (BB code):
ListBox1.Selected(ListBox1.ListIndex) = False
Thanks

Rich (BB code):
Private Sub ListBox1_Click()
    Dim rw          As Long
    Dim answer      As VbMsgBoxResult
   
    With Me.ListBox1
        'get database row number
        rw = Val(.Column(.ColumnCount - 1, .ListIndex))
        If rw = 0 Then Exit Sub
    End With
   
    With wsDatabase
        .Activate
        .Range("A" & rw).Select
    End With
   
    answer = MsgBox("OPEN CUSTOMERS FILE IN MAIN DATABASE ?", vbYesNo + vbInformation, "OPEN Database MESSAGE")
    If answer = vbYes Then
      Unload ProgrammerForm
      Database.LoadData Sheets("DATABASE"), Selection.Row
       
    Else
   
   
    End If
   
End Sub
 

Attachments

  • EaseUS_2023_07_14_21_24_44.jpg
    EaseUS_2023_07_14_21_24_44.jpg
    21 KB · Views: 6

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If you don't mind switching from the Click event to the doubleclick event, use the following code and delete your code.

VBA Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim rw          As Long
    Dim answer      As VbMsgBoxResult
    
    With Me.ListBox1
        'get database row number
        rw = Val(.Column(.ColumnCount - 1, .ListIndex))
        If rw = 0 Then Exit Sub
    End With
    
    With wsDatabase
        .Activate
        .Range("A" & rw).Select
    End With
    
    answer = MsgBox("OPEN CUSTOMERS FILE IN MAIN DATABASE ?", vbYesNo + vbInformation, "OPEN Database MESSAGE")
    If answer = vbYes Then
        Unload ProgrammerForm
        Database.LoadData Sheets("DATABASE"), Selection.Row
    Else
        ListBox1.Selected(ListBox1.ListIndex) = False
    End If
End Sub
 
Upvote 0
Solution
Thanks will give it a try tomorrow.

Would you mind taking a look at my other post.

Have a nice day.
 
Upvote 0
Hi,
I added this line of code to mine & it works even without using the double click.

Rich (BB code):
ListBox1.Selected(ListBox1.ListIndex) = False
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,114
Members
453,021
Latest member
Justyna P

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