Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

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 give us much-needed flexibility to record variable length Text data.  But, Access Versions earlier than 2007 allows us to enter in plain text format only like we do in Notepad.

The need for some form of text formatting was always felt necessary to organize them in the form of a Numbered List or Bullet List or highlight text to draw attention to important points etc. 

Well, the waiting is over and here it is in Microsoft Access2007.

A Sample Quick Run.

Let us quickly try and find out how it works.

  1. Open Microsoft Access2007

  2. If you have an earlier MS-Access Version Northwind.mdb sample database, then open it, otherwise select Sample from the displayed list of Templates, and click on the Northwind 2007 Template.

    • Click on the Folder Icon on the right side to select the folder to save the Northwind 2007.accdb file and click on the Create Command Button to create and open the file.
    • Click on the Login Command Button

    • Close the Home Form.

  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 were following the last four Articles on Number  Systems (Decimal, Binary, Octal, and Hexadecimal) then here is something for you to play with.  Before that following is the list of Links to those Articles. It is better if you take a look at them before continuing. You will be in a better position to understand it, appreciate its usefulness, and can enjoy working with its methods.

  1. Learn 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 above is an image of an MS-Access Form where you can enter a Decimal Number, ranging between 0 and 16777215 (equal to a maximum of 24 Bit Binary Value), and get it converted into a Binary Number.  At the same time, the number entered into the TextBox will be used for generating the RGB Color that will be displayed at the top color band, where the binary bit positional sequence numbers are shown. Logically, you can display a total of over sixteen million colors on the top color band on the form.

If you look closely at the image above, you can see that the value 65535 is entered into the text box and the Binary digits 1111111111111111 are appearing in the gray band above the Text Box.  The decimal value equal to each bit position is in the red font color of the labels arranged vertically above the binary digits. If you add up all those red-colored values together, you will get the result equal to the value in the text box.

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

Binary bit number 0 to 7 (8 bits) values give the Red Color and bit number 8 to 15 (8 bits) values from the Green Color.  When Red and Green Colors are mixed you will get Yellow Color shown on top of the Red, Green & Blue Color bands.

Let us make a little modification to the above sample color by subtracting some bit values, and see how the color changes on the top color band.  Click on the labels with the values 4096 and 64 one by one.  These values are moved into the TextBox and will be subtracted from 65535 (the sample number already appearing in there). The color of the labels changed back to its default color black.  Click on the Command Button with the label Convert. The result value (RGB Number) appears in blue color below the text box and the RGB Color of that number is now showing on the top color band. See the image given below:

If you want to add some more color (Red, Green, or Blue) to the existing color number you can click on the labels with numbers in black color, mix the color above those labels, and click Convert Command Button to show the result on the top band.  The intensity of the color added depends on the magnitude of the number selected from within the respective color band. The color of the label clicked will change to red indicating that the value is added to the color number.

If you click on the labels with red-colored font again, it will change to black indicating that those values will be subtracted from the color values.  You must click on the Convert Command Button to evaluate the final color value and display the color on the top color band. Every time the Binary digits of those values will also appear in the gray band above the Text Box as well.

