Microsoft Access VBA Tutorials for self-paced learning, Class Modules, SQL Techniques, and AI Integration Guides.

Showing posts with label Art Work. Show all posts
Showing posts with label Art Work. Show all posts

Memo Field Text Formatting

Introduction.

We know that Memo fields in Microsoft Access tables provide the flexibility to store variable-length text data. However, in Access versions before 2007, these fields only supported plain text—much like working in Notepad.

For a long time, users felt the need for richer formatting options, such as creating numbered or bulleted lists, or highlighting key points to emphasize important information.

With the release of Microsoft Access 2007, this long-awaited feature finally arrived.

A Sample Quick Run.

Let us quickly try to find out how it works.

  1. Open Microsoft Access 2007

  2. If you have an earlier version of the Northwind.mdb sample database, open it. Otherwise, select Sample from the displayed list of templates and choose the Northwind 2007 template.

  3. Open the Employees Table in Design View.

  4. Click on the Notes Field to select it.

  5. Click on the Text Format Property on the General Tab of the Field Properties Sheet.  The current value of the Property is Plain Text.

  6. Select Rich Text from the drop-down list to replace Plain Text.

  7. You will see a warning message below; click Yes to apply the change.

  8. Close the Design View and save the changes.

  9. Open the Employees Table in Datasheet View.

  10. Expand the Row Height of the records by dragging the intersection of the two records at the left border.

  11. Bring the Notes Field values into view by moving the Scrollbar to the right and increasing the column width, see the image below.

  12. You can now format the Memo Field Text as you apply Text formatting in MS Word.

  13. In the example image above, I have created a Numbered List, Bullet Text, applied Bold, Italics, highlighting, alternate rows fill/back color, etc.

Share:

Colors 24 Bits and Binary Conversion

Introduction.

If you have been following the last four articles on Number Systems (Decimal, Binary, Octal, and Hexadecimal), here’s something interesting for you to explore. Before we dive in, I recommend reviewing those earlier articles using the links provided below. Doing so, you know the background information on this topic, understand the concept more clearly, appreciate its practical usefulness, and enjoy experimenting with the methods we are about to discuss.

  1. Learn the Binary Numbering System
  2. Learn Binary Numbering System-2
  3. Octal Numbering System
  4. Hexadecimal Numbering System


Color Number Range 0 to 16 Million.

The image above shows an MS-Access Form where you can enter a Decimal Number ranging from 0 to 16,777,215 (the maximum value represented by a 24-bit binary number). The form converts the entered value into its Binary equivalent and simultaneously uses the number to generate an RGB color, displayed in the top color band. With this method, you can visualize over 16 million possible colors on the form.

In the example shown, the value 65535 is entered in the text box. The corresponding Binary representation (1111111111111111) is displayed in the gray band just above the text box. Each binary digit is aligned under a label in red font, which represents the decimal value of that bit position. By adding together all these red-labeled values where the binary digit is You arrive at the decimal number entered in the text box.

The Red, Green, and Blue (RGB) Colors.

Bits 0 to 7 (the first 8 bits) represent the Red component, while bits 8 to 15 (the next 8 bits) represent the Green component. When both Red and Green are at full strength, they combine to produce Yellow, which is displayed on the top color band above the Red, Green, and Blue bars.

Now, let’s slightly modify this sample color. Starting with the value 65535, click on the labels with the values 4096 and 64. Each selected value is transferred into the text box and subtracted from 65535. The clicked labels return to their default black font color, indicating that those bit values are no longer active.

Finally, click the Convert command button. The updated result (the new RGB number) is displayed in blue beneath the text box, and the top color band updates to show the new color generated after subtracting the selected bit values. See the image below for reference.

If you would like to add more Red, Green, or Blue to the existing color number, simply click on the labels that display numbers in black font. Each selected value will be added to the current color, and when you click the Convert command button, the new result will be displayed in the top color band. The intensity of the added color depends on the magnitude of the number chosen within the respective color band. Once a value is included, its label font changes to red, indicating that it has been added to the current color number.

