Solved Copy the background color to the hover color (1 Viewer)

zelarra821

Registered User.
Local time
Today, 07:47
Joined
Jan 14, 2019
Messages
803
Hi. I would like to know if it is possible to copy, through VBA, the background color of a button, to hover color.

I explain why. When I import a database, I change the color that I have customized for the buttons. This, from what I have been able to appreciate, is because I change the Use theme property, from Yes to No. I have found a code that changes that property to Yes in all the buttons of the forms. That's why I ask you if, in this code, you could add so that you copy the value of the property of the bottom of the button, to the property of the hover.

I leave the code, in case someone serves for something:

Code:
Private Sub UsarTema_Click()
    Dim strForm As String, db As DAO.Database
Dim doc As DAO.Document
Dim F As Object

Set db = CurrentDb

For Each doc In db.Containers("Forms").Documents
strForm = doc.Name

DoCmd.OpenForm strForm, acDesign
Set F = Access.Forms(doc.Name)
   Dim ctl As Control
   For Each ctl In F
           If ctl.ControlType = acCommandButton Then
               If ctl.UseTheme = False Then
                   ctl.UseTheme = True
               End If
           End If
   Next ctl
   Set ctl = Nothing
   DoCmd.Close acForm, strForm, acSaveYes
Next doc
Set doc = Nothing
Set db = Nothing
End Sub

Thank you.
 

isladogs

MVP / VIP
Local time
Today, 06:47
Joined
Jan 14, 2017
Messages
18,186
Code:
ctl.HoverColor=ctl.BackColor
 

zelarra821

Registered User.
Local time
Today, 07:47
Joined
Jan 14, 2019
Messages
803
Hi. Thank you. However, it does not work.

Look, although it is in Spanish, but by position it can be useful to know what is to be changed. They are the two that I have inside a box, for the one that is higher up.
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    104.2 KB · Views: 141

isladogs

MVP / VIP
Local time
Today, 06:47
Joined
Jan 14, 2017
Messages
18,186
I have to say I'm a bit confused by what you are doing

When I import a database...I change the Use theme property, from Yes to No
OK so you switch off use themes

..then you turn the themes back on for buttons
Code:
 If ctl.ControlType = acCommandButton Then
               If ctl.UseTheme = False Then
                   ctl.UseTheme = True
               End If
           End If

.... so why switch the themes off in the first place?

Next your screenshot indicates you want to change the hover color AND the pressed color to be the same as the back color
...in other words you want to get rid of much of the functionality in the theme!

Very confusing!

I had tested this code before I posted on a single form. I'm not going to try it on a complete application of my own
Code:
ctl.HoverColor=ctl.BackColor
This also works
Code:
ctl.PressedColor=ctl.BackColor

However if you run these using an open form, the settings in the property sheet won't change as you can't save design changes in form view

The attached app contains code to do what you want both in the form & separately in a module
Clicking the Reset Theme button on the form will make changes temporarily but these will be lost on saving ...even though you will be asked to save.
However, run the code from the module and its permanently saved

Hope that makes sense
 

Attachments

  • Zelarra test.zip
    27.9 KB · Views: 98
Last edited:

zelarra821

Registered User.
Local time
Today, 07:47
Joined
Jan 14, 2019
Messages
803
Hello thank you very much. Now it works. I was putting it inside the if, and of course, if the UseTheme was already in Yes, I did not see the effect.

There has been a translation error. What I wanted to say is that, when I import the database into a new one, Access changes the UseTheme, and puts it as No. Then, I've searched for a system to put it back to Yes on all the buttons I have in the forms. What happens is that the color of the button when you mouse over was not the one I wanted, hence I asked you how to fix it.
 

isladogs

MVP / VIP
Local time
Today, 06:47
Joined
Jan 14, 2017
Messages
18,186
Glad I could help.
Just out of interest, why do you export the database into a new one?
Have you tried the opposite? Create a new blank database and import all objects into that?
 

zelarra821

Registered User.
Local time
Today, 07:47
Joined
Jan 14, 2019
Messages
803
That's what I do. I create a new blank database and import all objects into that. I didn't explay well. Sorry.

I do it because my database is corrupt, but I doesn't work
 

isladogs

MVP / VIP
Local time
Today, 06:47
Joined
Jan 14, 2017
Messages
18,186
Creating a new clean database should be treated as a last resort. Before doing that you should try compacting and then decompiling.
If its happening a lot, you should investigate the causes and deal with them.
I'm still unclear when importing items would affect the theme ...unless that's a corruption issue?

Anyway, Good luck with your project
 

Users who are viewing this thread

Top Bottom