Earth and Sun at December Solstice drawn by Access Ms Access Gurus

If you learn something, please help support this site, thank you. Happy Solstice

Draw December Solstice in Access

Draw the Earth on its orbital path around the sun when it's at the position for the Winter Solstice in the Northern hemisphere. See how Earth's tilt causes part of the planet to not get any light, such as in Northern Norway.

VBA procedure that's easy to call from code behind your reports. Send the report object, center coordinate and orbit radius for the Winter Solstice with Earth and Sun. Optionally, you can choose colors for different objects.

The code that does the drawing is all in one module that you can easily import into your projects. Uses Circle, Line, and Print methods.

Show Earth and Sun at December Solstice on an Access report

Quick Jump

Goto Top  


Download

Download zipped BAS file you can import into your Access projects: bas_Draw_SolsticeDecember_s4p.zip

Download zipped ACCDB file with a sample report and a module: Draw_SolsticeDecember_s4p__ACCDB.zip

If you have trouble with a download, you may need to unblock the ZIP file, aka remove Mark of the Web, before extracting the file. Here are steps to do that: https://msaccessgurus.com/MOTW_Unblock.htm

Goto Top  

Try it yourself

There is 1 sample report you can play around with

Goto Top  

VBA

Standard module

'*************** Code Start ***************************************************
' Purpose  : draw the December Solstice on an Access report
'             specify center coordinate and orbital radius
'             optionally set colors for Earth, Sun, Rays, and lines
'           USES Circle, Line, Print
' Author   : crystal (strive4peace)
' Code List: www.msaccessgurus.com/code.htm
' This code: https://msaccessgurus.com/VBA/Draw_SolsticeDecember.htm
' LICENSE  :
'   You may freely use and share this code, but not sell it.
'   Keep attribution. Mark your changes. Use at your own risk.
' bas_Draw_SolsticeDecember_s4p
'------------------------------------------------------------------------------
'           Global variables
'------------------------------------------------------------------------------
'comment if defined elsewhere
Public Const PI As Double = 3.14159 
Public Const gColorYellowSun As Long = 7664895  'RGB(255, 244, 116) 'sun
Public Const gColorOrangeRay As Long = 3333375  'RGB(255, 220, 50)
Public Const gColorBlueEarth As Long = 16646420  'RGB(20, 1, 254)
Public Const gColorGray As Long = 6579300  'RGB(100,100,100)

'------------------------------------------------------------------------------
'           Draw_SolsticeDecember_s4p
' send report object, sun center coordinate and radius
'------------------------------------------------------------------------------
Public Sub Draw_SolsticeDecember_s4p(poReport As Report _ 
      ,pXCenter As Single _ 
      ,pYCenter As Single _ 
      ,pRadiusOrbit As Single _ 
   ,Optional pnColrEarth As Variant = gColorBlueEarth _ 
   ,Optional pnColrAxis As Variant = vbBlack _ 
   ,Optional pnColrOrbit As Variant = gColorGray _ 
   ,Optional pnColrSun As Variant = gColorYellowSun _ 
   ,Optional gColorSunRay As Variant = gColorOrangeRay _ 
   ) 
'221221 s4p
'Draw a Solstice
'   measurements in twips

   On Error GoTo Proc_Err 
   'PARAMETERs
   '  poReport is the Report object
   '  pXCenter is x-coordinate of sun center
   '  pYCenter is y-coordinate of sun center
   '  pRadiusOrbit is orbit radius
   
   '(Optional) -- long integer color values
   '     defined as Variant so they can be null
   '  pnColrEarth
   '  pnColrAxis
   '  pnColrOrbit
   '  pnColrSun
   '  gColorSunRay
   
   If IsNull(pnColrEarth) Then pnColrEarth = gColorBlueEarth 
   If IsNull(pnColrAxis) Then pnColrAxis = vbBlack 
   If IsNull(pnColrOrbit) Then pnColrOrbit = gColorGray 
   If IsNull(pnColrSun) Then pnColrSun = gColorYellowSun 
   If IsNull(gColorSunRay) Then gColorSunRay = gColorOrangeRay 

   'variables
   Dim X As Single,Y As Single _ 
      ,x1 As Single,y1 As Single _ 
      ,x2 As Single,y2 As Single _ 
      ,sgRadiusSun As Single _ 
      ,sgRadiusEarth As Single _ 
      ,sgRadiusAxis As Single _ 
      ,sgAspectOrbit As Single _ 
      ,sgAngleAxis As Single _ 
      ,sgAngle As Single 

   '----------------------------- customize as desired
   sgRadiusSun = pRadiusOrbit * 0.2 
   sgRadiusEarth = sgRadiusSun * 0.75 
   sgRadiusAxis = sgRadiusEarth * 1.4 
   sgAspectOrbit = 0.4 
   '-----------------------------
   sgAngleAxis = (90 + 23.4) / 180 * PI 
   
    With poReport 
      
      .ScaleMode = 1  'twips

      'orbit
      .FillStyle = 1  'Transparent
      .DrawWidth = 4  'pixel
      poReport.Circle (pXCenter,pYCenter) _ 
         ,pRadiusOrbit,pnColrOrbit,,,sgAspectOrbit 
      
      .DrawWidth = 1  'pixel
   
      'draw sun rays
      For sgAngle = 0 To 2 * PI Step PI / 12 
         x1 = pXCenter + Cos(sgAngle) * pRadiusOrbit * 1.2 
         y1 = pYCenter - Sin(sgAngle) * pRadiusOrbit * 1.2 
         poReport.Line (x1,y1)-(pXCenter,pYCenter),gColorOrangeRay 
 
      Next sgAngle 

      .FillStyle = 0  'Opaque

      'sun
      .FillColor = pnColrSun 
      poReport.Circle (pXCenter,pYCenter) _ 
         ,sgRadiusSun,gColorSunRay 

      'earth center
      X = pXCenter - pRadiusOrbit 
      
      'axis
      .DrawWidth = 3 
      x1 = X + Cos(sgAngleAxis) * sgRadiusAxis 
      y1 = pYCenter - Sin(sgAngleAxis) * sgRadiusAxis 
      sgAngleAxis = sgAngleAxis + PI 
      x2 = X + Cos(sgAngleAxis) * sgRadiusAxis 
      y2 = pYCenter - Sin(sgAngleAxis) * sgRadiusAxis 
      poReport.Line (x1,y1)-(x2,y2),pnColrAxis 
      
      'S for South
      .FontSize = 24 
      poReport.Print  "S"
      
      'N for North
      .CurrentX = x1 - .TextWidth( "N") 
      .CurrentY = y1 - .TextHeight( "N") 
      poReport.Print  "N"
            
      'earth
      .FillColor = pnColrEarth 
      poReport.Circle (X,pYCenter) _ 
         ,sgRadiusEarth,pnColrEarth 
         
      'equator
      sgAngleAxis = sgAngleAxis - PI / 2 
      
      x1 = X + Cos(sgAngleAxis) * sgRadiusEarth 
      y1 = pYCenter - Sin(sgAngleAxis) * sgRadiusEarth 

      x2 = X - Cos(sgAngleAxis) * sgRadiusEarth 
      y2 = pYCenter + Sin(sgAngleAxis) * sgRadiusEarth 
      poReport.Line (x1,y1)-(x2,y2),vbWhite 
      
   End With 
      
