combobox doesn't show selected item with VBA project locked for viewing

nardagus

Active Member
Joined
Apr 23, 2012
Messages
317
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi Everyone,

I have a strange thing...

There is quite simple form with two fields:
- TextBox - this field does one thing: it shows value of selected cell
- ComboBox - this one on the other hand... When a form is initialized, excel connects to MSSQL and retrieves some data consisting of two fields: username, and username_id. Then the result is shown in CB. I use column.width to hide username_id.

For safety reasons VBA project is locked for viewing.

1588144695350.png

And for some reason locking VBA project causes problems with this CB.
When I reopen a file CB retrieves needed data (as you can see on a screenshot above). However when I click on a chosen item it doesn't show up in the field.
However. When I enter a password to unlock VBA project, CB works as intended.

Below you can see its properties:
1588145681704.png


I have no idea why this is happening...
Maybe you can help me...

Cheers
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
*update*

Ok. I found the problem.
It seems that this piece of code:

VBA Code:
Private Sub cb_handlowiec_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    With Me.cb_handlowiec
        .BackColor = RGB(255, 195, 0)
        .ShowDropButtonWhen = fmShowDropButtonWhenAlways
    End With
End Sub

caused such a behavior.
What I wanted to achieve is that when one hovers over an item (CB in this case) item background changes to orange. With user form mouse move event I changed item's background to white.
Commenting out above code fixed the problem.
However two questions remain:

1) Why combo box was working after I entered password to unlock VBA Project. I also noticed that when I remove VBA project password and reopen a file problem remains, but when I change anything in the code, CB works as it should
2) How to make this code work. I'd like to use cb_handlowiec_MouseMove event.
 
Upvote 0
*update2*

Ok. I added a condition to above code. I'm checking if ShowDropButtonWhen = fmShowDropButtonWhenAlways. And it seems to solve the problem.

VBA Code:
Private Sub cb_handlowiec_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    With Me.cb_handlowiec
        If .ShowDropButtonWhen <> fmShowDropButtonWhenAlways Then
            .BackColor = RGB(255, 195, 0)
            .ShowDropButtonWhen = fmShowDropButtonWhenAlways
        End If
    End With
End Sub

Still it doesn't answer first question from last post, but it works now. ;)
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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