If you click a label that is already red, its font will switch back to black, meaning that value will now be subtracted from the total. Again, click the Convert command button to evaluate the final color value. The updated binary digits of the selected values will appear in the gray band above the text box each time, allowing you to trace which bits are active.

To restore the form to its default state, click the Reset command button.

How to make a Color Choice?

You can use one of the three methods given below or a mix of all three to enter the number into the TextBox:

  1. Enter a Decimal Number directly into the TextBox and click the Convert command button.

  2. Enter a valid expression into the TextBox (for example: 2^10 + 2^5 + 5*25 + 1638) and click the Convert command button. The expression will be evaluated, and the result will be converted.

  3. Click on the labels beneath the Red, Green, and Blue color bands to select values and combine them into a new color. Each clicked value is added to the TextBox as part of an expression, and its label font changes to red, showing it has been included. Clicking the same label again will subtract that value, and the font will revert to black color. When ready, click the Convert command button to apply the result.

  4. You can also combine all three methods—direct number entry, expressions, and label selections—to arrive at a valid color number between 1 and 16,777,215 (16777215 = 256 Blue × 256 Green × 256 Red – 1).

Get the result in three ways:

  1. The RGB Color equal to the number selected is displayed on the top color band.
  2. The Binary Number.
  3. The RGB Color Number of the top color band.

How to Use the Newly Created Color.

You can use this color number when designing Forms or Controls in Access by setting it as the Background, Foreground, or Border Color in the Property Sheet of the Form or Control. If you are a web designer, you can convert the decimal color number into a hexadecimal value and use it in your style sheets. To do this, call the function Hex(DecimalNumber) in the Debug Window. The result will give you the 24-bit hexadecimal format, which can be applied directly in CSS, for example: #0000FF for the decimal color value 255.

Enter the number 16777215 in the Text Box and click the Convert Command Button to change the top color band to white.

You can download a database with the above Form and Programs by clicking on the Download link below:

Technorati Tags:

Download Demo Database

Download Demo Binary.zip


Share:

Digital Clock on Main Switchboard

Digital Clock on Main Switchboard.

You probably have several timekeeping devices around you—clocks, wristwatches, or even your computer—to check the current date and time. But why not add a digital clock to your project’s Main Switchboard form? This way, users can check the date and time at a glance, right in the middle of their work, without interrupting their workflow.

Beyond practicality, an animated digital clock also adds a touch of style to the Main Switchboard. All it takes is a label control on the Form and just a few lines of VBA code.

The clock automatically pauses whenever another form is opened over the Main Switchboard, and it restarts with the current time as soon as the Switchboard becomes active again.

If you’ve never used VBA in your databases and aren’t sure where to begin, this is the perfect opportunity to start with something simple, useful, and fun. Simple Clock Design.

Let us do it together.

  1. Open one of your existing Databases.

  2. If you have a Control Screen (Main Switchboard) in your database, then open it in Design View. You can open any Form in Design View to try this out.

  3. Display the Toolbox (View ->Toolbox) if it is not visible.

  4. Click the Label Tool to select.

  5. Draw a Label where you would like the Digital Clock to appear on the Form.

    For this example, I used a copy of the Main Switchboard form from the Microsoft Access sample database Northwind. The image below shows the form in Design View, with a Label control inserted for displaying the digital clock.

  6. Type at least one character (any character) in the Label control; otherwise, the Label control will disappear when you click elsewhere.

  7. While the Label Control is still in the selected state, display its Property Sheet (View ->Properties).

  8. Change the following Property Values as given below:

    • Name    =   lblClock
    • Width   =  1.5938"
    • Height   =  0.3125"
    • Border Style = Transparent
    • Font Size = 8
    • Font Weight = Bold
    • Text Align   =  Center

    Next, we need just two lines of VBA code to start the digital clock. The first line goes in the Form_Load() event procedure of the Switchboard form. This code starts the form’s IntervalTimer immediately after the Switchboard opens, ensuring the clock begins running as soon as the form is displayed.

  9. Click the form selector at the top-left corner of the form, where the horizontal and vertical rulers intersect, to select the entire form. The Property Sheet will now display the form-level properties. If the Property Sheet is closed, follow Step 7 above to reopen it and view the form’s properties.

  10. Find the On Load Property and click on it to select it.

  11. Select [EventProcedure] from the drop-down list box.

  12. Click on the Build (...) button at the right edge of the Property to open up the VBA Module with an empty skeleton of the VBA Sub-Routine as given below:

    The Form_Load() Event and Code.

    Private Sub Form_Load()
    
    End Sub
  13. Write (or copy) the following line of VBA Code in the middle of the above lines of Code:

    Me.TimerInterval = 1000 

    This line of code tells Access to pass program control to the form’s Timer subroutine (which we will write next) at one-second intervals. In other words, whatever code we place in the Timer subroutine will be executed once every second, sixty times per minute.

    In the Timer subroutine, we will add a single line of code to read the system date and time, and to update the label caption we created earlier. As a result, the label will display a continuously updating digital clock.

  14. Select Timer from the drop-down control at the top of the VBA Module Window.

    The opening and closing lines of the Timer Sub-Routine will be inserted into the VBA Module.  You must write the line given in the middle by inserting spaces and other punctuation correctly between double-quotes (date/time format string).

    Private Sub Form_Timer()
        Me.lblClock.Caption = Format(Now(), "dddd dd, mmm-yyyy hh:nn:ss")
    End Sub

    Alternatively, you can copy and paste all three lines of the VBA Code anywhere within the Form Module.

  15. Close and Save the Form.

  16. Open the Form in Normal View.

