Solved Buttons color (1 Viewer)

zelarra821

Registered User.
Local time
Today, 17:17
Joined
Jan 14, 2019
Messages
813
Hello. I have a problem with the layout of the buttons. The fact is that I want to put the default by the Access theme through VBA (background color Emphasis 1, Lighter 40%, and text color Text 1, Lighter 25%). I attach a screenshot of the one I want to put. If I put the blue that it tells me, it comes out darker than it should. There must be some property that I don't know that establishes all that without having to enter background color, relief, text color... Let's see if someone can guide me. Thank you so much.
 

Attachments

  • ScreenShot002.jpg
    ScreenShot002.jpg
    517.1 KB · Views: 80

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:17
Joined
May 7, 2009
Messages
19,245
color values are Long integer.
so on the Load event of your sample form, save the color of the "blue" object.
to test:

private sub form_load()
msgbox me.theObject.BackColor
end sub

the number will ne shown in msgbox.
 

zelarra821

Registered User.
Local time
Today, 17:17
Joined
Jan 14, 2019
Messages
813
Thank you very much for your input. Seeing what you propose, it occurred to me to list all the button properties, and paste them into the procedure I use to set the layout, but it doesn't work: it changes the layout, yes, but not to the one I want. There must be some property that is passed to use. Then, I've tried to tag the buttons: there's one that has images that I don't want to touch (I've named them "Images" in the tag property); and the rest, when the checkbox is at -1 I pass it to the "UseTheme" tag, and when it is at 0, "NoUseTheme". I have verified that it takes the tag property well, and it works only halfway, because when it has to apply the format to it when it is at -1, it is as if it kept the old format. Therefore, I wanted to ask if there is a way to delete or copy the format from one Button to another, via VBA.
 

zelarra821

Registered User.
Local time
Today, 17:17
Joined
Jan 14, 2019
Messages
813
In the end I saved it in another way:

With this function, I set the Tag property, where I say which ones will be custom formatted and which ones won't.

Code:
Sub AsignarEtiquetaUsarTema(FName As Form)
    On Error GoTo err_lbl
    Dim Control As Access.Control
    Dim UsarTema As Boolean
   
    UsarTema = DLookup("UsarTema", "T00Configuracion")
   
    For Each Control In FName.Controls
        If Not Control.Tag = "Imagen" Then
            If UsarTema = False Then
                If Control.controlType = acCommandButton Then Control.Tag = "NoUsarTema"
                If Control.controlType = acToggleButton Then Control.Tag = "NoUsarTema"
            Else
                If Control.controlType = acCommandButton Then Control.Tag = "UsarTema"
                If Control.controlType = acToggleButton Then Control.Tag = "UsarTema"
            End If
        End If
    Next
    Set Control = Nothing
Salida:
    Exit Sub
err_lbl:
    Select Case Err.Number
        Case 438, 2462
            Resume Next
        Case Else
            MsgBox "Ha ocurrido el siguiente error" & vbCrLf & vbCrLf & _
                   "Número de error: " & Err.Number & vbCrLf & _
                   "Origen del error: AsignarEtiquetaUsarTema_mdlConfiguracion" & vbCrLf & _
                   "Descripción del error: " & Err.Description & _
                   Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Nº de línea: " & Erl) _
                   , vbInformation, NombreBD
            Resume Salida
    End Select
End Sub

Then I have a procedure for formatting, which is long to put here, but what I've done is add this:

Code:
    '****** DAR FORMATO AL TEXTO DE LAS ETIQUETAS Y BOTONES ******
   
    Dim ColorFondoBotonesRed As Double
    Dim ColorFondoBotonesGreen As Double
    Dim ColorFondoBotonesBlue As Double
    Dim ColorTextoBotonesRed As Double
    Dim ColorTextoBotonesGreen As Double
    Dim ColorTextoBotonesBlue As Double
   
    ColorFondoBotonesRed = DLookup("ColorFondoBotonesRed", "T00Configuracion")
    ColorFondoBotonesGreen = DLookup("ColorFondoBotonesGreen", "T00Configuracion")
    ColorFondoBotonesBlue = DLookup("ColorFondoBotonesBlue", "T00Configuracion")
    ColorTextoBotonesRed = DLookup("ColorTextoBotonesRed", "T00Configuracion")
    ColorTextoBotonesGreen = DLookup("ColorTextoBotonesGreen", "T00Configuracion")
    ColorTextoBotonesBlue = DLookup("ColorTextoBotonesBlue", "T00Configuracion")
   
    Dim Control As Access.Control
    For Each Control In FName.Controls
    Select Case Control.controlType
        Case acLabel
            If Control.Tag = "Titulo" Then
                Control.BackColor = RGB(ColorFondoTituloRed, ColorFondoTituloGreen, ColorFondoTituloBlue)
                Control.BackStyle = 1
                Control.ForeColor = RGB(ColorTextoTituloRed, ColorTextoTituloGreen, ColorTextoTituloBlue)
                Control.FontName = "Montserrat"
                Control.FontSize = 20
                Control.TextAlign = 2
                Control.FontBold = True
            ElseIf Control.Tag = "Subtitulo1" Then
                Control.BackColor = RGB(ColorFondoTituloRed, ColorFondoTituloGreen, ColorFondoTituloBlue)
                Control.BackStyle = 1
                Control.ForeColor = RGB(ColorTextoTituloRed, ColorTextoTituloGreen, ColorTextoTituloBlue)
                Control.FontName = "Montserrat"
                Control.FontSize = 14
                Control.FontBold = True
            ElseIf Control.Tag = "Subtitulo2" Then
                Control.ForeColor = RGB(255, 255, 255)
            Else
                Control.ForeColor = RGB(ColorTextoRed, ColorTextoGreen, ColorTextoBlue)
            End If
        Case acCommandButton, acToggleButton
            Select Case Control.Tag
                Case "NoUsarTema"
                    Control.UseTheme = True
                    Control.BackColor = RGB(ColorFondoBotonesRed, ColorFondoBotonesGreen, ColorFondoBotonesBlue)
                    Control.BorderColor = RGB(ColorFondoBotonesRed, ColorFondoBotonesGreen, ColorFondoBotonesBlue)
                    Control.ForeColor = RGB(ColorTextoBotonesRed, ColorTextoBotonesGreen, ColorTextoBotonesBlue)
                    Control.FontBold = True
                    Control.HoverColor = Control.BackColor
                    Control.PressedColor = Control.BackColor
                    Control.HoverForeColor = Control.ForeColor
                    Control.PressedForeColor = Control.ForeColor
            End Select
    End Select
    Next Control
    Set Control = Nothing

And finally, add another procedure that, when the custom theme needs to be used, opens all the forms and applies the default theme.

Code:
Sub UsarTema()
    On Error GoTo err_lbl
    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
    If Not strForm = "F00Wait" Then
    DoCmd.OpenForm strForm, acDesign, , , , acHidden
    Set f = Access.Forms(doc.Name)
       Forms(doc.Name).ShortcutMenuBar = ""
       Dim ctl As Control
       For Each ctl In f
               If ctl.controlType = acCommandButton Then
                   If ctl.UseTheme = False Then
                       ctl.UseTheme = True
                       ctl.HoverColor = ctl.BackColor
                       ctl.PressedColor = ctl.BackColor
                       ctl.HoverForeColor = ctl.ForeColor
                       ctl.PressedForeColor = ctl.ForeColor
                   Else
                       ctl.HoverColor = ctl.BackColor
                       ctl.PressedColor = ctl.BackColor
                       ctl.HoverForeColor = ctl.ForeColor
                       ctl.PressedForeColor = ctl.ForeColor
                   End If
               End If
       Next ctl
       Set ctl = Nothing
       DoCmd.Close acForm, strForm, acSaveYes
    End If
    Next doc
    Set doc = Nothing
    Set DB = Nothing
Salida:
    Exit Sub
err_lbl:
    MsgBox "UsarTema_Click: " & Err.Number & " " & Err.Description, vbInformation, NombreBD
    Resume Salida
End Sub

The only thing is to call the functions in the click event of the checkbox, with a Me.Requery when using a custom style to apply it; and in the Form_Current event, so that it loads it when starting the form.

The only thing I don't like about this system is that the form's property sheet is intuited, but hey, what can we do?
 

Users who are viewing this thread

Top Bottom