strive4peace

If you like my BoldMe code, please donate so I can keep on developing.
thank you

Access Basics Video Tutorials Learn VBA ListFiles Database Random Picker Error Handling Reference Database Whistles & Bells Help Examples Crystal's Analyzer Code Documenter

Boldface the label of true Checkboxes, and Selected Option in a Frame


BoldMe

go to the code
  • Bold checkbox label if checkbox is True
  • Bold chosen option label in a frame

Call code on
  • control AfterUpdate event
  • form Current event
<<<form showing bold faced labels>>

BoldMe Code

Here is the BoldMe code that should be put into a general (standard) module:

		
'~~~~~~~~~~~~~~~~~~~~~~~~~~ BoldMe Function BoldMe(Optional pF As Form _ , Optional pControlname As String = "" _ , Optional pNumOptions As Integer = 0 _ , Optional pValue As Variant _ ) As Byte '9-9-08,12-4-09 'Crystal 'strive4peace2009 at yahoo dot com 'Bold the label is the option is chosen or value is true 'remove Bold is the value is not true or the option is not chosen ' -------------------------------------------------------- 'PARAMETERS ' pF = form reference ' if in code behind a form, this is ' Me ' ' pControlName is name of control to test ' if not specified, ActiveControl will be used ' ' pNumOptions is the number of options in the frame (group) ' must be specified for option frame ' ' pValue is the comparison value for deciding Bold ' if parameter is passed ' then the opn frame will not be tested ' ' Labels MUST be named like this: ' Label_Controlname ' ' NOTE: the "label" control ' does not have to be a label ControlType ' It can be, for instance, a textbox ' -------------------------------------------------------- ' NOTES ' ' for checkboxes and toggle buttons ' ' if checkbox Name = MyCheckbox ' then label Name = Label_MyCheckbox ' ' for options in a frame ' ' if Frame Name = MyOptionFrame ' ' then Frame Option Buttons are Named: ' MyOptionFrame1, MyOptionFrame2, etc ' ' Labels for Frame Option Buttons are Named: ' Label_MyOptionFrame1, Label_MyOptionFrame2, etc ' ' Numbers in the name correspond to the Option Value ' ' Option Values can be any number ' ' -------------------------------------------------------- 'USEAGE ' BoldMe Me ' Bold the label of the ' active checkbox or toggle control ' if the control value = True ' ' BoldMe Me, "Mycheckbox_controlname" ' Bold the label of the ' specified checkbox or toggle control ' if the control value = True ' ' BoldMe Me, "Mycheckbox_controlname",,True ' Bold the label of the ' specified checkbox or toggle control ' ' BoldMe Me, "MyFrame_controlname", 4 ' Bold the label of the option ' in the specified frame control ' if the Option Value = the Frame Value ' where there are 4 options to pick from ' ' BoldMe Me, "MyFrame_controlname", 4, 999 ' Bold the label of the option ' in the specified frame control ' if the Option Value = 999 ' where there are 4 options to pick from ' ' set up error handler On Error GoTo Proc_Err ' if form reference is not specified, use the active form If pF Is Nothing Then Set pF = Screen.ActiveForm Dim mBoo As Boolean _ , mControlName As String _ , mControlnameOption As String If Len(pControlname) > 0 Then mControlName = pControlname Else mControlName = pF.ActiveControl.Name End If If IsMissing(pValue) Then pValue = pF(mControlName).Value End If ' use WITH to minimize the number of times ' this code has to access the object With pF(mControlName) ' checkbox or toggle button Select Case .ControlType Case acCheckBox, acToggleButton If IsMissing(pValue) Then mBoo = Nz(.Value, False) Else 'note: Null cannot be passed mBoo = pValue End If With pF("Label_" & mControlName) ' see if Bold is already right If .FontBold <> mBoo Then ' Bold needs to change .FontBold = mBoo End If End With GoTo Proc_Exit ' option box - MUST SPECIFY pNumOptions Case acOptionGroup Dim i As Integer For i = 1 To pNumOptions mControlnameOption = mControlName & Format(i, "0") If IsNull(pValue) Then ' if the comparison is blank ' no option will be bolded mBoo = False Else ' if the option value = the comparison value ' then mBoo = TRUE mBoo = IIf( _ pF(mControlnameOption).OptionValue = pValue, True, False) End If With pF("Label_" & mControlnameOption) If .FontBold <> mBoo Then .FontBold = mBoo End If End With Next i GoTo Proc_Exit End Select End With Proc_Exit: On Error Resume Next pF.Repaint Exit Function Proc_Err: MsgBox Err.Description _ , , "ERROR " & Err.Number & " BoldMe " & mControlName Resume Proc_Exit 'if you want to single-step code to find error, CTRL-Break at MsgBox 'then set this to be the next statement Resume End Function
Go To Top

Standard (General) Module

To Create a Standard (General) Module:
  • When you are in Access, press ALT-F11 to go to a code window.

  • From the menu in a the Microsoft Visual Basic window, choose:
    Insert —> Module This gives you a blank module sheet with any default compiler directives (Option statements) at the top.
Be sure to use the Option Explicit compiler directive at the top of each module so variables that are not declared or are misspelled will be caught when the code is compiled.
Option Explicit

  • Copy (CTRL-C) the code from this site and Paste (CTRL-V) into the module sheet below any compiler directives.

  • Once the code is in the module sheet, from the menu, choose —> Debug,Compile

    If there are no syntax/reference errors, nothing will appear to happen — in this case, nothing happening is good <g>
Make sure to give the module a good name when you save it. You can have several procedures (Subs and Functions) in a module, which gives you a way to categorize them ... ie: basic procedures that would be useful in any database; procedures that are specific to a particular database; procedures for converting data; etc

Go To Top


Now that we have this code saved in a general module, it can be used anywhere in the database.

Call BoldMe in the [Event Procedure] code* for each desired control AfterUpdate event.
* CBF (code behind form)

If your form is bound, also call BoldMe in the form Current event.


Download Database

DOWNLOAD a Sample Database for BoldMe
MainMenu_Sort123_BoldMe_Crystal_091207__MDB.zip

contents:
  • MainMenu_Sort123_BoldMe_Crystal_091207.mdb
    MDB File in Access XP (2000) format
    The first form you see is a main menu. Choose to see the example form for BoldMe or Sort123 (another whistle).

If you have comments or want to tell me how BoldMe helped you, please




Free Book on Access: Access Basics

Free Tutorials: Video Tutorials

For information on private programming and training,


Copyright © 2009 Crystal Long | All rights reserved | Last Updated Dec 2009 | Contact Webmaster for help with your web site