Your digital clock will show the Current Date and Time, and the time change is updated every second.

When other forms are open and overlapping the Switchboard or different programs and macros are running, the Main Switchboard Form becomes inactive. In such events, the digital clock can be temporarily turned off until the Switchboard becomes active again. This prevents unnecessary updates to the clock’s label and allows other programs to run more efficiently without interruptions from the clock’s timer.

We will write two more lines of code for the On Deactivate() and On Activate() Event Procedures to turn off the Timer (when the Main Switchboard is inactive) and to turn on (when the Main Switchboard is active again), respectively.

  1. Open the Form in Design View.

  2. Display the Form's VBA Module (View ->Code).

  3. Copy and paste the following VBA Code into an empty area of the Module.

    Private Sub Form_Activate()
        Me.TimerInterval = 1000
    End Sub
    
    Private Sub Form_Deactivate()
        Me.TimerInterval = 0
    End Sub

    Trial Run of Form Activity.

  4. Save the Form and close it.

  5. Open it in the normal view.

  6. Open some other Form overlapping the Main Switchboard.

  7. Click on the Title Area of the second Form and drag it away from the Main Switchboard Form so that you can see the Digital Clock on it.

    You can see that the clock is not getting updated.

  8. Close the second Form.

Now the Main Switchboard Form becomes active, and the Clock will start updating the Date and Time again.

Technorati Tags:
Share:

Color and Picture in Message Box

Color and Picture in Message Box - Access 2003

The image below shows a Microsoft Access Message Box displayed using the Office Assistant. This Message Box appears after the user changes the Appointment Date field to a new value. The alert prompts the user to reconfirm the change.

The field name is underlined, and the old and new values are displayed in different colors. Additionally, the company logo appears above the message text.

A Quick Demo

Want to find out quickly how this works?

  1. Copy the following VBA Code into a Standard Module in your Database:
    Public Function MyAssistant()
    Dim msg As String
    Dim AppointmentDt As Date
    Dim AppointmentDt2 As Date
    Dim logo As String
    
    AppointmentDt = #7/20/2009#
    AppointmentDt2 = #7/25/2009#
    logo = "{bmp D:\Images\CoLogo.bmp}"
    
    msg = logo & vbCr & "Existing {ul 1}Appointment Date:{ul 0}{cf 252} " & AppointmentDt & "{cf 0}" & vbCr & vbCr
    msg = msg & "Replace with {ul 1}New Date:{ul 0}{cf 249} " & AppointmentDt2 & "{cf 0}...?"
    
    With Assistant.NewBalloon
        .Icon = msoIconAlertQuery
        .Animation = msoAnimationGetAttentionMinor
        .Heading = "Appointment Date"
        .text = msg
        .Show
    End With
    
    End Function
  2. If you have a small Bitmap File (bmp) somewhere on your machine, then change the path in this line, logo = "{bmp D:\Images\CoLogo.bmp}" in the code to your .bmp image location.

  3. See that you have linked the Microsoft Office Object Library File to your Database. If you are not sure how to do it, then do the following:

    • Press Alt+F11 to display the VBA Editing Window (or Tools -> Macro -> Visual Basic Editor), if it is not already visible.

    • Select References from the Tools Menu.

    • Find Microsoft Office 11.0 Object Library (or whatever version is available) in the Available List and put a check mark to select it.

    • Click OK to close the Dialog Box.

  4. Click somewhere in the middle of the above VBA Code you have pasted into your Database.

  5. Press the F5 Key to Run the Code. You will find the above Message Box, with Office Assistant displaying your Bitmap Image above the message text.

