circles on an Access Report Ms Access Gurus

Support this site by helping with costs, thank you.

VBA to Draw Circles for Yes/No Values on an Access Report

Visualize Yes/No data with something better than a checkbox. Use the VBA CIRCLE method to draw circles in the Detail section of an Access report, so the drawing changes according to the data on each record. A simple circle can do a lot of different things, and this is just the tip of the iceburg!

2 records showing True and False drawings

Quick Jump

VBA

Goto Top  


Downloads and Documents

The download ACCDB database has a query and report to draw circle examples for YesNo data, as shown above. The data comes from a table of numbers and is created with expressions.

If you explore, you'll also find the beginning of a clock ... the face without the mechanics. This is drawn by code in a standard module just using the Circle method. All you have to do is call it, and send it your control so the code knows how big and where to put the clock (the easy but not most efficient way). Down the road, Line can be used to draw the hands, and then the clock can be more useful.

Many circles to draw a clock face in Access

File name   Description and Link 
ReportDraw_CIRCLE_YesNo_s4p__ACCDB.zip   Accdb in a Zip file with VBA to draw each of the examples using Circle on an Access report.
download ACCDB
r_CIRCLE_1_YesNo.pdf   Access report as a PDF showing circles for each record of a report.
r_CIRCLE_1_YesNo.pdf

Goto Top  

Yes or No Circle Report

Print Preview

This report shows various ways to indicate True or False using a circle. Some of these examples aren't practical, but are shown to share different uses of Circle with you. Ideally, the code to call 'standard' drawings would be in a standard module, and we'll get there ... . This example has all the code behind the report so it's easier to learn.

  1. A Blue circle is drawn if True, or not if False.
  2. A Red circle is drawn. If True, it is filled. If False, its FillStyle is transparent.
  3. On/Off - Top is On (True), Bottom is Off (False)
  4. Switch - Left is Off (False), Right is On (True)
  5. Semi-Circle Top or Bottom - Top is True (Color of circle, or part, and its FillColor can be different colors), Bottom is False
  6. Semi-Circle Left or Right - Left is False, Right is True

circles show or don't, or are filled or open

Goto Top  

Big Checkbox

... and if you really don't want a circle at all, but a bigger checkbox, this report does that too. See the big orange or yellow textbox that looks like a checkbox next to the tiny standard checkbox on the left? The ControlSource is an expression specifying a Unicode character using the ChrW function. It obviously doesn't use the Circle method, and is easily scaled by changing the Font Size.

=IIf( [ValueYesNo] <> False, ChrW(9745), ChrW(9744) )

oh, and because it's a textbox, it can have Conditional Formatting. Here, False has an orange background, and True is colored yellow. Or the background color can be set to something specific, or changed with VBA. The font color can also be specified.

go to video

Goto Top  

Design View of Report

Here is the design view of the report. Label controls are used to define where circles will be drawn. They aren't necessary but its easier to visualize where the circles will be. Change the size and position of each drawing by changing each respective control.

design view shows labels that define circle boundaries

Goto Top  

Syntax

Circle syntax

Draw circle, ellipse, or arc

Report.Circle Step (x,y), Radius, Color, StartAngle, EndAngle, Aspect

Circle information and parameters

Goto Top  


Video

As a preamble to the video that covers drawing the circle diagrams shown on this page (in production), I made a quick video about using a big checkbox that can be colored and sized instead of the built-in checkbox control. This is great when all you want is something bigger or to specify other formatting like background or font color.

Displaying bigger checkboxes is even easier on a report! The ControlSource can be simply set to the expression that results in what you want to show based on data.

Watch on YouTube: Big Checkbox in Access with Conditional Formatting (2:18)

Goto Top  

VBA behind the report

Since colors are used on every record, their Long Integer RGB values are defined in the ReportHeader_Format event. Circles are drawn (or not) on each record using the Detail_Print event.

Option Compare Database 
Option Explicit 
' Draw Circles to show various methods to indicate True or False values
'*************** Code Start *****************************************************
' code behind report: r_CIRCLE_1_YesNo
' Report Draw Reference:
'  https://msaccessgurus.com/VBA/ReportDraw_Reference.htm
' VBA and download with this example:
'  https://msaccessgurus.com/VBA/Draw_Circle_1_YesNo.htm
'-------------------------------------------------------------------------------
' Purpose  : draw using the Circle method
'            change center, radius,
'            FillStyle, FillColor, and specified Color
' Author   : crystal (strive4peace)
' Code List: www.msaccessgurus.com/code.htm
'-------------------------------------------------------------------------------
' LICENSE
'   You may freely use and share this code, but not sell it.
'   Keep attribution. Use at your own risk.
'-------------------------------------------------------------------------------
'-------------------------------------------------------------------------------
'           Module variables for Color, define PI
'-------------------------------------------------------------------------------
Private mnColorRed As Long _ 
   ,mnColorBlueMedium As Long _ 
   ,mnColorYellow As Long _ 
   ,mnColorBlack As Long _ 
   ,mnColorGray As Long 
   
Private Const PI = 3.14159 'usually this would be global