Proc_Exit: 
   On Error GoTo 0 
   Exit Sub 
  
Proc_Err: 
   MsgBox Err.Description _ 
       ,, "ERROR " & Err.Number _ 
        &  "   Draw_SolsticeDecember_s4p"

   Resume Proc_Exit 
   Resume 
   
End Sub 
'*************** Code End *****************************************************

Goto Top  

rpt_SolsticeDecember

Code behind report to draw the December Solstice with Earth and Sun. Although different colors can be used, they aren't specified, so you see the default colors.

'*************** Code Start CBR ***********************************************
' Purpose  : code behind rpt_SolsticeDecember
'            calls Draw_SolsticeDecember_s4p
'              draw Winter Solstice on page (Landscape)
' Author   : crystal (strive4peace)
' Code List: www.msaccessgurus.com/code.htm
' This code: https://msaccessgurus.com/VBA/Draw_Solstice.htm
' LICENSE  :
'   You may freely use and share this code, but not sell it.
'   Keep attribution. Mark your changes. Use at your own risk.
'------------------------------------------------------------------------------
'           Report_Page
'------------------------------------------------------------------------------
Private Sub Report_Page() 
'221221 crystal
'draw Winter Solstice on a landscape page
   'CALLs
   '  Draw_SolsticeDecember_s4p
      
   Dim X As Single,Y As Single _ 
      ,sgRadius As Single _ 
      ,dx As Single,dy As Single _ 

   With Me 
      
      .ScaleMode = 1  'twips
      
      'width and height for drawing
      dx = .ScaleWidth 
      dy = .ScaleHeight 
      
      'X center
      X = .ScaleLeft + dx / 2 
      'Y center
      Y = .ScaleTop + dy / 2 
      
      'radius based on X
      sgRadius = (dx / 2) * 0.85 
   
   End With 
   
   'Call Draw_SolsticeDecember_s4p
   Call Draw_SolsticeDecember_s4p(Me,X,Y,sgRadius) 
      
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 method

Line method

Print method

DrawWidth property

FillColor property

Sine function

Cosine function

Goto Top  

Backstory

Yesterday was the winter solstice for me and my friends in the Northern hemisphere, which means that the sun is lowest on the horizon at its highest point, if it even shows! Last night was the longest night after the shortest day, and the first day of winter. Even though the days will get longer for us till the Summer Solstice, we have colder weather coming in the next couple months, so bundle up!

To honor this day, I wrote code in Access to show how Earth is positioned in relationship to the sun. It's not to scale because Earth would just be a dot!

Earth's relationship to the sun is hard-coded, but there could be logic to calculate position based on the day of year.

If you like this page, please let me know. Donations are always appreciated, thank you

Share with others

Here's the link for this page in case you want to copy it and share it with someone:

https://msaccessgurus.com/VBA/Draw_Solstice_December.htm

or in old browsers:
http://www.msaccessgurus.com/VBA/Draw_Solstice_December.htm

Get Help with Access and drawing

Let's connect and team-develop your application together. I teach you how to do it yourself. My goal is to empower you.

While we build something great together, I'll pull in code and features from my vast libraries as needed, cutting out lots of development time. I'll give you lots of links to good resources.

Do you want your reports to be more creative and visual? I'd love to help you. Email me at training@msAccessGurus.com

~ crystal

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

Goto Top