Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

MsgBox with Office Assistant

Introduction - Access 2003.


Two Message Box examples are shown above. The one on the left is the default message box style in MS Access. The one on the right—featuring the Office Cat image—is created using the Office Assistant in VBA. These customized message boxes use the built-in features of the Office Assistant to enhance user interaction.

You can change the animated character from the Tools menu. By adding a few VBA functions to your MS Access project, you can use this feature wherever needed in your applications.

To simplify usage, several frequently used message box styles have been implemented as user-defined functions that utilize the Office Assistant. These functions are designed for convenience and require only two parameters:

  1. Message Text – the main message to display.

  2. Title (optional) – the caption displayed in the title bar of the message box. If this is not specified, a default title will be used.

The Button Type and Icon Type (such as the question mark icon displayed in the top-left corner of the message box) are preset within each function, based on the message type. This allows you to quickly use these message boxes without having to specify additional options every time.

The following user-defined functions are available, along with their usage syntax:

MsgOK("Message Text","Title") - MessageBox with only OK Button

MsgYN("Message Text","Title") - MessageBox with Yes & No Buttons. Returned Value is vbYes or vbNo

MsgOKCL("Message Text","Title") - MessageBox with OK and Cancel Buttons. Returned Value is vbOK or vbCancel

The function names listed above indicate the type of command buttons that will appear in the message box, as well as the return values corresponding to the user's responses.

Essential Library Files

First, you must attach the Microsoft Office 9.0 Object Library (or the version that matches your installed Office) to your project. This is essential for enabling the use of Office Assistant features in your VBA programs. Additionally, you’ll need to add a few other important library references that are not linked to Access by default.

For a complete list of required library files and detailed instructions on how to attach them, please refer to my earlier article titled Command-Button Animation.

Once the necessary libraries are attached, copy and paste the following code into a global module in your project and save it.

Public Function MsgOK(ByVal strmsg As String, Optional ByVal strHeading As String) As Integer
    On Error resume next
 MsgOK = MsgBalun(strmsg, strHeading, msoButtonSetOK, msoAnimationGestureUp, msoIconAlertInfo) 
End Function
Public Function MsgOKCL(ByVal strmsg As String, Optional ByVal strHeading As String) As Integer
  On Error Resume Next
  MsgOKCL = MsgBalun(strmsg, strHeading, msoButtonSetOkCancel, msoAnimationWritingNotingSomething, msoIconAlertQuery)
End Function 
Public Function MsgYN(ByVal strmsg As String, Optional ByVal strHeading As String) As Integer
on error resume next
    MsgYN = MsgBalun(strmsg, strHeading, msoButtonSetYesNo, msoAnimationWritingNotingSomething, msoIconAlertQuery)
End Function
Private Function MsgBalun(ByVal strText As String, ByVal strTitle As String, ByVal lngButtons As Long, ByVal intAnimation, ByVal intIcon) As Integer '------------------------------------------------------------ 
'Author : a.p.r. pillai 
'Date   : September 2006 
'Rights : All Rights Reserved by www.msaccesstips.com
'------------------------------------------------------------ 
Dim lngx As Long, intVal As Integer, Balu As Balloon 
On Error GoTo MsgBaloons_Err  
With Assistant   
If .On = False Then     
    .On = True
   '.FileName = "OFFCAT.acs"
     .Animation = msoAnimationGetAttentionMinor
     .AssistWithHelp = True
     .GuessHelp = True
     .FeatureTips = False
     .Visible = True
End If 
End With
  Set Balu = Assistant.NewBalloon
 With Balu
     .Animation = intAnimation
     .Icon = intIcon
    .Heading = strTitle
    .Text = strText
    .BalloonType = msoBalloonTypeButtons
    .Button = lngButtons
  Select Case Balu.Show
        Case msoBalloonButtonOK
            MsgBalun = vbOK
        Case msoBalloonButtonCancel
           MsgBalun = vbCancel
        Case msoBalloonButtonYes
           MsgBalun = vbYes
        Case msoBalloonButtonNo
           MsgBalun = vbNo
 End Select
 End With
  Assistant.Visible = False

MsgBaloons_Exit: 
Exit Function  

MsgBaloons_Err: 
MsgBox Err.Description, , "MsgBaloons" 
Resume MsgBaloons_Exit 
End Function 

You can use these Functions without bothering about selecting the Button-Type, IconType, etc. that you normally need to give along with the Message Box Command, like:

vbYesNo+vbDefaultButton2+vbQuestion

Usage Example:

If MsgYN("Select Yes to Proceed, No to Cancel.","cmdProcess") = vbYes then
    Docmd.runmacro "Process" 
End if 

OR

The second Parameter Title is omitted in the second example.

If MsgYN("Select Yes to Proceed, No to Cancel.") = vbYes then
    Docmd.runmacro "Process"
End if 

Testing the Code

You can type any of the above commands in the Debug Window and press the Enter Key, like the sample given below, to test the commands before using them in your programs:

MsgOK "System is preparing to shut down", "cmdExit_Click"

OR

MsgOK "System is preparing to shut down"

The MsgBalun() Function is not directly used in programs.

Implement the procedures in your Project and try them out.

Download

Download Demo Database


Share:

SHADOW3D HEADING STYLE

Introduction.

This article continues the series showcasing various 3D Heading Styles for designing Microsoft Access Form and Report headers. The style demonstrated here is a variant of the 3D Heading design previously introduced under the title Create 3D Headings on Forms.

Each style offers its own unique visual appeal, and once created, it can be easily copied and customized, changing the foreground color, font, and font styles (such as Bold or Italic) to suit the look and feel of your form or report headings.

I have created several heading designs of this type. If this is the first one you’ve come across on this site, please note that some initial setup is required before you can successfully run the code for this heading style—or any of the others shared here.

To prepare your Microsoft Access project environment:

  1. Link the required library files to your project. These are common libraries already available on your system. You simply need to attach them by following the steps outlined in my earlier post titled Command-Button Animation.
  2. Copy the necessary program code (listed below) into a new global VBA module in your project and save it.
  3. If you’ve already added the core functions from earlier posts, then you only need to copy the final function: Shadow3D()

The VBA Programs

Option Compare Database
 Option Explicit
 '-- Global declarations
 Private Const lngheight as long = 0.45 * 1440
 Private Const lngWidth as long = 4.5 * 1440
 Private Const intFontSize as integer = 26
 Private Const intTextAlign as integer = 0
 Private Const intBackStyle as integer = 0
 Private Const LngI as long = 0.0104 * 1440
 Private Const intX as long = 0.15 * 1440
 Private Const intY as long = 0.15 * 1440
 Dim MyFrm As Form 

Public Function FormTxtLabels(Optional ByVal ControlType As Integer) As String 
'---------------------------------------------------
'Author : a.p.r. pillai 
'Date : September 2006
'ControlType = 0 for label
'ControlTYPE = 1 for TextBox 
'--------------------------------------------------- 
Dim ctl As Control 
'On Error GoTo FormTxtLabels_Err
If ControlType > 0 Then ControlType = 1 

Set MyFrm = CreateForm 

If ControlType = 1 Then
   Set ctl = CreateControl(MyFrm.NAME, acTextBox, acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight) 

   With ctl
    .ControlSource = "=" & Chr(34) & "msaccesstips.com" & Chr(34)
   End With
Else
   Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight)

  With ctl
    .Caption = "msaccesstips.com" 
  End With

End If 

FormTxtLabels = MyFrm.NAME 

FormTxtLabels_Exit: 
Exit Function

Public Function Validate_Dup(ByRef MyFrm As Form, ByVal intNooflabels As Integer) As Integer 
'---------------------------------------------------
'Author : a.p.r. pillai 
'Date : September 2006
'ControlType = 0 for label
'ControlTYPE = 1 for TextBox 
'---------------------------------------------------
Dim mysec As Section, lblcount As Integer 
Dim myctrl As Control, newctrl As Control, j As Integer 
Dim lngx As Long, lngY As Long, lngH As Long, lngW As Long 
Dim strCap As String, ctrltype As Integer, intlbls As Integer 
Dim ctrlName() As String, ctrlIndex() As Integer, i As Long
Dim strFont As String, intFntSize As Integer, x As Integer 
Dim intFntWeight As Integer  