'-------------------------------------------------------------------------------
'           ReportHeader_Format
'-------------------------------------------------------------------------------
Private Sub ReportHeader_Format(Cancel As Integer,FormatCount As Integer) 
   'define colors
   mnColorRed = RGB(255,0,0) 
   mnColorBlueMedium = RGB(0,100,255) 
   mnColorYellow = RGB(255,255,0) 
   mnColorBlack = 0 
   mnColorGray = RGB(200,200,200) 
End Sub 

'-------------------------------------------------------------------------------
'           Detail_Print
'-------------------------------------------------------------------------------
Private Sub Detail_Print(Cancel As Integer,PrintCount As Integer) 
'draw circles on each record depending if the value is True or False
'220628 strive4peace

   Dim iValue As Integer _ 
      ,xCenter As Single _ 
      ,yCenter As Single _ 
      ,sgRadius As Single 
      
   Dim xLeft As Single _ 
      ,xWidth As Single _ 
      ,yTop As Single _ 
      ,yHeight As Single _ 
      ,nColor As Long _ 
      ,i As Integer 
      
   ' iValue is ValueYesNo
   ' (xCenter, yCenter) is the circle center coordinate
   ' sgRadius is the circle radius
   ' use Label controls for boundaries
   
   With Me 
      '-----------  set up drawing space
      .ScaleMode = 1  'twips, default
      .DrawWidth = 1  'pixel
      'it circle is filled, color it black
      
      'get Value
      iValue = Nz(.ValueYesNo,0) 
	  

Goto Top  

True= Blue Circle False= Nothing

      ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ShowOrNot
      '----------- Label_ShowOrNot
      If iValue <> 0 Then 
         'if value is True then draw a circle
         ' in the middle of the
         ' Label_ShowOrNot control
         With .Label_ShowOrNot 
            '--- radius of circle is limited by width or height
            If .Width > .Height Then 
               sgRadius = .Height / 2 
            Else 
               sgRadius = .Width / 2 
            End If 
               
            '--- center coordinate for the circle
            xCenter = .Left + .Width / 2 
            yCenter = .Top + .Height / 2 
         
         End With 
         
         'filled circle
         .FillStyle = 0  'opaque
         'fill color is blue
         .FillColor = mnColorBlueMedium 
         '----- draw a circle
         '      middle is (xCenter, yCenter)
         '      radius is sgRadius
         '      outline color is blue
         Me.Circle (xCenter,yCenter),sgRadius,mnColorBlueMedium 
         
      End If 

Goto Top  

True= Blue Circle False= Blue Circle

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FilledOpen
      '----------- Label_FilledOpen
      With .Label_FilledOpen 
         'draw an open or closed circle in the middle of
         ' the Label_FilledOpen control
         '--- radius of circle is limited by width or height
         If .Width > .Height Then 
            sgRadius = .Height / 2 
         Else 
            sgRadius = .Width / 2 
         End If 
            
         '--- center coordinate for the circle
         xCenter = .Left + .Width / 2 
         yCenter = .Top + .Height / 2 
      
      End With 
      
      If iValue <> 0 Then 
         'if value is True then filled red circle
         .FillStyle = 0  'opaque
         .FillColor = mnColorRed 
      Else 
         'if the value is False, then an open circle
         .FillStyle = 1  'transparent
      End If 
      '----- draw a circle
      '      middle is (xCenter, yCenter)
      '      radius is sgRadius
      '      outline color is red
      Me.Circle (xCenter,yCenter),sgRadius,mnColorRed 	  

Goto Top  

True= Blue Circle False= Blue Circle

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OnOff
      ' height is split in 2 circles
      '----------- Label_FilledOpen
      With .Label_OnOff 
         '--- radius of circle is limited by width or half height
         If .Width > .Height / 2 Then 
            sgRadius = .Height / 4 
         Else 
            sgRadius = .Width / 2 
         End If 
         
         'horizontal center is the same for both
         xCenter = .Left + .Width / 2 
         
         'yCenter will be calculated
         yTop = .Top 
         yHeight = .Height 
         
      End With 
      
      .FillStyle = 0  'opaque
      
      '----- Top and Bottom Circles
      For i = 0 To 1  'Top then bottom
         'Circle vertical center
         yCenter = yTop + yHeight / 4 _ 
            + i * sgRadius * 2 
            
         'top circle is ON
         'bottom circle is OFF
         
         If iValue <> 0 And i = 0 Then 
            'True is filled black circle
            nColor = mnColorBlack 
         Else 
            nColor = mnColorGray 
         End If 

         '----- draw a circle
         '      middle is (xCenter, yCenter)
         '      radius is sgRadius
         '      outline color is nColor
         .FillColor = nColor 
         Me.Circle (xCenter,yCenter),sgRadius,nColor 
      Next i 

Goto Top  