The Enhancement Makes the Difference.

One important point to note here is that the actual data visibility within the message text is underlined and colored. It catches the user's eye quickly and a lot better than showing everything in one Color.

Note: Readers who have not yet learned how to use the Office Assistant with MS-Access Message Boxes may read the following Post and copy the Programs presented there in your Library Database or Project. You can download a sample Database with the Code from there, too.

Message Box using the Office Assistant.

You may also go through the following Posts to learn more interesting ways to use the Office Assistant with Message Boxes:

  1. Message Box with Options Menu
  2. Office Assistant with Check-Box Menu
  3. Selection of Office Assistant

The AppointmentDt_LostFocus() Event Procedure that displays the above Message Box is given below:

Private Sub AppointmentDt_LostFocus()
Dim msg As String

If Me![AppointmentDt].OldValue <> Me![AppointmentDt].Value Then
    msg = AsstLogo & vbCr & "Existing {ul 1}Appointment Date:{ul 0}{cf 252} " & Me![AppointmentDt].OldValue & "{cf 0}" & vbCr & vbCr
    msg = msg & "Replace with {ul 1}New Date:{ul 0}{cf 249} " &  Me![AppointmentDt].Value & "{cf 0}...?"

    If MsgYN(msg, "AppointmentDt_LostFocus()") = vbNo Then
        Me![AppointmentDt].Value = Me![AppointmentDt].OldValue
    End If
    Me.Refresh
End If

End Sub

Text Formatting Codes.

If you check the above message text formatted and stored in the String Variable msg. You can see that it uses certain code values within {} (curly brackets) in the Message String to format the Underline and Color of the text. Old and New Values for the AppointmentDt field are joined with the message text to show them in color.

At the beginning of the message text, I have used the word AsstLogo to add the Company Logo above the Message Text. I will explain this after we check the other codes and usage.

The MsgYN() User Defined Function we have created for displaying a Message Box with Yes and No Option Buttons with the Office Assistant, and learned about other options in the earlier Articles mentioned above.

There are only two types of Codes used within curly brackets to format the message text:

{ul } ' stands for Underline
{cf } ' stands for Color Format and is used with 16 different Color Numbers.

{ul 1} turns On the underline and {ul 0} turns it Off.

{cf 0} (Black Color) is used to change the color of the text to the normal message color.

Example-1: MsgOK "Hi {ul 1}Michael{ul 0}, Welcome to Tips and Tricks."

Result: Hi Michael, Welcome to Tips and Tricks.

Example-2: MsgOK "Hi {cf 250}{ul 1}Michael{ul 0}{cf 0}, Welcome to Tips and Tricks."

Result: Hi Michael, Welcome to Tips and Tricks.

You can copy the text string part of the above examples into the first program above and try them out to find out.

You can use any of the following 16 Color Numbers in the {cf } format string:

Color Codes:

  • Black: 0
  • Dark Red: 1
  • Dark Green: 2
  • Dark Yellow: 3
  • Dark Blue: 4
  • Dark Magenta: 5
  • Dark Cyan: 6
  • Light Gray: 7
  • Medium Gray: 248
  • Red: 249
  • Green: 250
  • Yellow: 251
  • Blue: 252
  • Magenta: 253
  • Cyan: 254
  • White: 255

