Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Memo field and data filtering

Introduction.

When designing tables, we carefully organize information to make it easy to retrieve through searches, filters, and queries. For example, in the Employees table of the Northwind.mdb sample database, an employee’s name is split into three separate fields—Title, FirstName, and LastName—so that each piece of information can be managed individually. These fields are also defined with specific lengths, based on the size of the source data.

However, when recording details such as an employee’s qualifications or work experience, we cannot predict the length of the text. In such cases, the Memo field type is used. A memo field allows free-form text of varying lengths, making it ideal for storing descriptive information.

That said, memo fields are not often used directly in reports or queries because their contents are unstructured and more difficult to work with. Still, they do provide some flexibility in filtering records—for example, by searching for specific text that may appear anywhere within the field.

Let’s look at a few examples of working with memo field data from the Employees table in the Northwind.mdb sample database.

Prepare for a Trial Run.

  1. Import the Employees Table from the sample database C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb.

  2. Open the Employees Table in the datasheet view.

  3. Move the horizontal scrollbar at the bottom to the right, so that the Notes Memo Field contents are visible to you.

  4. Point the mouse at the left border of the table at the intersection of the two rows so that the mouse pointer turns into a cross.

  5. Click and drag down to increase the row size so that the Notes field contents can be viewed properly.

    If you review the qualification details stored in each employee record, you’ll notice that many employees hold a BA degree. However, the text “BA” does not appear in a fixed position within the memo field—it may occur anywhere in the description. So how can we filter all employee records that include a BA degree?

    To begin, let’s try this directly in Datasheet View before moving on to writing a query that filters data based on text within a memo field.

  6. Highlight the letters BA in any one of the records and Right-click on the highlighted text.

    A shortcut menu is displayed, and the suggested options for filtering data from the Memo Field are Contains "BA" or Does Not Contain "BA".

  7. Click on the Contains 'BA' option to filter the records with the text "BA" appearing anywhere within the memo field.

If you want to filter records this way for printing a Report, then we must create Queries to filter data based on the text in the Memo Field.  You can use the Like Operator with AND, OR logical operators.

Copy and paste the following SQL Strings into the SQL Editing Window of new Queries and save them with the suggested names:

Query Name:  Employee_BAQ

SELECT Employees.LastName, Employees.FirstName, Employees.Notes
FROM Employees
WHERE (((Employees.Notes) Like "*BA*"));

The output of this Query will include a record of an employee with an MBA Degree, too, because of the text 'BA' in MBA. If you want to exclude this record, then modify the criteria with a space immediately after the first asterisk, like '* BA*'.

Query Name:   Employee_BA_BSCQ

SELECT Employees.LastName, Employees.FirstName, Employees.Notes
FROM Employees
WHERE (((Employees.Notes) Like "* BA*")) OR (((Employees.Notes) Like "*BSC*"));

The above query is an example of the usage of the logical operator OR to filter data of employees with a graduation in BA or BSC.

Query Name:   Employee_BA_BSCQ

SELECT Employees.LastName, Employees.FirstName, Employees.Notes
FROM Employees
WHERE (((Employees.Notes) Like "* BA*" And (Employees.Notes) Like "*psychology*"));

The above example demonstrates the logical operator AND, and filters the records of the employees with a graduation in BA in Psychology.

Earlier Post Link References:

Share:

Lively Controls on Form

Introduction

In most projects, our primary focus is always on completing the work on time and delivering it to the user as quickly as possible. I make every effort to stay on schedule and ensure that the user receives the application for testing without delay. However, I also like to take a second look at the overall design and appearance of the Forms and Reports in a more relaxed frame of mind. This allows me to introduce some improvements, explore new ideas, and incorporate enhancements—alongside the requirements suggested by the user.

From past experience, these little refinements have always been met with appreciation. Users often respond positively to subtle design improvements, which motivates me to keep experimenting with fresh ideas in future projects. After all, Forms are the first component that catches a user’s eye, followed by well-formatted Reports and visually engaging charts.

Forms hold a special place in the Users' minds. They should not only be functional but also visually pleasing and user-friendly. Once the core functionality of an application is complete, and if time permits, revisiting the main forms’ design can open the door for creativity. Even small visual tricks can make a significant difference. For instance, most controls we place on Microsoft Access forms are static, but by introducing a touch of movement or animation—applied tastefully and without excess—we can leave a lasting positive impression on users.