True= Blue Circle False= Blue Circle

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Switch
      ' width is split in 2 circles
      '----------- Label_Switch
      With .Label_Switch 
         '--- radius of circle is limited by height or half width
         If .Width / 2 > .Height Then 
            sgRadius = .Height / 2 
         Else 
            sgRadius = .Width / 4 
         End If 
         
         'vertical center is the same for both
         yCenter = .Top + .Height / 2 

         'xCenter will be calculated
         xLeft = .Left 
         xWidth = .Width 
         
      End With 
      
      '----- Left and Right Circles
      For i = 0 To 1  'Left then right
         'Circle horizontal center
         xCenter = xLeft + xWidth / 4 _ 
            + i * sgRadius * 2 
            
         'left circle is OFF
         'right circle is ON
         
         'if drawing left circle, color is gray
         'if drawing right circle, color is black
         If i = 0 Then 
            nColor = mnColorGray 
         Else 
            nColor = mnColorBlack 
         End If 
         
         '  if value is false and on left then fill
         '  if value is true and on right, fill
         If iValue = 0 And i = 0 _ 
               Or iValue <> 0 And i = 1 _ 
            Then 
            .FillStyle = 0  'opaque
         Else 
            .FillStyle = 1  'transparent
         End If 

         '----- draw a circle
         '      middle is (xCenter, yCenter)
         '      radius is sgRadius
         '      outline color is nColor
         .FillColor = nColor 
         Me.Circle (xCenter,yCenter),sgRadius,nColor 
      Next i 

Goto Top  

True= Blue Circle False= Blue Circle

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TopBottom
      '----------- Label_TopBottom
      With .Label_TopBottom 
         '--- radius of circle is limited by height or width
         If .Width > .Height Then 
            sgRadius = .Height / 2 
         Else 
            sgRadius = .Width / 2 
         End If 
         
         'center is the same for both
         xCenter = .Left + .Width / 2 
         yCenter = .Top + .Height / 2 
         
      End With 
      
      .FillStyle = 0  'opaque
      'if filled, it will be yellow
      .FillColor = mnColorYellow 
      
      '----- Top and Bottom Half Filled Circles
      '----- draw a circle
      '      middle is (xCenter, yCenter)
      '      radius is sgRadius
      '      outline color is Blue
      
      If iValue <> 0 Then 
         'top half is True
         '  angle is 0 to PI
         '     negative indicates fill, the angle is positive
         '  instead of 0, use very small number
         Me.Circle (xCenter,yCenter),sgRadius,mnColorBlueMedium _ 
            ,-0.000000001,-PI 
      Else 
         'bottom half is False
         '  angle is PI to 2*PI
         Me.Circle (xCenter,yCenter),sgRadius,mnColorBlueMedium _ 
            ,PI,2 * PI 
      
      End If 

Goto Top  

True= Blue Circle False= Blue Circle

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LeftRight
      '----------- Label_LeftRight
      With .Label_LeftRight 
         '--- radius of circle is limited by height or width
         If .Width > .Height Then 
            sgRadius = .Height / 2 
         Else 
            sgRadius = .Width / 2 
         End If 
         
         'center is the same for both
         xCenter = .Left + .Width / 2 
         yCenter = .Top + .Height / 2 
         
      End With 
      
      .FillStyle = 0  'opaque
      .FillColor = mnColorBlack 
      
      '----- Left and Right Half Filled Circles
      '----- draw a circle
      '      middle is (xCenter, yCenter)
      '      radius is sgRadius
      '      outline color is Blue
      '  angle is negative to indicate fill
      If iValue <> 0 Then 
         'right is true
         'angle2 has to be >= angle1
         'and circle can't go past 360° or 2 Pi radians
         'so it is drawn in 2 parts
         Me.Circle (xCenter,yCenter),sgRadius,mnColorBlack _ 
            ,-0.0000001,-PI / 2 
         Me.Circle (xCenter,yCenter),sgRadius,mnColorBlack _ 
            ,-3 / 2 * PI,-2 * PI 
      Else 
         'left is false
         Me.Circle (xCenter,yCenter),sgRadius,mnColorBlack _ 
            ,-PI / 2,-3 / 2 * PI 
      End If 
      
      ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
   End With  'Me
End Sub 
'*************** Code End *******************************************************
' Code was generated with colors using the free Color Code add-in for Access.

Goto Top  

Reference

Drawing Reference on MsAccessGurus

Report Draw Reference for VBA syntax and help for drawing on Access reports.

Circle syntax, parameters, and help

RGB Function

Goto Top  

Backstory

True or False is easy -- just one or another. There is a lot you can do with simple circles though. These are ideas to get you started.

Before we can go to more complex drawings, the Line method needs to be explored. And then drawings can have hands on a clock, needles, section lines, and other visual indicators that Circle can't do alone.

Green, Yellow, and Red Stoplights

If you like this basic circle page, please express your appreciation, thank you.

Share with others

here's the link for this page in case you want to copy it:
https://msaccessgurus.com/VBA/Draw_Circle_1_YesNo.htm

Get Help with Access

Let's connect and team-develop your application together. I teach you how to do it yourself. As needed, while we build something great together, I'll pull in code and features from my vast libraries, cutting out lots of development time.

Do you want to incorporate more drawings on your reports? Do you want some ideas? For training and programming, email me at training@msAccessGurus.com

Donations are always welcome

~ crystal

the simplest way is best, but usually the hardest to see

Goto Top