The main challenge when formatting the message text is typing all the codes within curly brackets correctly, as it’s easy to make mistakes in balancing the opening and closing brackets. If this happens, part of the message text or the inserted field values may not appear in the Message Box.

A simple solution is to define all the color codes as Global Constants in a standard VBA module and use these constants wherever needed in the message text. You can declare the color values as constants in a standard module like this:

Declaring Global Constants.

Constant declaration Examples:

Public Const AsstUlOn as String = "{ul 1}"

Public Const AsstUlOff as String = "{ul 0}"

Public Const AsstGreen as String = "{cf 250}"

Public Const AsstBlack as String = "{cf 0}"

Then we can rewrite the example 2 Code above.

Example-2:

MsgOK "Hi " & AsstGreen & AsstUlOn & "Michael" & AsstUlOff & AsstBlack & ", Welcome to Tips and Tricks. "

No curly brackets or color codes to memorize. If you know the color name, then you can format the message quickly, the way you want it.

Valid Image Formats.

To display the Company Logo above the Message Text (or below if you like), you can use two types of Images, a Bitmap Image (bmp) or a Windows Meta File (wmf) Image.

Bitmap Image usage: {bmp ImagePath}

Windows Meta File usage: {WMF ImagePath sizing_factor}

The sizing_factor determines the width of the WMF file displayed and is omitted for Bitmap Files. You can use the WMF image without the sizing_factor value.

The complete Global Constant declarations for the above color values are provided below. You can copy them into a standard module in your Common Library Database to use across multiple applications on your network, or into a single database to test them before implementing them in other applications.

Text Formatting Constant Declarations

Public Const AsstLogo As String = "{bmp D:\Images\CoLogo}"
Public Const AsstUlon As String = "{ul 1}"
Public Const AsstUloff As String = "{ul 0}"
Public Const AsstBlack As String = "{cf 0}"
Public Const AsstDarkRed As String = "{cf 1}"
Public Const AsstDarkGreen As String = "{cf 2}"
Public Const AsstDarkYellow As String = "{cf 3}"
Public Const AsstDarkBlue As String = "{cf 4}"
Public Const AsstDarkMagenta As String = "{cf 5}"
Public Const AsstDarkCyan As String = "{cf 6}"
Public Const AsstLightGray As String = "{cf 7}"
Public Const AsstMediumGray As String = "{cf 248}"
Public Const AsstRed As String = "{cf 249}"
Public Const AsstGreen As String = "{cf 250}"
Public Const AsstYellow As String = "{cf 251}"
Public Const AsstBlue As String = "{cf 252}"
Public Const AsstMagenta As String = "{cf 253}"
Public Const AsstCyan As String = "{cf 254}"
Public Const AsstWhite As String = "{cf 255}"

You can modify the image path on the first line to point to a bitmap image stored in a network’s common folder accessible to all your application users. This allows all your MS-Access applications on the network to use the same image.

Network Server Location Mapping.

Use the Image Path Name in UNC format (like \\ServerName\FolderName\ImageName.bmp) so that if the Disk Drive mapping is changed to a different letter, like K: or J:, etc., the programs will not lose contact with the image on the Network Path.

Instead of adding the AsstLogo Constant along with the message text every time, like:

Msg = AsstLogo & vbCr & "Hi Michael,... " It is better if you add it to the main program code so that it is used automatically for all the messages before they are displayed. See the modified code segment in the main program given above:

Public Function MyAssistant()
With Assistant.NewBalloon
    .Icon = msoIconAlertQuery
    .Animation = msoAnimationGetAttentionMinor
    .Heading = "Appointment Date"
 .text = AsstLogo & vbCr & msg
    .Show
End With
End Function

Modify the above Code segment of the Main Program you have copied from the earlier Article: Message Box uses Office Assistant to use the Company Logo in all your Message Boxes.

Displaying Greetings on Special Occasions.

During special occasions, such as Christmas or Valentine's Day, you can replace the company logo with themed images to delight and surprise your application users.

Check the sample Message Boxes with Christmas Images:

Or the Image of the King of Pop Music:

Note: These features work only in Access 2003 or earlier versions.

Image Source: Britannica Encyclopedia.

Share:

Form Background with Gradient Color