'On Error GoTo Validate_Dup_Err 

Set mysec = MyFrm.Section(acDetail)
intlbls = mysec.Controls.Count - 1 

Set myctrl = mysec.Controls(0) 
ctrltype = myctrl.ControlType 
intNooflabels = intNooflabels - 1 
If intlbls > 0 Then 
  ReDim ctrlName(intlbls) As String
  ReDim ctrlIndex(intlbls) As Integer 
End If 
If ctrltype = 109 And intlbls > 0 Then 
    For j = 0 To intlbls 
      Set myctrl = mysec.Controls(j) 
      ctrlIndex(j) = myctrl.ControlType 
      ctrlName(j) = myctrl.NAME 
    Next 
  For j = 0 To intlbls 
    If ctrlIndex(j) = 100 Then 
      DeleteControl MyFrm.NAME, ctrlName(j) 
    End If 
  Next 
  intlbls = mysec.Controls.Count - 1 
End If 

Set myctrl = mysec.Controls(0) 
If intlbls < intNooflabels Then 
With myctrl
  lngx = .Left
  lngY = .Top
  lngW = .Width
  lngH = 0.0208 * 1440 ' 0.0208 inches
  strFont = .FontName
  intFntSize = .FontSize
  intFntWeight = .FontWeight 
End With 

If ctrltype = 100 Then 
  strCap = myctrl.Caption 
ElseIf ctrltype = 109 Then 
  strCap = myctrl.ControlSource 
End If 
If ctrltype = 109 And intlbls > 0 Then 
  For j = 0 To intlbls 
    Set myctrl = mysec.Controls(j) 
    ctrlIndex(j) = myctrl.ControlType 
    ctrlName(j) = myctrl.NAME 
  Next 
  For j = 0 To intlbls 
    If ctrlIndex(j) = 100 Then 
      DeleteControl MyFrm.NAME, ctrlName(j) 
    End If 
  Next 
intlbls = mysec.Controls.Count - 1 
Set myctrl = mysec.Controls(intlbls)
With myctrl 
  lngx = .Left 
  lngY = .Top 
  lngW = .Width 
  lngH = .Height 
  ctrltype = .ControlType 
  strFont = .FontName 
  intFntSize = .FontSize 
  intFntWeight = .FontWeight 
End With 
End If 

i = 0.0104 * 1440 + lngH ' 0.0104 inches 
lngY = lngY + i 
For j = intlbls + 1 To intNooflabels 

  Set newctrl = CreateControl(MyFrm.NAME, ctrltype, _acDetail, "","", lngx, lngY, lngW, lngH) 

  If ctrltype = 100 Then 
    newctrl.Caption = strCap 
    newctrl.FontName = strFont 
    newctrl.FontSize = intFntSize 
    newctrl.FontWeight = intFntWeight 
  Else 
    newctrl.ControlSource = strCap 
    newctrl.FontName = strFont 
    newctrl.FontSize = intFntSize 
    newctrl.FontWeight = intFntWeight 
  End If 
lngY = lngY + i 
Next 
End If 

If intlbls > intNooflabels Then 
  For j = intNooflabels + 1 To intlbls 
    Set myctrl = mysec.Controls(j) 
    ctrlIndex(j) = myctrl.ControlType 
    ctrlName(j) = myctrl.NAME 
  Next 
  For j = intNooflabels + 1 To intlbls 
    DeleteControl MyFrm.NAME, ctrlName(j) 
  Next 
  Validate_Dup = 0 
End If 

intlbls = mysec.Controls.Count - 1 
Set myctrl = mysec.Controls(0) 
ctrltype = myctrl.ControlType 
If ctrltype = 109 Then 
  For j = 0 To intlbls 
    Set myctrl = mysec.Controls(j) 
    With myctrl 
     .Enabled = False 
     .Locked = True 
     .SpecialEffect = 0 
    End With 
  Next 
End If 
Validate_Dup = 0 

Validate_Dup_Exit: 
Exit Function 

Validate_Dup_Err: 
MsgBox Err.Description, ,"Validate_Dup" 
Validate_Dup = 1 
Resume Validate_Dup_Exit 
End Function 

