Microsoft Access code samples

Click Here to return to the main MVCT page.

Bookmark and Share


Ever wanted to change the color of a tab on a Microsoft Access TabControl? Ever been frustrated by that? I have. So below I am posting the simplest method I know for programmatically displaying a different color for the body section of a Tab Control.


    Sub SetTabBackground(ByRef AccessTab As Access.TabControl, _
        ByRef AccessRectangle As Access.Rectangle, ByVal BackgroundColor As Long, _
        ByRef AccessApp As Access.Application)

        ' A MUCH more elegant solution would be to create the rectangle on the
        ' fly as needed, however this is not supported in Access 2003
        Dim tX As Long
        Dim tY As Long

        tX = Screen.TwipsPerPixelX() ' TwipsPerPixelX Only works in VB5/6
        tY = Screen.TwipsPerPixelY()

        If AccessApp.GetOption("Themed Form Controls") = 0 Then
            AccessTab.BackStyle = 0 ' transparent
            AccessRectangle.BackColor = BackgroundColor ' Window Background System Color
            AccessRectangle.BackStyle = 1 ' solid
            AccessRectangle.SpecialEffect = 0 ' raised
            AccessRectangle.Left = AccessTab.Left + (1 * tX)
            AccessRectangle.Top = AccessTab.Top + (21 * tY)
            AccessRectangle.Width = AccessTab.Width - (3 * tX)
            AccessRectangle.Height = AccessTab.Height - (23 * tY)
        Else
            Err.Raise vbObjectError + 514, "clsTabControlColors.SetTabBackground", _
                "Themed Form Controls are enabled. SetTabBackground cannot modify " & _                 "the background color of the tab when Themed Form Controls is enabled."
        End If

    End Sub

The best way to use this is to create an ActiveX DLL project using VB5 or VB6. Using Visual Studio .Net to accomplish this will only cause you more headaches since .Net does not easily accommodate being called from a COM compliant (unmanaged) application.

Download the code for this here: AccessTC.zip. By downloading this code, you agree to use it solely at your own risk. I provide no warranty express or implied for this code.



I can be reached via email to mvernon@mvct.ca. If I don't reply it's because either my spam filter took care of you, or I'm really busy. Either way, please accept my apologies in advance.


Whats the velocity of a sheep in a vacuum? Click here to find out!


 



You are visitor 2728 of 2728. Your IP Address is 38.107.191.83
This is your first visit!