To reset everything back to the default setting, click on 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 into the TextBox and Click on the Convert Command Button.
  2. Enter a valid expression into the Text Box like 2^10+2^5+5*25+1638 and click Convert Command Button.
  3. Click on the labels showing the binary digit values underneath Red, Green & Blue color bands to pick those color numbers and mix them together to create a new color. Each value clicked will be added to the Text Box in the form of an expression. Each Label clicked will change its font color to Red indicating it is added to the color number and if any of those labels are clicked again that color value will be subtracted and the label font color will change back to default black.  When done, click Convert Command Button.
  4. You can use a mix of all the three methods given above to input a valid expression to arrive at a valid value between 1 and 16777215 (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 while designing your Forms or Controls to set the Background Color, Foreground Color, or Border Color on the Property Sheet of the Form or Control.  If you are a Web Designer, convert the Color Number into the HexaDecimal Number, and use it on the Style Sheets.  You can call the Function HEX$(Decimal Number) in Debug Window to convert it into a HexaDecimal value.  Use the color value in the 24-bit format like #0000FF for decimal color value 255.

Enter the number 16777215 in the Text Box and click 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

Introduction

You may find several pieces of gadgets like Clocks, Wrist Watches, and so on around you to check the Date and Time.  How about inserting a Digital Clock into your Project's Main Switchboard Form so that your User can check the Date and Time with a casual glance in the middle of their normal work without interrupting what they are doing?

Besides all that it is a matter of style to put an animated Digital Clock on the Main Switchboard.  It takes only a few lines of VBA Code and a Label control on the Form.

We can stop the Clock when you open other Forms over the Main Switchboard and re-start the Clock with the current time when the Main Switchboard becomes active again.

If you have not started using VBA in your Databases and don't know where to begin then this is the time to learn something interesting and simple.

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 on the Label Tool (button face with the letter Aa on it).

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

    I have used a copy of the Main-Switchboard Form from Microsoft Access Sample Database - Northwind. An image of the Form in Design View, with a Label Control inserted, is given below:

  6. Type at least one character (any character) in the Label control otherwise the label control will get deleted when you click somewhere else.

  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

    Now, we need two lines of VBA Code to start running our Digital Clock. One line of code to start running the IntervalTimer of the Form through Form_Load() Event Procedure, immediately after the Switchboard Form is open.

  9. Click on the top left corner of the Form, where the Horizontal and Vertical Rulers meet, to select the Form. Now you will see the Form-level Property Values in the Property Sheet you displayed earlier. If you have closed the Property Sheet follow Step-7 above to display the Property Sheet of the Form.

  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 Sheet 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 says that the program control should be passed to the Form's Timer Sub-Routine (we will write the code for that next) at every one-second interval. So whatever program we will write in the Timer Sub-Routine will be executed sixty times per minute or once every second. We will write a one-line Code in the Timer Sub-Routine to take the System Date and Time and update the Caption of the Label we have created at the beginning. So, we will be seeing a continuous-time change every second.

  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 giving spaces and other punctuations 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 may 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 change of time is updated every second.

When you open other Forms or run different programs or macros the Main Switchboard may become inactive and we can turn off the clock temporarily till the Main Switchboard become active again. This will help other programs to run faster without interruption from the digital clock taking time to update the label on the Main Switchboard.

We will write two more lines of code for the On Deactivate() and On Activate() Event Procedures to turn Off (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 VBA Module of the Form (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 Forms over the Main Switchboard from your database.

  7. Click on the Title Area of the second Form and drag 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/Time again.

Technorati Tags:
Share:

Color and Picture in Message Box

Introduction - Access2003

Image of a Microsoft Access Message Box, with the use of Office Assistant, is shown below. The Message Box pops up after the User changes the Appointment Date field value with a new date and the Message Alert asks the User to reconfirm whether she really needs to replace the earlier Date 20/07/2009 with the new value 25/07/2009 or not.

The Field Name text is underlined and field values (old and new) are displayed in different colors. Company-Logo is displayed 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}" of 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 Tools Menu.
    • Find Microsoft Office 11.0 Object Library (or whatever Version 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 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 visibility of the actual data displayed within the message text with underline and Color. It catches the eye of the User quickly and looks 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) embedded 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 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 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 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 may copy the text string part of the above examples into the first program given 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 only difficulty you may experience while formatting the message text is to type all the codes in curly brackets and it is likely that you may make errors in balancing the opening or closing brackets. In such cases, part of the message text or the field values added to it will not appear in the Message Box when displayed.

There is an easy way out of this problem. Define all the above Color Codes as Global Constants in VBA Standard Module and use the Constants wherever we need them in the message text. You can declare the Color Values as Constants in a Standard Module like the following:

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 re-write 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 Company Logo above the Message Text (or below if you like) you can use two types of Images, Bitmap Image (bmp) or 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 wmf Image without the sizing_factor Value as well.

The complete Global Constant declarations for the above Color values are given below. You may copy them into the Standard Module of your Common Library Database to use across your Applications on the Network or into one of your Databases to try them out before implementing it in your 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 may modify the Image Path on the first line to point it to the Bitmap Image on the Network's common folder accessible to your Application Users so that all your MS-Access Applications on the Network can use this 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,. . . " 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 on 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 like Christmas or Valentine's Day, you can replace the Company Logo Image with other images suitable to these occasions to give surprises to your Application Users.

Check the sample Message Boxes with Christmas Images:

Or the Image of King of Pop Music:

Note: This feature works in Access 2003 or earlier versions of Access only.

Image Source: Brittanica Encyclopedia.

Share:

Form Background with Gradient Color

Introduction

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

For example, if the user is keying in data from a pre-printed Document like a Telephone Bill or Electricity Bill etc.; it is a good idea to scan an image of this Document and use it as the Data Entry Form's background picture. 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 has several images to use as a background picture, but I didn't find the one that I need; the one with a gradient background. So, I thought I would make one of my own and use it.


Creating a Sample Image

The steps that I have taken 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 Bit Map Image:
  2. Selected Format - - >Background - - > Fill Effects.
  3. Under Colors, options 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. Push the Prt Scrn key (at the top row right side). The full-screen image is now captured and copied to Clipboard.
  11. Opened 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 before capturing it in MS Paint.
  15. Use Ctrl+C to copy the selected area into Clipboard.
  16. Clicked outside the selected area to deselect the earlier selection.
  17. Selected Clear Image from 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 de-select 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 adjusted the right side of the image.
  22. Selected Save from File Menu to save the image at a convenient location with a name.

If you were with me so far then we will enter into the next stage of implementing the gradient image as a background picture. But, there are some limitations to using images like this one as a background picture, but we can overcome this with a little trick. If you are thinking about the increase in the size of the database then you are in the right direction. If you are considering the idea of saving the image in .jpeg or .GIF format; then you are far ahead of me. Saving the image in .GIF format in MS Paint will not give you a good quality image. If you have software like Adobe Photoshop then you can make better quality .GIF images.

We will do another trick to use the .bmp image itself to maintain the background image quality without affecting the database size.

But, first, let us see how to apply the gradient image as the Form's Background picture.

Inserting the Image on the Form Background

Before opening your database if you would like to check the present size of your database you may open Windows Explorer, check and note down the current size of the database. I suggest you better Compact the Database before you take its file size. You may check it again after the background picture is added to a Form to find the difference.

  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 on the build button (. . .) at the right side of the Property Sheet and click on 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 choices Embedded or Linked to select from and the default value is embedded. The embedded option is provided for invoking the default Image Editor Program from within MS-Access by double-clicking on the image and making changes to the image if needed. To facilitate this; the necessary image editor program invocation information is also stored along with the image in the database, resulting in a substantial increase of the database size for each image you add this way on your Form or Report. But, the background image inserted this way cannot be edited by double-clicking on the background as we do on the inserted image as an OLE object, on the Form.

A better choice is the Linked option which will keep the image outside and the database size is not affected. In either case, the image should go along with your database in the same location as the image wherever you take your database.

The Picture Size Mode has three options Clip (default) displays the picture in actual size wherever you position it by setting one of the Picture Alignment property Values (Top Left, Top Right, Bottom Right, Bottom Left, Center, and Form Center). The Center option will position the image vertically and horizontally centered on the Form and the Form Center option will position the image vertically centered on the left side.

The Stretch/Zoom/Tile Picture Methods

The Stretch Picture Size Mode option will stretch the image to fit the dimension of the Form and result 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 very much 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 that will give a good quality gradient picture effect and the image size also will be small.

  1. Open the earlier saved .bmp image in MS Paint Program.
  2. Select Attributes. . . from Image Menu.
  3. Change the Width value to 1 and let the Height value remain without change.
  4. Check the Units selected is 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 will 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

Introduction.

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 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 of them must be named in such a way that we could address them easily in code. A sample design is given below:


Automating the Labels Creation

There are about 42 identical Labels to create. Even if we create them once manually, arranging them in this fashion is not an easy task. But we can do it with a small Program. The Program creates a new Form and creates all 42 Labels, and gives names like lbl1 to lbl42, changes other Properties as shown 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.

    Every time when the code is run it will create a new Form with the Labels arranged in a zigzag form. After you create it once, export that Form to your other Projects where you want to install the ZigZag Ticker. Or better you may install 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 somewhere outside the Labels and drag over them so that all the Labels are selected without disturbing the arrangement of the labels.
  4. Select Copy from 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 provide useful information to display to the User as a reminder. Refer to the earlier example Reminder Ticker Form which uses information from within the Application for 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:

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:

    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