Public Function MsgLabel() 
'------------------------------------------------------------ 
'Author : a.p.r. pillai 
'Date : September 2006 
'------------------------------------------------------------
Dim mySection As Section, ctl As Control, xForm As Form 
Dim l As Long, t As Long, w As Long, h As Long, F As Long 
F = 1440 
l = 0.5 * F: t = 1.2 * F: w = 3.6563 * F: h = 0.4896 * F 'values in inches 
On Error Resume Next 
Set mySection = MyFrm.Section(acDetail) 
Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , "", l, t, w, h) 
ctl.Caption = "Click outside the Controls and Drag Over. "  & "Display the Property Sheet. " & "Type New Text for Caption/Control " & "Source Property area for Label/ Text Boxes. " & "Copy and Paste the Controls to " & "Target Form/Report Area." 
End Function

  • The code above includes the main functions required for all the heading styles presented so far, including this one. Once you have those in place, you can proceed by copying the code provided below for this specific heading style and try it out.
  • Paste the following code into the same global module where you've already copied the main programs—or into any other global module of your choice—and save it.
  • Public Function Shadow3D(ByVal intStyle As Integer, ByVal intForeColor As Integer, _
    Optional ByVal Label0Text1 As Integer) As String  
    '---------------------------------------------------------- 
    'Author : a.p.r. pillai 
    'Date   : September 2006
    'Rights : All Rights Reserved by www.msaccesstips.com
    '---------------------------------------------------------- 
    Dim intlbls As Integer, intFSize As Integer  
    Dim j As Integer, mySection As Section  
    Dim lblName() As String, lngForecolor As Long, X As Integer  
    Dim l As Long, t As Long   
    
    On Error Resume Next
       Shade3D = FormTxtLabels(Label0Text1)
       Set mySection = MyFrm.Section(acDetail)
      intlbls = mySection.Controls.Count - 1
       On Error GoTo Shadow3D_Err
       X = Validate_Dup(MyFrm, 5) ' check type and duplicate
       If X = 1 Then
        Exit Function
      End If
      intlbls = mySection.Controls.Count - 1
       X = intStyle
      intStyle = IIf(X < 0, 0, IIf(X > 3, 3, intStyle))
      X = intForeColor
      intForeColor = IIf(X < 0, 0, IIf(X > 15, 15, intForeColor))
       ReDim lblName(0 To intlbls) As String
       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
         Select Case j
           Case 0
            lngForecolor = 8421504
           Case 1 To intlbls - 2
            lngForecolor = 8421504
           Case intlbls - 1
            lngForecolor = 0 '12632256
           Case intlbls
            lngForecolor = QBColor(intForeColor)
          End Select
            .ForeColor = lngForecolor
       End With
      Next
      l = intX: t = intY
       With mySection.Controls(lblName(1))
        .Left = l
        .Top = t
      End With
      For j = 0 To intlbls
      Select Case intStyle
             Case 0
                l = l + LngI
                t = t + LngI
             Case 1
                l = l + LngI
                t = t - LngI
             Case 2
              l = l - LngI
              t = t + LngI
             Case 3
                l = l - LngI
                t = t - LngI
      End Select
        With mySection.Controls(lblName(j))
           .Left = l
           .Top = t
        End With
      Next
      MsgLabel
    
    Shadow3D_Exit:
    Exit Function
    Shadow3D_Err:
    Msgbox Err.Description,, "Shadow3D"
    Resume Shadow3D_Exit  
    End Function  
    

    Create Shadow3D Heading Style.

      To run the Shadow3D function manually from the VBA editor:

    1. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor. (You can toggle between the Access Database window and the VBA editor using this keyboard shortcut.)
    2. Press Ctrl + G (or go to View > Immediate Window) to open the Immediate Window at the bottom of the VBA screen.

      In the Immediate Window, type the following line and then press Enter:

      Shadow3D 1, 4, 0

      This will execute the function with the specified parameters:

      1 = Text Fore-Color (e.g., Blue)
      
      4 = Border Color (e.g., Red)
      
      0 = Label-based design (default)
      

    You will notice the screen briefly flashes, indicating that the form has been updated. Minimize the Visual Basic window, and you will see a new form created with the 3D heading style applied. Along with the heading, the form also displays help text providing tips on how to customize the 3D heading with your own caption, preferred font, and font styles such as bold or italic.

    Let us examine the Command Line Values.

    Shadow3D is the function name.

    The first parameter value 1 controls the Shadow position of the Heading Text.  The first parameter value range is 0 to 3

    • 0 - Shadow is tilted to the top left corner of the heading text.
    • 1 - bottom left corner
    • 2 - Right top corner
    • 3 - Right bottom corner

    The second parameter value 4 (Red color) sets the text color of the topmost label. The acceptable range of color values is from 0 - 15, based on the QBColor codes. A reference chart of these codes is provided on the page titled Border2D Heading Text.

    The third parameter value 0 creates 3D text using Label controls. This parameter is optional, and when omitted, the function defaults to creating a Label-based 3D heading. 

    Note: If you choose to omit this parameter, do not add a comma after the second parameter.

    If the third parameter is 1 then the function that creates a TextBox-based design. In this case, an expression such as ="Sample Text" is automatically inserted into the Control Source property of each TextBox layer created for the heading.

    You can replace the constant text in the Control Source property with your own text, or set it to display values from a field in the underlying Table or Query linked to the form. Alternatively, you can use a DLookup() function to retrieve values from a different Table or Query.

    Example: =Dlookup("CountryName","Country Table","CountryCode = 'USA'")

    The above example will display "United States of America" in a 3D style by retrieving the value from the CountryName field of the Country table, using the CountryCode as the lookup key. If the criteria parameter of the function needs to reference a control on the form, modify the expression accordingly to use the control name as the criteria, as shown below:

    =Dlookup("CountryName","CountryTable","CountryCode = '" & Me![CCode] & "'")

    [CCode] The field that stores country codes in the table or query attached to the Form. The current value of this field on the form is used to find the corresponding country name.

    Note: The single quote immediately after the equal sign (=), followed by a double-quote, and the closing single quote within double-quotes before the closing parenthesis, indicates that the value of [CCode] is treated as text (character data type) in the expression.

    Tip: Search in MS Access Help for more details on the Dlookup() Function.

    Download

    Download Demo Database
    Share:

    BORDER3D HEADING


    Introduction.

    If you've arrived directly on this page, please refer to my earlier article, Command-Button Animation, for instructions on linking the essential library files to your project. That article includes the list of required library files and step-by-step guidelines for attaching them. These libraries are necessary for running the program described on this page successfully.

    The function below creates an attractive and visually engaging heading style, similar to the sample image shown above. After generating the sample heading on a new form, you can customize the font, style (Bold, Italic), shadow, border, and text color to suit your preferences.

    Copy and paste the VBA code below into a new global module in your database. If you’ve already added the first three functions (listed below) along with the Global declarations from the earlier post Create 3D Headings on Forms, then you only need to copy and paste the final function: Border3D.

    The following common functions are used by the main program Border3D for all other 2D/3D styles:

    • FormTxtLabels()
    • Validate_Dup()
    • MsgLabel()

    The Functions VBA Code.

    If you have already copied the above functions earlier, then copy only the last Function: Border3D

    Option Compare Database
     Option Explicit
     '-- Global declarations
     Private Const lngheight as long = 0.45 * 1440
     Private Const lngWidth as long = 4.5 * 1440
     Private Const intFontSize as integer = 26
     Private Const intTextAlign as integer = 0
     Private Const intBackStyle as integer = 0
     Private Const LngI as long = 0.0104 * 1440
     Private Const intX as long = 0.15 * 1440
     Private Const intY as long = 0.15 * 1440
     Dim MyFrm As Form 
    
    Public Function FormTxtLabels(Optional ByVal ControlType As Integer) As String 
    '---------------------------------------------------
    'Author : a.p.r. pillai 
    'Date : September 2006
    'ControlType = 0 for label
    'ControlTYPE = 1 for TextBox 
    '--------------------------------------------------- 
    Dim ctl As Control 
    'On Error GoTo FormTxtLabels_Err
    If ControlType > 0 Then ControlType = 1 
    
    Set MyFrm = CreateForm 
    
    If ControlType = 1 Then
       Set ctl = CreateControl(MyFrm.NAME, acTextBox, acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight) 
    
       With ctl
        .ControlSource = "=" & Chr(34) & "msaccesstips.com" & Chr(34)
       End With
    Else
       Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight)
    
      With ctl
        .Caption = "msaccesstips.com" 
      End With
    
    End If 
    
    FormTxtLabels = MyFrm.NAME 
    
    FormTxtLabels_Exit: 
    Exit Function
    

    Public Function Validate_Dup(ByRef MyFrm As Form, ByVal intNooflabels As Integer) As Integer 
    '---------------------------------------------------
    'Author : a.p.r. pillai 
    'Date : September 2006
    'ControlType = 0 for label
    'ControlTYPE = 1 for TextBox 
    '---------------------------------------------------
    Dim mysec As Section, lblcount As Integer 
    Dim myctrl As Control, newctrl As Control, j As Integer 
    Dim lngx As Long, lngY As Long, lngH As Long, lngW As Long 
    Dim strCap As String, ctrltype As Integer, intlbls As Integer 
    Dim ctrlName() As String, ctrlIndex() As Integer, i As Long
    Dim strFont As String, intFntSize As Integer, x As Integer 
    Dim intFntWeight As Integer  
    
    'On Error GoTo Validate_Dup_Err 
    
    Set mysec = MyFrm.Section(acDetail)
    intlbls = mysec.Controls.Count - 1 
    
    Set myctrl = mysec.Controls(0) 
    ctrltype = myctrl.ControlType 
    intNooflabels = intNooflabels - 1 
    If intlbls > 0 Then 
      ReDim ctrlName(intlbls) As String
      ReDim ctrlIndex(intlbls) As Integer 
    End If 
    If ctrltype = 109 And intlbls > 0 Then 
        For j = 0 To intlbls 
          Set myctrl = mysec.Controls(j) 
          ctrlIndex(j) = myctrl.ControlType 
          ctrlName(j) = myctrl.NAME 
        Next 
      For j = 0 To intlbls 
        If ctrlIndex(j) = 100 Then 
          DeleteControl MyFrm.NAME, ctrlName(j) 
        End If 
      Next 
      intlbls = mysec.Controls.Count - 1 
    End If 
    
    Set myctrl = mysec.Controls(0) 
    If intlbls < intNooflabels Then 
    With myctrl
      lngx = .Left
      lngY = .Top
      lngW = .Width
      lngH = 0.0208 * 1440 ' 0.0208 inches
      strFont = .FontName
      intFntSize = .FontSize
      intFntWeight = .FontWeight 
    End With 
    
    If ctrltype = 100 Then 
      strCap = myctrl.Caption 
    ElseIf ctrltype = 109 Then 
      strCap = myctrl.ControlSource 
    End If 
    If ctrltype = 109 And intlbls > 0 Then 
      For j = 0 To intlbls 
        Set myctrl = mysec.Controls(j) 
        ctrlIndex(j) = myctrl.ControlType 
        ctrlName(j) = myctrl.NAME 
      Next 
      For j = 0 To intlbls 
        If ctrlIndex(j) = 100 Then 
          DeleteControl MyFrm.NAME, ctrlName(j) 
        End If 
      Next 
    intlbls = mysec.Controls.Count - 1 
    Set myctrl = mysec.Controls(intlbls)
    With myctrl 
      lngx = .Left 
      lngY = .Top 
      lngW = .Width 
      lngH = .Height 
      ctrltype = .ControlType 
      strFont = .FontName 
      intFntSize = .FontSize 
      intFntWeight = .FontWeight 
    End With 
    End If 
    
    i = 0.0104 * 1440 + lngH ' 0.0104 inches 
    lngY = lngY + i 
    For j = intlbls + 1 To intNooflabels 
    
      Set newctrl = CreateControl(MyFrm.NAME, ctrltype, _acDetail, "","", lngx, lngY, lngW, lngH) 
    
      If ctrltype = 100 Then 
        newctrl.Caption = strCap 
        newctrl.FontName = strFont 
        newctrl.FontSize = intFntSize 
        newctrl.FontWeight = intFntWeight 
      Else 
        newctrl.ControlSource = strCap 
        newctrl.FontName = strFont 
        newctrl.FontSize = intFntSize 
        newctrl.FontWeight = intFntWeight 
      End If 
    lngY = lngY + i 
    Next 
    End If 
    
    If intlbls > intNooflabels Then 
      For j = intNooflabels + 1 To intlbls 
        Set myctrl = mysec.Controls(j) 
        ctrlIndex(j) = myctrl.ControlType 
        ctrlName(j) = myctrl.NAME 
      Next 
      For j = intNooflabels + 1 To intlbls 
        DeleteControl MyFrm.NAME, ctrlName(j) 
      Next 
      Validate_Dup = 0 
    End If 
    
    intlbls = mysec.Controls.Count - 1 
    Set myctrl = mysec.Controls(0) 
    ctrltype = myctrl.ControlType 
    If ctrltype = 109 Then 
      For j = 0 To intlbls 
        Set myctrl = mysec.Controls(j) 
        With myctrl 
         .Enabled = False 
         .Locked = True 
         .SpecialEffect = 0 
        End With 
      Next 
    End If 
    Validate_Dup = 0 
    
    Validate_Dup_Exit: 
    Exit Function 
    
    Validate_Dup_Err: 
    MsgBox Err.Description, ,"Validate_Dup" 
    Validate_Dup = 1 
    Resume Validate_Dup_Exit 
    End Function 
    

    Public Function MsgLabel() 
    '------------------------------------------------------------ 
    'Author : a.p.r. pillai 
    'Date : September 2006 
    '------------------------------------------------------------
    Dim mySection As Section, ctl As Control, xForm As Form 
    Dim l As Long, t As Long, w As Long, h As Long, F As Long 
    F = 1440 
    l = 0.5 * F: t = 1.2 * F: w = 3.6563 * F: h = 0.4896 * F 'values in inches 
    On Error Resume Next 
    Set mySection = MyFrm.Section(acDetail) 
    Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , "", l, t, w, h) 
    ctl.Caption = "Click outside the Controls and Drag Over. "  & "Display the Property Sheet. " & "Type New Text for Caption/Control " & "Source Property area for Label/ Text Boxes. " & "Copy and Paste the Controls to " & "Target Form/Report Area." 
    End Function
    

    Public Function Border3D(ByVal intStyle As Integer, 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, I As Long, intFSize As Integer
    On Error Resume Next
     I = 0.0104 * 1440 ' 0.0104 inches
     Border3D = FormTxtLabels(Label0Text1)
     Set mySection = MyFrm.Section(acDetail)
     intlbls = mySection.Controls.Count - 1 
    On Error GoTo Border3D_Err
     X = Validate_Dup(MyFrm, 7) ' 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))
     X = intStyle
     intStyle = IIf(X < 0, 0, IIf(X > 3, 3, intStyle)) 
    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(intlbls))
       .Left = l
       .Top = t
     End With 
    For j = 2 To intlbls - 1
       With mySection.Controls(lblName(j))
          Select Case j
             Case 2
               .Left = l + I
               .Top = t + I
             Case 3
               .Left = l + I
               .Top = t - I
             Case 4
               .Left = l - I
               .Top = t + I
             Case 5
               .Left = l - I
               .Top = t - I
          End Select
       End With
     Next
       For j = 0 To 1
        With mySection.Controls(lblName(j))
         '.ForeColor = 9868950
         .ForeColor = 0
        If j = 0 Then
         Select Case intStyle
            Case 0
                .Left = l - (I * 3)
                .Top = t - (I * 3)
            Case 1
                .Left = l - (I * 3)
                .Top = t + (I * 3)
            Case 2
                .Left = l + (I * 3)
                .Top = t - (I * 3)
            Case 3
                .Left = l + (I * 3)
                .Top = t + (I * 3)
         End Select
       Else
         Select Case intStyle
              Case 0
                .Left = l - (I * 2)
                .Top = t - (I * 2)
            Case 1
                .Left = l - (I * 2)
                .Top = t + (I * 2)
            Case 2
                .Left = l + (I * 2)
                .Top = t - (I * 2)
            Case 3
                .Left = l + (I * 2)
                .Top = t + (I * 2)
         End Select
       End If
         End With
     Next
     MsgLabel
     Border3D_Exit:
     Exit Function
    
     Border3D_Err:
     Msgbox Err.Description,, "Border3D"
     Resume Border3D_Exit
     End Function  
    

    How to Create

    To create the Border3D Heading Text, press ALT+F11 to open the VBA Window and press Ctrl+G to display the Debug Window (Immediate Window). Type the following line in the immediate window and press the Enter key:

    Border3D 1,4,15,0

    The module window will flash for a moment as if it has been refreshed. Minimize the VBA Window, and you will see a new form created and kept minimized on the taskbar by the program. Restore the form and save it, with the Heading Text.

    First, let’s get familiar with the parameter values of the function. The first three parameters are mandatory — if any of them is omitted, the program will display an error message: "Parameter not optional." The fourth parameter is optional.

    Parameter Values

    The first parameter value represents the shadow position. The value range and their shadow positions are as given below:

    • 0 - Top Left
    • 1 - Bottom Left
    • 2 - Top Right
    • 3 - Bottom Right

    By using one of the four values as the first parameter, you can display the shadow tilted to any one of the four corners of the heading.

    The second parameter value 4 (Red Color) is the Text color, and the value range is 0 to 15.  You can find the color numbers and their description here.

    The third parameter value 15 creates a white-colored border around the text. The valid range of values is from 0 to 15.

    The fourth parameter is optional. If omitted, a default value  0 is assumed, which creates a Label-based heading. A value of 1 creates a TextBox-based heading.

    Customizing Text

    After creating the 3D heading, you can select all the labels together by clicking and holding the left mouse button just outside the group, then dragging the mouse over them. Once selected, press F4 or go to View → Properties to display the Property Sheet. From there, update the Caption property with your desired text. You can also customize the font, font size, and apply styles like Bold or Italic as per your preference.

    How to Copy and Reuse the 3D Heading

    1. Deselect All Labels:

      • Click anywhere on the form outside the label group to deselect it.

    2. Change the Foreground Color of the Top Label:

      • Carefully click only on the topmost label.

      • Change its fore-color to the heading color of your choice.

      • Be cautious not to move the label out of alignment.

    3. Select All Labels Again:

      • Click and drag your mouse to select all the labels together, just like before.

    4. Copy the Labels:

      • Press Ctrl + C to copy the selected labels to the clipboard.

    5. Open Target Form/Report:

      • Open the target Form or Report in Design View.

    6. Paste the Heading:

      • Press Ctrl + V to paste the heading onto your form or report.

    7. Save as a Template (Optional):

      • Save the current form as a template, so you can copy and modify the 3D heading on other forms or reports.

    Downloads

    Download Demo Database
    Share:

    Border2D Heading Text


    Introduction.

    MS Access Form and Report design tools are very user-friendly and only require some practice to master. However, manually creating effects like the one shown in the image above can be quite challenging, though it is possible. The effect can be achieved by stacking five identical labels on top of each other: the topmost label should have a red font color, while the four labels beneath it should have a white font. Each of the white labels should be shifted by about one pixel in different directions—top-left, top-right, bottom-left, and bottom-right—relative to the red label to create a 3D or shadowed effect.

    The Sample Report Title image is given below:

    However, manually positioning all the labels precisely to maintain the intended style, without distortion, is not easy. Fortunately, you can create the red-colored heading text with white-bordered layers—shown above—in just seconds using the user-defined function provided below. The color can be customized as needed. This function automates the technique described earlier, saving you time and effort.

    Automating Text Styling

    Copy and paste the VBA code below into a new global module in your database. If you've already copied the first three functions (listed below) and the global declarations from the earlier post “Create 3D Headings on Forms”, then you only need to copy and paste the final function Border2D.

    The following common functions are used for all 2D/3D styles:

    • FormTxtLabels()
    • Validate_Dup()
    • MsgLabel()

    If you have already copied them earlier, then copy only the last Function: Border2D()

    Option Compare Database
     Option Explicit
     '-- Global declarations
     Private Const lngheight as long = 0.45 * 1440
     Private Const lngWidth as long = 4.5 * 1440
     Private Const intFontSize as integer = 26
     Private Const intTextAlign as integer = 0
     Private Const intBackStyle as integer = 0
     Private Const LngI as long = 0.0104 * 1440
     Private Const intX as long = 0.15 * 1440
     Private Const intY as long = 0.15 * 1440
     Dim MyFrm As Form 
    
    Public Function FormTxtLabels(Optional ByVal ControlType As Integer) As String 
    '---------------------------------------------------
    'Author : a.p.r. pillai 
    'Date : September 2006
    'ControlType = 0 for label
    'ControlTYPE = 1 for TextBox 
    '--------------------------------------------------- 
    Dim ctl As Control 
    'On Error GoTo FormTxtLabels_Err
    If ControlType > 0 Then ControlType = 1 
    
    Set MyFrm = CreateForm 
    
    If ControlType = 1 Then
       Set ctl = CreateControl(MyFrm.NAME, acTextBox, acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight) 
    
       With ctl
        .ControlSource = "=" & Chr(34) & "msaccesstips.com" & Chr(34)
       End With
    Else
       Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight)
    
      With ctl
        .Caption = "msaccesstips.com" 
      End With
    
    End If 
    
    FormTxtLabels = MyFrm.NAME 
    
    FormTxtLabels_Exit: 
    Exit Function 
    
    FormTxtLabels_Err: 
    MsgBox Err.Description, , "FormTxtLabels" 
    FormTxtLabels = "" 
    Resume FormTxtLabels_Exit 
    End Function 
    
    Public Function Validate_Dup(ByRef MyFrm As Form, ByVal intNooflabels As Integer) As Integer 
    '---------------------------------------------------
    'Author : a.p.r. pillai 
    'Date : September 2006
    'ControlType = 0 for label
    'ControlTYPE = 1 for TextBox 
    '---------------------------------------------------
    Dim mysec As Section, lblcount As Integer 
    Dim myctrl As Control, newctrl As Control, j As Integer 
    Dim lngx As Long, lngY As Long, lngH As Long, lngW As Long 
    Dim strCap As String, ctrltype As Integer, intlbls As Integer 
    Dim ctrlName() As String, ctrlIndex() As Integer, i As Long
    Dim strFont As String, intFntSize As Integer, x As Integer 
    Dim intFntWeight As Integer  
    
    'On Error GoTo Validate_Dup_Err 
    
    Set mysec = MyFrm.Section(acDetail)
    intlbls = mysec.Controls.Count - 1 
    
    Set myctrl = mysec.Controls(0) 
    ctrltype = myctrl.ControlType 
    intNooflabels = intNooflabels - 1 
    If intlbls > 0 Then 
      ReDim ctrlName(intlbls) As String
      ReDim ctrlIndex(intlbls) As Integer 
    End If 
    If ctrltype = 109 And intlbls > 0 Then 
        For j = 0 To intlbls 
          Set myctrl = mysec.Controls(j) 
          ctrlIndex(j) = myctrl.ControlType 
          ctrlName(j) = myctrl.NAME 
        Next 
      For j = 0 To intlbls 
        If ctrlIndex(j) = 100 Then 
          DeleteControl MyFrm.NAME, ctrlName(j) 
        End If 
      Next 
      intlbls = mysec.Controls.Count - 1 
    End If 
    
    Set myctrl = mysec.Controls(0) 
    If intlbls < intNooflabels Then 
    With myctrl
      lngx = .Left
      lngY = .Top
      lngW = .Width
      lngH = 0.0208 * 1440 ' 0.0208 inches
      strFont = .FontName
      intFntSize = .FontSize
      intFntWeight = .FontWeight 
    End With 
    
    If ctrltype = 100 Then 
      strCap = myctrl.Caption 
    ElseIf ctrltype = 109 Then 
      strCap = myctrl.ControlSource 
    End If 
    If ctrltype = 109 And intlbls > 0 Then 
      For j = 0 To intlbls 
        Set myctrl = mysec.Controls(j) 
        ctrlIndex(j) = myctrl.ControlType 
        ctrlName(j) = myctrl.NAME 
      Next 
      For j = 0 To intlbls 
        If ctrlIndex(j) = 100 Then 
          DeleteControl MyFrm.NAME, ctrlName(j) 
        End If 
      Next 
    intlbls = mysec.Controls.Count - 1 
    Set myctrl = mysec.Controls(intlbls)
    With myctrl 
      lngx = .Left 
      lngY = .Top 
      lngW = .Width 
      lngH = .Height 
      ctrltype = .ControlType 
      strFont = .FontName 
      intFntSize = .FontSize 
      intFntWeight = .FontWeight 
    End With 
    End If 
    
    i = 0.0104 * 1440 + lngH ' 0.0104 inches 
    lngY = lngY + i 
    For j = intlbls + 1 To intNooflabels 
    
      Set newctrl = CreateControl(MyFrm.NAME, ctrltype, _acDetail, "","", lngx, lngY, lngW, lngH) 
    
      If ctrltype = 100 Then 
        newctrl.Caption = strCap 
        newctrl.FontName = strFont 
        newctrl.FontSize = intFntSize 
        newctrl.FontWeight = intFntWeight 
      Else 
        newctrl.ControlSource = strCap 
        newctrl.FontName = strFont 
        newctrl.FontSize = intFntSize 
        newctrl.FontWeight = intFntWeight 
      End If 
    lngY = lngY + i 
    Next 
    End If 
    
    If intlbls > intNooflabels Then 
      For j = intNooflabels + 1 To intlbls 
        Set myctrl = mysec.Controls(j) 
        ctrlIndex(j) = myctrl.ControlType 
        ctrlName(j) = myctrl.NAME 
      Next 
      For j = intNooflabels + 1 To intlbls 
        DeleteControl MyFrm.NAME, ctrlName(j) 
      Next 
      Validate_Dup = 0 
    End If 
    
    intlbls = mysec.Controls.Count - 1 
    Set myctrl = mysec.Controls(0) 
    ctrltype = myctrl.ControlType 
    If ctrltype = 109 Then 
      For j = 0 To intlbls 
        Set myctrl = mysec.Controls(j) 
        With myctrl 
         .Enabled = False 
         .Locked = True 
         .SpecialEffect = 0 
        End With 
      Next 
    End If 
    Validate_Dup = 0 
    
    Validate_Dup_Exit: 
    Exit Function 
    
    Validate_Dup_Err: 
    MsgBox Err.Description, ,"Validate_Dup" 
    Validate_Dup = 1 
    Resume Validate_Dup_Exit 
    End Function 
    
    Public Function MsgLabel() 
    '------------------------------------------------------------ 
    'Author : a.p.r. pillai 
    'Date : September 2006 
    '------------------------------------------------------------
    Dim mySection As Section, ctl As Control, xForm As Form 
    Dim l As Long, t As Long, w As Long, h As Long, F As Long 
    F = 1440 
    l = 0.5 * F: t = 1.2 * F: w = 3.6563 * F: h = 0.4896 * F 'values in inches 
    On Error Resume Next 
    Set mySection = MyFrm.Section(acDetail) 
    Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , "", l, t, w, h) 
    ctl.Caption = "Click outside the Controls and Drag Over. "  & "Display the Property Sheet. " & "Type New Text for Caption/Control " & "Source Property area for Label/ Text Boxes. " & "Copy and Paste the Controls to " & "Target Form/Report Area." 
    End Function
    
    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, make sure that all essential library references—outlined in my earlier article, Command-Button Animation—are properly linked to your project. Additionally, the main procedures provided under the topic Create 3D Headings on Forms are also required. If you haven’t already done so, copy and paste those programs into a global module in your project.

    The above function will create a new form and design the heading text on it in seconds. You can copy & paste it anywhere on Forms or Reports you like and customize it with the required text, text size, color, and text in bold or italics. 

    How to Run the Code Manually.

    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, Label, or Text

    Type the following and press the 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 of the function and use references to the text boxes in command parameters.

    Example:

    Private Sub cmdBorder2D_Click()
       Border2D Me![txtForeColor], Me![txtBorderColor],0
    End Sub

    The first two parameter values define the text's foreground color and border color, respectively (value range: 0 to 15). The third parameter determines the type of control: a value of 0 creates a label-based design, while 1 creates a textbox-based design. This third parameter is optional—if omitted, the function defaults to creating a label-based design.

    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 briefly flash, indicating a refresh. Press Alt+F11 to toggle back to the database window, where you’ll see a new form named Form1. This form will contain the Border2D heading with a white border already applied.

    Customizing Text Properties.

    Once the heading is created, you can customize the text, adjust the font size, change the foreground and border colors, and apply styles such as bold or italic.

    To change the Heading Text, Text Style, Border Color, and Text Color:

    Select all the controls together, open the Property Sheet, and change the Caption to the text of your choice. While all the labels remain selected, you can make the text bold, italic, or adjust the font size. Choose a border color from the color palette—this will apply the selected color as the foreground color to all labels. Next, carefully click only on the top label and change its foreground color to distinguish it from the others.

    Downloads

    Download Demo Database
    Share:

    CREATE 3D-HEADINGS ON FORMS

    Introduction.

    The 3D-style heading text, as shown above, can be created quickly in Microsoft Access by layering multiple copies of the same label. Simply copy and paste the label five to seven times, each with the same caption text. Then, offset each duplicate slightly upward and to the left or right to create a shadow-like depth effect. You can customize the topmost label with a brighter font color and use darker shades for the underlying labels to enhance the 3D appearance. This approach offers an easy and effective way to add visual appeal to your Form or Report headers.

    The 3D text design can be customized by using Label controls with your desired caption, font style, size, color, bold, or italic formatting. For dynamic content, you can also create a similar 3D effect using TextBox controls, allowing you to display information from table or query fields directly on the form or report. 

    Before proceeding further, ensure that all essential project library references have been linked to your database. Failing to do so may result in runtime errors. Please refer to the earlier post on Command Button Animation and follow the steps outlined there to link the necessary library files to your project.

    The VBA Code

    Copy and paste the following code into a new Global Module and save it:

    Option Compare Database
     Option Explicit
     '-- Global declarations
     Private Const lngheight as long = 0.45 * 1440
     Private Const lngWidth as long = 4.5 * 1440
     Private Const intFontSize as integer = 26
     Private Const intTextAlign as integer = 0
     Private Const intBackStyle as integer = 0
     Private Const LngI as long = 0.0104 * 1440
     Private Const intX as long = 0.15 * 1440
     Private Const intY as long = 0.15 * 1440
     Dim MyFrm As Form 
    
    Public Function FormTxtLabels(Optional ByVal ControlType As Integer) As String 
    '---------------------------------------------------
    'Author : a.p.r. pillai 
    'Date : September 2006
    'ControlType = 0 for label
    'ControlTYPE = 1 for TextBox 
    '--------------------------------------------------- 
    Dim ctl As Control 
    'On Error GoTo FormTxtLabels_Err
    If ControlType > 0 Then ControlType = 1 
    
    Set MyFrm = CreateForm 
    
    If ControlType = 1 Then
       Set ctl = CreateControl(MyFrm.NAME, acTextBox, acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight) 
    
       With ctl
        .ControlSource = "=" & Chr(34) & "msaccesstips.com" & Chr(34)
       End With
    Else
       Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , , (0.2 * 1440), (0.2 * 1440), lngWidth, lngheight)
    
      With ctl
        .Caption = "msaccesstips.com" 
      End With
    
    End If 
    
    FormTxtLabels = MyFrm.NAME 
    
    FormTxtLabels_Exit: 
    Exit Function 
    
    FormTxtLabels_Err: 
    MsgBox Err.Description, , "FormTxtLabels" 
    FormTxtLabels = "" 
    Resume FormTxtLabels_Exit 
    End Function 
    
    Public Function Validate_Dup(ByRef MyFrm As Form, ByVal intNooflabels As Integer) As Integer 
    '---------------------------------------------------
    'Author : a.p.r. pillai 
    'Date : September 2006
    'ControlType = 0 for label
    'ControlTYPE = 1 for TextBox 
    '---------------------------------------------------
    Dim mysec As Section, lblcount As Integer 
    Dim myctrl As Control, newctrl As Control, j As Integer 
    Dim lngx As Long, lngY As Long, lngH As Long, lngW As Long 
    Dim strCap As String, ctrltype As Integer, intlbls As Integer 
    Dim ctrlName() As String, ctrlIndex() As Integer, i As Long
    Dim strFont As String, intFntSize As Integer, x As Integer 
    Dim intFntWeight As Integer  
    
    'On Error GoTo Validate_Dup_Err 
    
    Set mysec = MyFrm.Section(acDetail)
    intlbls = mysec.Controls.Count - 1 
    
    Set myctrl = mysec.Controls(0) 
    ctrltype = myctrl.ControlType 
    intNooflabels = intNooflabels - 1 
    If intlbls > 0 Then 
      ReDim ctrlName(intlbls) As String
      ReDim ctrlIndex(intlbls) As Integer 
    End If 
    If ctrltype = 109 And intlbls > 0 Then 
        For j = 0 To intlbls 
          Set myctrl = mysec.Controls(j) 
          ctrlIndex(j) = myctrl.ControlType 
          ctrlName(j) = myctrl.NAME 
        Next 
      For j = 0 To intlbls 
        If ctrlIndex(j) = 100 Then 
          DeleteControl MyFrm.NAME, ctrlName(j) 
        End If 
      Next 
      intlbls = mysec.Controls.Count - 1 
    End If 
    
    Set myctrl = mysec.Controls(0) 
    If intlbls < intNooflabels Then 
    With myctrl
      lngx = .Left
      lngY = .Top
      lngW = .Width
      lngH = 0.0208 * 1440 ' 0.0208 inches
      strFont = .FontName
      intFntSize = .FontSize
      intFntWeight = .FontWeight 
    End With 
    
    If ctrltype = 100 Then 
      strCap = myctrl.Caption 
    ElseIf ctrltype = 109 Then 
      strCap = myctrl.ControlSource 
    End If 
    If ctrltype = 109 And intlbls > 0 Then 
      For j = 0 To intlbls 
        Set myctrl = mysec.Controls(j) 
        ctrlIndex(j) = myctrl.ControlType 
        ctrlName(j) = myctrl.NAME 
      Next 
      For j = 0 To intlbls 
        If ctrlIndex(j) = 100 Then 
          DeleteControl MyFrm.NAME, ctrlName(j) 
        End If 
      Next 
    intlbls = mysec.Controls.Count - 1 
    Set myctrl = mysec.Controls(intlbls)
    With myctrl 
      lngx = .Left 
      lngY = .Top 
      lngW = .Width 
      lngH = .Height 
      ctrltype = .ControlType 
      strFont = .FontName 
      intFntSize = .FontSize 
      intFntWeight = .FontWeight 
    End With 
    End If 
    
    i = 0.0104 * 1440 + lngH ' 0.0104 inches 
    lngY = lngY + i 
    For j = intlbls + 1 To intNooflabels 
    
      Set newctrl = CreateControl(MyFrm.NAME, ctrltype, _acDetail, "","", lngx, lngY, lngW, lngH) 
    
      If ctrltype = 100 Then 
        newctrl.Caption = strCap 
        newctrl.FontName = strFont 
        newctrl.FontSize = intFntSize 
        newctrl.FontWeight = intFntWeight 
      Else 
        newctrl.ControlSource = strCap 
        newctrl.FontName = strFont 
        newctrl.FontSize = intFntSize 
        newctrl.FontWeight = intFntWeight 
      End If 
    lngY = lngY + i 
    Next 
    End If 
    
    If intlbls > intNooflabels Then 
      For j = intNooflabels + 1 To intlbls 
        Set myctrl = mysec.Controls(j) 
        ctrlIndex(j) = myctrl.ControlType 
        ctrlName(j) = myctrl.NAME 
      Next 
      For j = intNooflabels + 1 To intlbls 
        DeleteControl MyFrm.NAME, ctrlName(j) 
      Next 
      Validate_Dup = 0 
    End If 
    
    intlbls = mysec.Controls.Count - 1 
    Set myctrl = mysec.Controls(0) 
    ctrltype = myctrl.ControlType 
    If ctrltype = 109 Then 
      For j = 0 To intlbls 
        Set myctrl = mysec.Controls(j) 
        With myctrl 
         .Enabled = False 
         .Locked = True 
         .SpecialEffect = 0 
        End With 
      Next 
    End If 
    Validate_Dup = 0 
    
    Validate_Dup_Exit: 
    Exit Function 
    
    Validate_Dup_Err: 
    MsgBox Err.Description, ,"Validate_Dup" 
    Validate_Dup = 1 
    Resume Validate_Dup_Exit 
    End Function 
    
    Public Function MsgLabel() 
    '------------------------------------------------------------ 
    'Author : a.p.r. pillai 
    'Date : September 2006 
    '------------------------------------------------------------
    Dim mySection As Section, ctl As Control, xForm As Form 
    Dim l As Long, t As Long, w As Long, h As Long, F As Long 
    F = 1440 
    l = 0.5 * F: t = 1.2 * F: w = 3.6563 * F: h = 0.4896 * F 'values in inches 
    On Error Resume Next 
    Set mySection = MyFrm.Section(acDetail) 
    Set ctl = CreateControl(MyFrm.NAME, acLabel, _acDetail, , "", l, t, w, h) 
    ctl.Caption = "Click outside the Controls and Drag Over. "  & "Display the Property Sheet. " & "Type New Text for Caption/Control " & "Source Property area for Label/ Text Boxes. " & "Copy and Paste the Controls to " & "Target Form/Report Area." 
    
    End Function
    
    Public Function Heading3D(ByVal intStyle As Integer, ByVal intForeColor As Integer, _
    Optional ByVal Label0Text1 As Integer) As String 
    '------------------------------------------------------------ 
    'Author : a.p.r. pillai 
    'Date : September 2006 
    '------------------------------------------------------------ 
    Dim intlbls As Integer, mySection As Section 
    Dim j As Integer, intFSize As Integer 
    Dim lblName() As String, lngForecolor As Long, x As Integer 
    Dim l As Long, t As Long 
    
    On Error Resume Next 
    
    Heading3D = FormTxtLabels(Label0Text1) 
    
    Set mySection = MyFrm.Section(acDetail) 
    intlbls = mySection.Controls.Count - 1 
    
    On Error GoTo Heading3D_Err 
    
    x = Validate_Dup(MyFrm, 5) 'check type and duplicate 
    
    If x = 1 Then 
      Exit Function 
    End If 
    
    intlbls = mySection.Controls.Count - 1 
    
    x = intStyle 
    intStyle = IIf(x < 0, 0, IIf(x > 3, 3, intStyle)) 
    
    x = intForeColor 
    intForeColor = IIf(x < 0, 0, IIf(x > 15, 15, intForeColor)) 
    
    ReDim lblName(0 To intlbls) As String 
    
    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 
      Select Case j 
           Case 0 
                  lngForecolor = 0  
           Case 1 To intlbls - 2 
                  lngForecolor = 9868950 
           Case intlbls - 1 
                  lngForecolor = 16777215 
           Case intlbls 
                  lngForecolor = QBColor(intForeColor) 
      End Select 
      .ForeColor = lngForecolor 
    End With 
    Next 
    
    l = intX: t = intY 
    With mySection.Controls(lblName(1)) 
         .Left = l 
         .Top = t 
    End With 
    
    For j = 0 To intlbls 
         Select Case intStyle 
              Case 0 
                    l = l + LngI 
                    t = t + LngI 
              Case 1 
                    l = l + LngI 
                    t = t - LngI 
               Case 3 
                    l = l - LngI 
                   t = t - LngI 
               Case 2 
                   l = l - LngI 
                   t = t + LngI 
            End Select 
        With mySection.Controls(lblName(j)) 
           .Left = l 
            .Top = t 
        End With 
    Next 
    
    MsgLabel 
    
    Heading3D_Exit: 
    Exit Function 
    
    Heading3D_Err: 
    Msgbox Err.Description, ,"Heading3D" 
    Resume Heading3D_Exit 
    End Function 
    

    How the Functions are Used

    The first 3 Functions in the above code:

    FormTxtLabels()

    Validate_Dup()

    MsgLabel()

    The above-listed functions are called from the Heading3D() Function and will be used for other forthcoming Heading Styles.

    How to Create a Customizable Sample 3D Heading

    To create the 3D-Heading on a new Form, display the Visual Basic Window (if not already open) and press Alt+F11. Press Ctrl+G (or select the Immediate Window option from the View menu) to display the Debug Window.

    Type the next line in the immediate window and press the Enter key:

    Heading3D 1, 0

    @@@When the module window refreshes, it will briefly flash. Minimize the Visual Basic Editor window, and you’ll see a new form (named something like Form1) created with a 3D heading. This heading displays the default text msaccesstips.com, along with a help message suggesting possible modifications.

    To reuse the 3D heading:

    • Select all the controls by clicking outside the Labels and dragging the mouse over all of them.

    • Copy and paste the selection into your own Form or Report.

    • With all controls still selected, open the Property Sheet and change the Caption property to your desired text.

    • You can also modify font settings such as Bold, Italic, or Font Name as needed.

    • To change the text color, carefully click only the topmost label (to avoid misaligning it) and apply the color of your choice.

    • If you accidentally select all controls and apply color changes to the entire group, simply press Ctrl+Z to undo.

    Defining the Shadow Position

    The position of the 3D-Text shadow can be controlled by the first parameter value of the Function, and the following values are used:

    1. - Shadow tilted to the top left corner
    2. - Left Bottom Corner
    3. - Right top Corner
    4. - Bottom Right corner

    The second parameter of the function determines the type of 3D heading:

    • A value of 0 creates a Label-based 3D heading.

    • A value of 1 creates a TextBox-based 3D heading, with its Control Source property set to a formula for displaying data.

    For TextBox-based headings, you can modify the Control Source to display values from the underlying table or query fields. This allows the heading text to change dynamically as you navigate between records on your data editing form.

    Tip: You may omit the second parameter when calling the function if you only need a Label-based 3D heading.

    Downloads

    Download Demo Database
    Share:

    COMMAND-BUTTON ANIMATION

    Introduction


    Microsoft Access, the relational database management system, is a jewel among the Microsoft Office suite of applications. It offers powerful design tools and a built-in Visual Basic for Applications (VBA) programming environment. These pages are not intended for beginners, but rather for users who already have a foundational understanding of database design using MS Access—working with tables, queries, forms, reports, and macros—as well as a general familiarity with VBA, including modules, class modules, functions, and event procedures.

    When developing an application using any database management system, it should not only be functional but also user-friendly and visually appealing. A poorly designed interface can diminish the overall impact of the project and reflect the lack of creativity or an ineffective approach to data processing on the part of the developer. A well-designed database enhances usability, improves user experience, and demonstrates professionalism in both design and execution.

    Here, I’d like to share a few programs I’ve developed for use with form controls—each with some amusing and creative twists that I’ve incorporated into my own projects. I’m confident you’ll find them both interesting and useful.

    These demo programs were originally written for Access 2000 and are also compatible with Access 97.

    Attaching Access System Reference Library Files.

    First and foremost, ensure that the essential Microsoft Access reference library files are attached to your project. To configure Microsoft Access properly, follow these steps:

    1. Open the Visual Basic Editor window by selecting Visual Basic Editor from the Tools menu or Code from the View menu in the Access interface.
    2. In the Visual Basic Editor, go to the Tools menu and select References.
    3. In the Available References dialog box, place a check mark next to the following essential library files:
      • Visual Basic for Applications
      • Microsoft Access 11.0 Object Library
      • OLE Automation.
      • Microsoft DAO 3.6 Object Library
      • Microsoft ActiveX Data Objects 2.5 Library
      • Microsoft Office 11.0 Object Library
      • Microsoft Visual Basic for Applications Extensibility 5.3

    These references are required to ensure that your VBA code functions correctly and can interact with the Access objects and features.

    Design Modification

    On the Microsoft Access user interface, the command button is one of the most frequently used controls, second only to text boxes. It typically carries a clear label indicating the action it performs when clicked. However, beyond its basic functionality, we often overlook its potential for enhancing interactivity and user experience.

    Here, we're aiming to make the command button a more engaging and visually appealing element on the form. By introducing subtle animated effects, we can bring the button to life on the screen and enhance the user experience.

    This can be achieved by placing a dark-colored rectangle behind the command button and using just a few lines of VBA code to animate its behavior. The result is a dynamic, attention-grabbing control that stands out and adds a creative touch to your form's design.

    Animating Command Button

    The animation design is simple yet effective. A rectangular control, nearly the same size as the command button and filled with a black background, is positioned directly behind the button and kept hidden by default.

    When the mouse moves over the command button, the button shifts slightly upward and to the left, revealing part of the rectangle beneath it, creating a subtle shadow effect. As the mouse moves away, the button returns to its original position, hiding the rectangle again. This creates the illusion of the button lifting off the surface, adding a touch of interactivity and visual appeal to the form.

    When this action is repeated in quick succession, the command button gives a lively and dynamic appearance, as it moves up and down, alternately revealing and hiding the shadow effect beneath it. This simple animation creates an engaging visual cue for the user, making the button feel more interactive and responsive. Refer to the images above to see both states of the command button—its default position and the animated state with the visible shadow.

    Copy and paste the following VBA code into a new Global Module:

    Public Function ButtonAnimate(ByVal strForm As String,ByVal mode As Integer, ByVal lblName As String)
    '------------------------------------------------------------
    'Command Button Animation
    'Author : a.p.r. pillai
    'Date : September 2006
    '------------------------------------------------------------
    Dim FRM As Form, l As Long, t As Long
    On Error GoTo ButtonAnimate_Err
    Set FRM = Forms(strForm)
    l = FRM.Controls(lblName & "Box").Left
    t = FRM.Controls(lblName & "Box").Top
    If (mode = 1) And (FRM.Controls(lblName & "Box").Visible = False) Then
        FRM.Controls(lblName & "Box").Visible = True
        FRM.Controls(lblName).Left = l - (0.0208 * 1440)' 0.0208 inches
        FRM.Controls(lblName).Top = t - (0.0208 * 1440)' 0.0208 inches
        FRM.Controls(lblName).FontWeight = 700
    ElseIf (mode = 0) And (FRM.Controls(lblName & "Box").Visible = True) Then
        FRM.Controls(lblName & "Box").Visible = False
        FRM.Controls(lblName).Left = l
        FRM.Controls(lblName).Top = t
        FRM.Controls(lblName).FontWeight = 400
    End If
    ButtonAnimate_Exit:
    Exit Function
    
    ButtonAnimate_Err:
    Err.Clear
    Resume ButtonAnimate_Exit
    End Function

    Note: All object specifications on this site are in U.S. Measurements.

    Those who follow the Metric System, please convert the values or select the US in the Regional Settings of the Control Panel or convert the given values into your Regional values.

    Command Button Animation Design:


    1. Open one of your Access Forms in Design View.
    2. Create a Command Button control on the Footer Section of the form.
    3. Display the Property Sheet (F4) of the command button and change the following Property values as given below:
          Name = cmdClose
          Caption = Close
          ControlTipText = Click
    4. Create a rectangle control in the footer section of the form, ensuring it is slightly smaller in both height and width than the command button. This sizing ensures that when the command button is placed directly over the rectangle, the rectangle remains completely hidden beneath it. This setup allows for a clean visual effect when animating the button, as the rectangle will only become partially visible when the button shifts position during the mouse-over event.
    5. Change the following property values of the rectangle control:
          Name = cmdCloseBox

      Note: The name of the rectangle control must be the same as the command button, suffixed with the word ‘Box’.

          Visible = False
          SpecialEffect = Shadowed
          BorderColor = 0
          BorderStyle = Solid
          BackStyle = Transparent
    6. Drag and position the rectangle control precisely underneath the command button so that it is completely hidden from view. To fine-tune its placement, you can use the Ctrl key with the arrow keys in MS Access 2000, or simply the arrow keys alone in later versions of Access, for pixel-level alignment.

      If the rectangle control appears on top of the command button, making it visible, click the "Send to Back" button on the toolbar, or choose Format → Send to Back from the menu. This ensures the command button remains fully visible while the rectangle stays hidden beneath it, ready to create the shadow effect during mouse-over animation.

    7. Copy and paste the following Code into the Form’s Visual Basic Module and save the Form:
      Private Sub cmdClose_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as single)
      ButtonAnimate Me.Name, 1, "cmdClose"
      End Sub
      
      Private Sub FormFooter_MouseMove(Button as Integer, Shift As Integer, X As Single, Y As Single)
      ButtonAnimate Me.Name, 0, "cmdClose"
      End Sub
    8. Open the Form in normal view and try moving the Mouse over the Command Button and over the blank area in the Form Footer in a continuous stroke.
    9. When the mouse moves over the command button, the button shifts slightly upward and to the left, revealing a portion of the rectangle underneath. This exposed area creates the illusion of a shadow, giving the button a lifted appearance. When the mouse moves away—such as into the blank area of the form’s footer section—the button returns to its original position, concealing the rectangle once again. Repeating this interaction gives the command button a lively and dynamic feel, making it stand out among the other static controls on the form.@@@

      Add More Animated Command Buttons

      You can add any number of command buttons to the form using this technique by placing the appropriate code in each button’s MouseMove event procedure. When the ButtonAnimate function is called with a parameter value of 1, it moves the button slightly upward and to the left, creating the shadow effect. Passing a value of 0 resets the button to its original position, hiding the shadow.

      If additional buttons are placed in the form footer, each button should have its own MouseMove event that calls ButtonAnimate(1). The Form Footer’s MouseMove event should include a call to ButtonAnimate(0) to reset all buttons when the mouse moves away. This ensures each button responds independently while maintaining consistent animation behavior across the form.

      Download Demo CommandButtonAnimation.zip

      1. Command Button Animation
      2. Double Action Command Button
      3. Colorful Command Buttons
      4. Transparent Command Button
      5. Command Button Animation-2
      6. Creating Animated Command Button with VBA
      7. Command Button Color Change on Mouse Move

    Share:

    PRESENTATION: ACCESS USER GROUPS (EUROPE)

    Translate

    PageRank

    Post Feed


    Search

    Popular Posts

    Blog Archive

    Powered by Blogger.

    Labels

    Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code