We have already explored several animation techniques for form controls in earlier discussions. If you’d like to revisit those, the links are provided below:

  1. Command Button Animation
  2. Reminder Ticker Form
  3. Startup Screen Design
  4. Animated Floating Calendar
  5. Wave Shaped Reminder Ticker
  6. Command Button Animation-2
  7. Animating Label on Search Success
  8. Run Slide Show when Form is Idle
  9. Label Animation Style-1
  10. Label Animation Style-2
  11. Label Animation Variant
  12. Label Animation Zoom in Style
  13. Label Animation in Colors
  14. Label Animation Zoom-out Fade
  15. Digital Clock on Main Switchboard

Option Group Control Style Change on Mouse Move.

In this example, we will apply a simple trick to an Option Group control to make it respond visually when the mouse moves over it. The idea is straightforward: when the Option Group is created, we set its Style property to Raised. As the mouse moves over the control, the style changes to Sunken, and when the mouse moves away, it reverts back to the original Raised state. This repeated action gives the Option Group a more dynamic and lively appearance, making the form more engaging for users.

Create a Form for Demo.

  1. Open a new Form in Design View.

  2. Click on the Wizard Button (with the magic wand icon) on the Toolbox to select it, if it is not already in the selected state.

  3. Select the Option Group control and draw it on the detail section of the form.

  4. Enter the options as shown on the design below by pressing the Tab key after each option to advance to the next row. You may enter any Text as options as you like.

  5. Complete the design by selecting the Finish Command Button.

  6. Move the attached label above and make it as wide as the Option Group Control, and change its Caption to Main Menu.

  7. Move the attached child label above and make its width the same as the Option Group control, and align it to the left edge. 

  8. Change the Caption of the label to Main Menu.

  9. Click on the Option Group to select it and display its Property Sheet (View -> Properties or press ALT+Enter).

  10. Change the following Property Values as given below:

    • Name = Frame0

    • Back Style = Normal
    • Special Effect = Raised

    The Form's Class Module Code.

  11. Display the VBA Code Module of the Form (View ->Code or click on the Module Toolbar Button or press ALT+F11).

  12. Copy and Paste the following VBA Code into the VBA Module of the Form:

    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
       If Me.Frame0.SpecialEffect <> 1 Then
           Me.Frame0.SpecialEffect = 1
       End If
    End Sub
    
    Private Sub Frame0_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
       If Me.Frame0.SpecialEffect <> 2 Then
           Me.Frame0.SpecialEffect = 2
       End If
    End Sub
  13. Save and close the Form.

    The Demo Run.

  14. Open the Form in the normal view.  You will find the Option Group control is in Raised style.

  15. Move the mouse over the control, and it will enter the Sunken state.

  16. Move the mouse pointer away from the control, and it will restore to the Raised state.

  17. Repeat this action in quick succession, and you can see how the Option Group control responds to this simple action; otherwise, it remains rigid forever.

Technorati Tags:
Share:

Create your own color palette

Introduction.

We have already explored the Binary, Octal, and Hexadecimal number systems and learned some simple rules that allow us to devise new number systems with any base value, as long as the user understands the basic rules and can interpret the numbers correctly.

In our previous session, we worked with a form that allowed us to enter decimal numbers, convert them into binary, and also display their corresponding RGB color representation.

If you would like to learn and understand Binary, Octal, and Hexadecimal Number Systems, then check the following Posts:

  1. Learn the Binary Numbering System
  2. Learn Binary Numbering System-2
  3. Octal Numbering System
  4. Hexadecimal Numbering System
  5. Colors 24-Bits And Binary Conversion.

This week, we will build a Form-based utility that will be especially useful during the design phase of a new project. With this tool, you can visually create your own 24-bit custom colors and save up to 15 colors in a color palette within the form. Any of these saved colors can then be applied to the form background, or to the foreground, background, or border color properties of other controls at design time.

For reference, an image of the Employees Form in Design View is shown below, displaying the form’s Header Section Property Sheet alongside the Color Palette Form.

The Color Palette Usage

A new custom color is created on the Color Palette Form (see the large rectangle) and then applied to the Employees Form Header Section background by setting its value in the Back Color property.

Click on the image to enlarge it. The Employees Form is shown in Design View, with the Header Section selected. Its Property Sheet is also visible, displaying the Back Color property.

When you click on any of the 15 Color Boxes (which you can create and overwrite with your own saved colors), the corresponding color value is displayed in the text box above the palette, labeled as an RGB Color. You can then copy this value (Ctrl+C) and paste it (Ctrl+V) into the Property Sheet’s Back Color, ForeColor, or Border Color property—depending on where you want to apply it—thus setting the form or control color.