Form Background with Gradient Color.

The Form background pictures are not only used for giving the Form a different look, but also for other useful purposes.

Assume that the user is entering data from a pre-printed document, such as a telephone or an electricity bill.  In such situations, it can be very effective to scan an image of the source document and use it as the background picture of the data entry form. The Data Fields can be positioned in appropriate locations on the image, matching the physical Document so that it will be easier for the user to find information on the Document and key in exactly the same locations on the Form.

Microsoft Access Form Wizard offers several images that can be used as background pictures, but I couldn’t find the one I wanted — a simple gradient background. So, I decided to create one myself and use it instead.


Creating a Sample Image.

The steps are given below to create the image for the Form Background picture.

  1. Opened a new Microsoft Word Document and went through the following steps to create a Gradient bitmap image:

  2. Selected Format - - >Background - - > Fill Effects.

  3. Under Colors, selected One Color.

  4. Clicked on the Color 1 drop-down control and selected a light color.

  5. Used the Darker/Lighter slider control to adjust the color tone.

  6. Selected the Horizontal Radio Button under Shading Styles.

  7. Clicked on one of the Style Variants.

  8. Clicked OK to apply the selected shade as the Background of the Word Document.

  9. Maximized the Word Document Window.

  10. Selected the Prt Scrn key (at the top row, right side). The full-screen image is now captured and copied to the Clipboard.

  11. Opened the MS Paint Program. You can find this in Start -> Programs -> Accessories.

  12. Displayed the Toolbox (View -> Toolbox or press Ctrl+T).

  13. Selected the Select Tool (the one at the top right with a rectangle picture).

  14. Drawn a rectangle from the left top corner of the gradient image area to the right bottom corner to select the image large enough for my Form's width and height. If you find the width is not enough to cover your form, then change the Page Orientation of the Word Document into Landscape mode before capturing it in MS Paint.

  15. Use Ctrl+C to copy the selected area into the Clipboard.

  16. Click outside the selected area to deselect the earlier selection.

  17. Select Clear Image from the Image Menu (Ctrl+Shift+N) to clear the Canvas. Inspected the right Scroll Bar to check whether it is positioned at the top or not. It was positioned slightly down, so I dragged it up to the top. Similarly, adjusted the Scroll bar at the bottom to the position at the left end.

  18. Pressed Ctrl+V to paste the copied image from the Clipboard.

  19. Clicked outside the pasted image to deselect it.

  20. Dragged the Sizing control at the bottom of the Canvas up and stopped at the edge of the pasted image to eliminate the white area of the canvas.

  21. Similarly, adjust the right side of the image.

  22. Select Save from the File Menu to save the image with a name in a convenient location.

If you’ve been following along so far, we’re now ready to move on to the next stage — implementing the gradient image as a background picture. However, there are a few limitations when using images like this as a form background, but with a little trick, we can easily overcome them.

If you’re thinking about the increase in database size, you’re absolutely right to consider it. And if you’re already thinking about saving the image in JPEG or GIF format, then you’re one step ahead of me! Saving the image type as GIF in MS Paint won’t produce good-quality results. If you have access to software like Adobe Photoshop, you can create high-quality GIF images with much better control.

We’ll use the BMP image format with a few smart modifications to preserve excellent image quality without increasing the database size.

But first, let’s see how to change the form’s background picture to the gradient image.

Inserting the Image on the Form Background.

Before opening your database, you can check the current file size in Windows Explorer. It’s a good idea to compact the database first to get an accurate baseline size. After adding the background picture to a Form, inspect the database size again to see how much it has changed.

  1. Open your Database and open a Form in Design View or create a new one.

  2. Display the Property Sheet of the Form (View -> Properties).

  3. Find the Picture Property and click on it.

  4. Click the Build button (...) in the Property Sheet and click it to browse to the location of the image you have saved and select the image.

  5. The next four Properties are used for formatting and displaying the Background Picture.

  • Picture Type
  • Picture Size Mode
  • Picture Alignment
  • Picture Tiling

Linked or Embedded Image Methods.

