MS-Access Form/Report Design Tools are very easy to use and needs only little practice to master them. But creating controls like the image given above manually is very difficult, but it can be done manually too. You can do it with five identical labels by arranging one over the other, the top most one with font color red and others in white. The four labels with white color must be moved, each one about one pixel distance, to four corners of the topmost label with red color.
But, arranging all the labels properly in the right places, without distortion of the style, is not that easy to do manually. The above red colored (you can customize the color later) heading text with white borders can be created in seconds with the user-defined Function given below, by automating the technique I have explained above.
Copy and Paste the VBA Code given below in a Global Module in your Database.
Public Function Border2D(ByVal intForeColor As Integer, _ ByVal intBorderColor As Integer, Optional ByVal Label0Text1 As Integer) As String '------------------------------------------------------------ 'Author : a.p.r. pillai 'Date : September 2006 '------------------------------------------------------------ Dim intlbls As Integer Dim j As Integer, ForeColor As Long, BorderColor As Long Dim lblName() As String, X As Integer, mySection As Section Dim l As Long, t As Long, intFSize As Integer On Error Resume Next Border2D = FormTxtLabels(Label0Text1) Set mySection = MyFrm.Section(acDetail) intlbls = mySection.Controls.Count - 1 On Error GoTo Border2D_Err X = Validate_Dup(MyFrm, 5) ' check type and duplicate If X = 1 Then Exit Function End If intlbls = mySection.Controls.Count - 1 X = intForeColor intForeColor = IIf(X < 0, 0, IIf(X > 15, 15, intForeColor)) X = intBorderColor intBorderColor = IIf(X < 0, 0, IIf(X > 15, 15, intBorderColor)) ReDim lblName(0 To intlbls) As String ForeColor = QBColor(intForeColor) BorderColor = QBColor(intBorderColor) For j = 0 To intlbls lblName(j) = mySection.Controls(j).NAME Next For j = 0 To intlbls With mySection.Controls(lblName(j)) .Height = lngheight .Width = lngWidth .FontName = "Times New Roman" intFSize = .FontSize If intFSize < intFontSize Then .FontSize = intFontSize End If .FontUnderline = False .TextAlign = intTextAlign .BackStyle = intBackStyle End With Next mySection.Controls(lblName(intlbls)) .ForeColor = ForeColor For j = 0 To intlbls - 1 mySection.Controls(lblName(j)).ForeColor = BorderColor Next l = intX: t = intY With mySection.Controls(lblName(4)) .Left = l .Top = t End With For j = 0 To intlbls - 1 With mySection.Controls(lblName(j)) If j = 0 Or j = 3 Then .Left = l - LngI If j = 1 Or j = 2 Then .Left = l + LngI If j = 0 Or j = 1 Then .Top = t If j = 1 Then .Top = t - (0.0104 * 1440) If j = 0 Then .Top = t + (0.0104 * 1440) If j = 2 Then .Top = t + LngI If j = 3 Then .Top = t - LngI End With Next MsgLabel Border2D_Exit: Exit Function Border2D_Err: MsgBox Err.Description,, "Border2D" Resume Border2D_Exit End Function
Note : Before Running this Function ensure that the essential Library files, which I have mentioned in my earlier Article Command-Button Animation, are linked to your Project. The Main Programs given under the Topic Create 3D-Headings on Forms are also required here. Copy and paste those Programs into a Global Module in your Project, if it is not already done earlier.
The above Function will create a new Form and will design the heading text on it in seconds. You can copy & paste it anywhere on Forms or Reports you like and customize it with required text, text-size, color, text in bold or italics.
Open the VBA Module Window (if not already open) by pressing Alt+F11 then press Ctrl+G to open the Immediate Window (Debug window).
Command Syntax:
Border2D TextForeColor, TextBorderColor, LabelorText
Type the following and press Enter Key in the Debug Window:
Border2D 4,15,0
If you prefer to run the program with a Command Button click Event Procedure, then you must use text boxes on the Form to set the parameter values for the function and use references of the text boxes in command parameters.
Example:
Private Sub cmdBorder2D_Click() Border2D Me![txtForeColor], Me![txtBorderColor],0 End Sub
The first two Parameter values are for Text Fore-Color and Border Color respectively (Value Range is 0 – 15). The 3rd parameter value 0 will create a Label based design and 1 will create a Tex box based design. The third parameter value is optional, when omitted it will create a Label based design by default.
QBColor | Description | QBColor | Description |
---|---|---|---|
0 | Black | 8 | Gray |
1 | Blue | 9 | Light Blue |
2 | Green | 10 | Light Green |
3 | Cyan | 11 | Light Cyan |
4 | Red | 12 | Light Red |
5 | Magenta | 13 | Light Magenta |
6 | Yellow | 14 | Light Yellow |
7 | White | 15 | Bright White |
The Module Window will flash a little as if it is refreshed. Minimize the Module Window (with Alt+F11 you can toggle the window) to show up the Database Window and you will see a New Form is Created with the name like Form1 and the Border2D heading is created with White Border. Once the Heading is created you can change text, text size, fore-color, border color and change the style to bold, italic etc.
To change the Heading Text, Text Style, Border Color and Text Color:
Select all the controls together and display the Property Sheet and change the Caption with the Text of your choice. While all the labels are in selected state you can make the Text Bold, Italic or change the Size of the Text. Select a Color from the Color Pallette for Border first. This will change the Fore-color of all Labels. Now Click only on the top Label and apply a different foreground color.