In the Property Sheet, color values appear in hexadecimal format prefixed with a hash symbol (for example: #4E61BC). However, you can directly paste the decimal color value, and Access will automatically convert it into hexadecimal form.

Since we have already learned about the hexadecimal number system, I’d like to draw your attention to a small issue related to this conversion.

A Test Run.

Let us take a sample color number in decimal: 12345678. Enter (or paste) this value into the Form Header or Detail Section Back Color property and press Enter. Access will automatically convert it into a hexadecimal value, such as #4E61BC and the form background will be filled with a dark blue color.

👉 Notice the difference between the first two digits and the last two digits of the hexadecimal number—this is the key to understanding how Access interprets color values.


Checking the value in VBA

  1. Open the VBA Editor (Alt+F11).

  2. Display the Immediate Window (Ctrl+G).

  3. Type the following and press Enter:

? HEX(12345678)

The result will be:

BC614E

This is the raw hexadecimal equivalent of 12345678.

  • If you paste this number into a property in the form of #BC614E Access will display a dark red color.


Why do the results differ?

  • When you type the decimal value 12345678 directly into a color property, Access reinterprets the bytes internally and reformats them as #4E61BC in 24 Bit RGB order:

    • R = 78 (&H4E) - least significant 8-bit Value.

    • G = 97 (&H61) - middle 8-bit Value

    • B = 188 (&HBC) - most significant 8-bit value.

  • On the other hand, when you convert 12345678 using VBA’s Hex() function, you get BC614E. If this is placed directly into the property (#BC614E) Access does not remap it into RGB order—it takes it literally, which leads to a completely different color.


Conclusion

In both cases, decimal-to-hexadecimal conversion works correctly, just as in the decimal-to-binary method we discussed earlier. However, Access interprets decimal color values and hex color values differently because of the byte order applied internally.

The safest method: Always paste the decimal value into the color property and let Access handle the conversion automatically.

Creating New Colors and Saving Them in the Color Palette.

Now, we will look at the simple trick of designing new Colors (logically, there are over 16 million 24 Bit color values available) and saving them on the Color palette for later use. 

You can download a database with the above Form with the Programs from a link at the bottom of this article so that you can import this Form into your new Projects, design your own colors, and use them on your Forms or Controls.

You can click on the above image to enlarge it for a clearer view of the controls on the Form. Let us examine them one by one.

  • Scrollbars (Red, Green, Blue):
    There are three scrollbar controls to input integer values ranging from 0 to 255 for the primary colors Red, Green, and Blue.

    • Moving a scrollbar to the right increases its value, while moving it to the left decreases it.

    • Clicking on the arrow buttons at either end adjusts the value by 1 with each click.

    • Holding down an arrow button rapidly increases or decreases the value, and the color graph updates accordingly.

  • Color Bar Graphs:
    On the right of each scrollbar, a vertical bar graph provides a visual representation of the current intensity of each primary color. The corresponding numeric values also appear in the text boxes labeled Red, Green, and Blue.

  • Preview Rectangle:
    The large rectangle at the bottom-right displays the resulting color created by mixing the Red, Green, and Blue values from the scrollbars.

  • RGB Color Text Box:
    The text box labeled RGB Color shows the decimal color number representing the combined RGB value.

    • You can copy this number (Ctrl+C) and paste it (Ctrl+V) into a Form’s or Control’s Back Color, ForeColor, or Border Color property to apply the new color.

  • Saving Custom Colors:
    To preserve a newly created color:

    1. Click on the preview rectangle to select the color.

    2. Then click on one of the 15 color boxes on the left to store it there for later use (overwriting any existing color in that box).

  • Reusing Saved Colors:
    To apply a previously saved color, simply click on the desired color box. The selected color’s decimal number will appear in the RGB Color text box, ready to copy and paste into the appropriate property.

Tips

  • Modify an Existing Color:
    If you already have an RGB color number but want to adjust it, copy and paste the decimal value into the RGB Color text box (or type it directly) and press Enter. The selected color will appear in the preview rectangle, while the Red, Green, and Blue text boxes will update with their respective values. The bar chart will also provide a quick visual indication of each color component. From there, you can use the scrollbar sliders to fine-tune the color further.

  • Working with Hexadecimal Values (MS Access 2007):
    If you are using MS Access 2007, color values are displayed in hexadecimal format. To convert them into decimal numbers for use in the RGB Color text box:

    1. Open the VBA Debug window (Ctrl+G).

    2. Type: ? &hXXxxXX (replace XXxxXX with your six-digit hex value).

    3. Swap the rightmost two digits with the leftmost two digits of the hex value before conversion.

    4. The result will be the decimal equivalent, which you can copy into the RGB Color text box for modification.

  • Direct Value Entry:
    Instead of using scrollbars, you can type integer values directly (from 0 to 255) into the Red, Green, and Blue text boxes to generate a new color instantly.

Technorati Tags:

Download the Demo Database.


Download Demo RGBColor.zip

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:

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