The Picture Type property has two options, Embedded and Linkedwith Embedded as the default. The Embedded option allows you to open the default image editor directly from within MS Access by double-clicking the image and editing the picture if needed. However, to support this functionality, Access stores not only the image but also additional information required to invoke the image editor. As a result, each embedded image can significantly increase the size of your database. Note that background images added this way cannot be edited by double-clicking them, unlike OLE object images inserted on a Form.

A better option is the Linked setting, which keeps the image stored externally, leaving your database size unaffected. However, in either case, the image file must remain available in the same location relative to your database if it is moved or shared.

The Picture Size Mode property provides three options. The default option, Clip, displays the picture at its actual size, positioned according to the Picture Alignment setting—Top Left, Top Right, Bottom Right, Bottom Left, Center, or Form Center. The Center option places the image both vertically and horizontally centered on the Form, while Form Center aligns it vertically centered along the left edge.

The Stretch/Zoom/Tile Picture Methods

The Stretch Picture Size Mode option will stretch the image to fit the dimensions of the Form, resulting in distortion of the image if it is a picture of something.

The Zoom Picture Size Mode option will attempt to maintain the right proportions of the image when stretched to match the dimensions of the Form. But both the Stretch and Zoom options will show stretch marks when the Form is restored to its original size. This is much more evident when a .jpeg or GIF image is used.

The One Pixel Width Image.

We can modify our earlier .bmp file to a one-pixel-width image and Tile it across the Form, which will give a good quality gradient picture effect, and the image size will also be small.

  1. Open the earlier saved .bmp image in the MS Paint Program.

  2. Select Attributes... from the Image Menu.

  3. Change the Width value to 1, and leave the Height value unchanged.

  4. Check that Units is selected as Pixels.

  5. Save the image with a different name.

  6. Change the name of the background image to the new image in the Picture property of the Form.

    Caution: Do not attempt to use the Picture Size Mode property options Stretch or Zoom; MS-Access may hang up.

  7. Set the Picture Tiling Property Value to Yes and save the Form.

  8. Open the Form in Normal View and enjoy your creation.

Share:

Wave Shaped Reminder Ticker

Wave-Shaped Reminder Ticker.

We have already seen how to create and install a Reminder Ticker that runs in a straight line on the Main Screen. We could do this with a few lines of VBA code and a Label control on the Main Screen. We will try something different this time. This ticker runs in a Zigzag form. An image of a sample run of this method is given below:

To create this Ticker, we need a series of labels arranged in a wavelike form, and each one must be named in a way that makes it easy to address them in code. A sample design is given below:


Automating the Label Creation.

