Solved Combo box Dropdown and Got Focus highlight field with colour (1 Viewer)

lacampeona

Registered User.
Local time
Today, 07:31
Joined
Dec 28, 2015
Messages
392
Hello experts
I have strange situation.
I want that when user click into combox, combox automaticly display the values and highlight the combobox with specific colour.

My problems now is that the combox contanins the colour but dropdown is not working?

I have two modules: one modul on the On Open event and one modul on Load form event.

I am sure that this two modules are "fighting" and becouse that one modul is working and the second no?
Maybe someone can explain me what I can do?

I want that both modules become "friends" and show me the dropdown and the colour.

I am attaching a sample database to show my problem.

Thank is advance
 

Attachments

  • DbProblemA.accdb
    544 KB · Views: 83

Eugene-LS

Registered User.
Local time
Today, 08:31
Joined
Dec 7, 2018
Messages
481
My problems now is that the combox contanins the colour but dropdown is not working?
Take a look on example below please.
ComboBoxes dropdown only if it has no value.
 

Attachments

  • DbProblemA_v02.zip
    27.3 KB · Views: 103

lacampeona

Registered User.
Local time
Today, 07:31
Joined
Dec 28, 2015
Messages
392
Hi Eugene
thanks for your solution.

About got and lost focus I was already trying something but I wanted that this two modules do that automaticly.
becouse i have a lot of comboboxes and a lot of forms...

If someone will know the solution I will be happy if no then I will have to make one by one like your example.
thank you very much.
 

Eugene-LS

Registered User.
Local time
Today, 08:31
Joined
Dec 7, 2018
Messages
481
I was already trying something but I wanted that this two modules do that automaticly.
I'm working on that ...

Try the example below
 

Attachments

  • DbProblemA_v03.zip
    27.6 KB · Views: 88
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 01:31
Joined
May 21, 2018
Messages
8,529
A class for this is a little overkill.
Simply build this function in a standard module

Code:
Public Function FocusInOut(bGotFocus As Boolean)
Dim ctrlComboBox As ComboBox
    Set ctrlComboBox = Me.ActiveControl
    If bGotFocus = True Then
        ctrlComboBox.ForeColor = Me.txtGotGocus.ForeColor
        ctrlComboBox.BackColor = Me.txtGotGocus.BackColor
        ctrlComboBox.BorderColor = Me.txtGotGocus.BorderColor
        If ctrlComboBox.Text = "" Then ctrlComboBox.Dropdown
    Else
        ctrlComboBox.ForeColor = Me.txtLostGocus.ForeColor
        ctrlComboBox.BackColor = Me.txtLostGocus.BackColor
        ctrlComboBox.BorderColor = Me.txtLostGocus.BorderColor
    End If
    Set ctrlComboBox = Nothing
End Function


Now in any combobox on any form in the event procedures for gotfocus and lostfocust
onGotFocus: =FocusInOut(True)
onLostFocus: =FocusInOut(False)
 

Eugene-LS

Registered User.
Local time
Today, 08:31
Joined
Dec 7, 2018
Messages
481
Simply build this function in a standard module
You forgot Me.... statment! :)

Code:
Public Function FocusInOut(bGotFocus As Boolean)
'Now in any combobox on any form in the event procedures for gotfocus and lostfocust
'   onGotFocus: =FocusInOut(True)
'   onLostFocus: =FocusInOut(False)
'-----------------------------------------------------------------------------------
'Colors:
Const GFForeColor& = 1643706    'Red
Const GFBackColor& = 13952764   'Light Rose
Const GFBorderColor& = 1643706  'Red
Const LFForeColor& = 4210752    'Standart
Const LFBackColor& = 16777215   'Standart
Const LFBorderColor& = 10921638 'Standart
'Objects:
Dim ctrlComboBox As ComboBox
Dim frm As Form
  
    Set frm = Screen.ActiveForm
    Set ctrlComboBox = frm.ActiveControl
  
    If bGotFocus = True Then
        ctrlComboBox.ForeColor = GFForeColor
        ctrlComboBox.BackColor = GFBackColor
        ctrlComboBox.BorderColor = GFBorderColor
        If ctrlComboBox.Text = "" Then ctrlComboBox.Dropdown
    Else
        ctrlComboBox.ForeColor = LFForeColor
        ctrlComboBox.BackColor = LFBackColor
        ctrlComboBox.BorderColor = LFBorderColor
    End If
  
    Set ctrlComboBox = Nothing
    Set frm = Nothing

End Function
 

Attachments

  • DbProblemA_v04.zip
    27.8 KB · Views: 93
Last edited:

lacampeona

Registered User.
Local time
Today, 07:31
Joined
Dec 28, 2015
Messages
392
Hello experts
very very good. Thank you.
Yes that was what I need it.
Thank you very much. :)
 

Users who are viewing this thread

Top Bottom