There are about 42 identical labels to be created. Even if we create them manually once, arranging them in the required zigzag layout is a challenging task. However, this can be done efficiently with a small program. The program generates a new form, creates all 42 labels, arranges them in a zigzag pattern, assigns them sequential names, such as lbl1 through lbl42, and adjusts their other properties as described above.

  1. Copy the following Code into a Global Module of your Database and save it.
    Public Function ZIGZAG()
    '-----------------------------------------------------------
    'Author  :  a.p.r. pillai
    'Date    :  01/10/2008
    'URL     :  www.msaccesstips.com
    'All Rights Reserved by www.msaccesstips.com
    '-----------------------------------------------------------
    Dim frm As Form, ctrl As Label, t As Long, lngleft As Long
    Dim lngwidth As Long, lngheight As Long, lngtop As Long
    Dim j As Integer, k As Integer, h As Long, G As Long
    
    h = 30: G = 0: t = 0
    lngwidth = 0.1146 * 1440
    lngheight = 0.2083 * 1440
    lngtop = 1 * 1440
    lngleft = 0.16667 * 1440
    Set frm = CreateForm
    For j = 1 To 42
    Set ctrl = CreateControl(frm.Name, acLabel, acDetail, , , lngleft, lngtop, lngwidth, lngheight)
    lngleft = lngleft + lngwidth
    With ctrl
        .Name = "lbl" & j
        .FontName = "Tahoma"
        .FontSize = 8
        .Caption = ""
        .BackStyle = 0
        .ForeColor = 255
     End With
     Next
    G = 0
    For j = 1 To 3
         For k = 1 To 7
            G = G + 1
            Set ctrl = frm.Controls("lbl" & G)
            With ctrl
                .Top = .Top - (h * k)
            End With
            DoEvents
         Next
        t = frm.Controls("lbl" & G).Top
         For k = 1 To 7
             G = G + 1
            Set ctrl = frm.Controls("lbl" & G)
            With ctrl
                .Top = t + (h * 1)
            End With
            t = frm.Controls("lbl" & G).Top
            DoEvents
        Next
    Next
    End Function
    
  2. You can run the above Code directly by placing the cursor in the middle of the Code and pressing the F5 Key, or running from a Command Button's On Click Event Procedure or a Macro.

    Each time the code is executed, it creates a new form with the labels arranged in a zigzag pattern. Once you’ve created it, you can export this form to other projects where you want to install the ZigZag Ticker. Alternatively, you can place the code in a common library database and run it from your new project after attaching the library file to your project.

    Placement of the Ticker Labels.

  3. After creating the Labels, click outside the Labels and drag over them so that all the Labels are selected without disturbing the Labels' arrangement.

  4. Select Copy from the Edit Menu.

  5. Open the Main Switch Board (Control Form) in Design View and paste them.

  6. When all the labels are still in the selected state, drag and place the Labels into a position where you want the Ticker to appear on the Form.

    We have two more Sub-Routines, which are run from the Form_Load() and Form_Timer() Event Procedures. In the Form_Load() Event Procedure, we can create a Text Message in a String either with a constant value or with Field Values from a Table/Query that provides useful information to display to the User as a reminder. Refer to the earlier example Reminder Ticker Form, which uses data from within the Application as a reminder.

    Formatting Ticker Text.

    The Form_Timer() Event Procedure will control the Display of Label values, shifting one character at a time in succeeding labels, giving it a sense of motion.

  7. Copy and paste the following Sub-Routines into the Form Module where you have pasted the above labels.

    Option Compare Database
    Option Explicit
    Dim txt As Variant
    
    Private Sub Form_Load()
        txt = Space(42) & UCase("Excellence is not a matter of chance. It is a matter of Change. It is not a thing to be waited for. It is a thing to be achieved.")
        Me.Timerinterval=250
    End Sub
    
  8. See that the Dim txt As Variant is placed in the Global Area of the Module, which is referenced from the Form_Load() and Form_Timer() Event Procedures.

    Private Sub Form_Timer()
    Dim x As String, k As String, j As Integer, ctrl As Control
    
      x = Left(txt, 1)
      txt = Right(txt, Len(txt) - 1)
      txt = txt & x
      k = Left(txt, 42)
    For j = 1 To Len(k)
        Set ctrl = Me.Controls("lbl" & J)
        Ctrl.Caption = Mid(k, j, 1)
    Next
    End Sub 
    

    Disable Ticker on inactive Form.

  9. The following lines of code are useful if you plan to disable the ticker when the Main Form is inactive and run it when the Main Form is active again, so that other processes are not interrupted by the Ticker.

Private Sub Form_Deactivate()
   Me.TimerInterval = 0
End Sub

Private Sub Form_Activate()
   Me.TimerInterval = 250
End Sub

Download


Download Demo Database Access2007.zip



Download Demo Database Access2002-03.zip

Share:

Shadow 3D Heading Text Style

Create manually or use VBA.

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 with 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 - Bottom right 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 Border 2D Heading Text.

    The third parameter 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 MS Access Help for more details on the dlookup() Function.

    Download

    Download Demo Database
    Share:

    Border 3D Heading Style

    Creating a 3D Heading on a Form/Report.

    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 to run the program described on this page successfully.

    The function below creates an attractive, 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 drag 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:

    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 External Links Queries Array Class Module msaccess reports Accesstips msaccess tips WithEvents Downloads Objects Menus and Toolbars MsaccessLinks Process Controls Art Work Collection Object Property msaccess How Tos Combo Boxes ListView Control Query VBA msaccessQuery Calculation Dictionary Object 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 Recordset Top Values Variables msaccess email progressmeter Access2007 Copy Excel Expression Fields Join Methods Microsoft Numbering System RaiseEvent Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup Wrapper Classes 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 Export 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