Happy Birthday, America!
Since there aren't parades this year, or big social gatherings,
to celebrate Independence Day,
I'm making a video about how to draw
the American flag with Access …
as I listen to fireworks going off all over town.
Hi, this is crystal.
You can do a lot of drawing in Microsoft Access
with just a few commands.
This American flag was drawn with 2 methods:
Report.Line and Report.Print
The stripes and rectangles are done with Line.
Line can also draw rectangles,
which can be filled or not,
and the color can be specified.
The border around the flag isn't filled,
but the stripes and union are.
The stars in the union were done with a character
in the Wingdings 2 font, Chr(234).
Let's review the code to do this.
First, we need the dimensions for the flag
so we can be accurate.
I got the measurements from ushistory.org,
and I've put the link in the video description as well.
You can also download this code from MsAccessGurus.com
The procedure name, which is a Sub, is FlagAmerican.
It was named with "Flag" first because I plan
to figure out code for other flags too.
Most often, this code would probably be called
from code behind a report, but not necessarily.
That is why there is a parameter
for the report object (pReport)
instead of using the CodeContext object.
Next are the XY coordinates for the upper left
position of the flag that will be drawn.
Then comes the maximum width and maximum height.
Because the flag will be drawn proportionally,
these parameters are the maximum allowed
instead of the actual size.
Measurements are in TWIPs (TWenty In a Point).
There are 1440 twips in an inch.
If you're using centimeters,
and divide 1440 by
the standard conversion of 2.54 cm/inch,
you get about 450 twips,
but this isn't accurate
since twips are small.
The actual number is about
567 twips per cm.
Optionally, you can send a parameter to
fade the colors so the flag
can be rendered behind something else.
All variables that will be used are DIMensioned first.
The variable name and data type are declared.
At the top of the module is Option Explicit.
This ensures that variables are declared
when the code is compiled
so that errors in names will be picked up.
Next we see if the optional ColorSet parameter was specified.
If is anything except the default value of 0,
then colors will be faded.
Blue, Red, and Black are affected when fading
but White is always the same color.
The Width to Height ratio of the flag is 1.9
The drawing width is set to 2 points
Next, the actual height and width of the flag are calculated,
keeping the proportions
and considering the maximum dimensions sent in parameters.
x2Flag is the X coordinate of the end of the flag.
y2Flag is the Y coordinate of the bottom of the flag.
The size of the union is calculated.
The height of each stripe
is 1/13 of the flag height.
Because the start position for the first 7 stripes
depends on where the union ends,
we need to know the size of the union
before the stripes are drawn,
so the union size is calculated.
There are 13 stripes.
Only the red stripes are actually drawn though.
The 7 first stripes start where the union ends.
and the remaining stripes start at the beginning of the flag.
The report.Line method is used.
The syntax for this is odd
and intellisense doesn't work.
The first coordinate is in parentheses,
then comes a dash,
then the second coordinate in parentheses.
You can specify color
or whatever fore color is set for the report will be used.
BF is specified
B means the line will be a Box not a line
and F means it will be filled with the color.
Now the blue background of the union is drawn
To do the stars on top of the blue background,
I had to find a character in a font
that was a star,
since it turns out that the report.Print method
doesn't recognize ChrW to do Unicode characters.
The X and Y distance between each star is calculated
and the font size is set proportionally
to the height of the flag.
Now some report properties are set for the stars:
font name, font size, and foreground color.
The width and height of each star is calculated.
The Y coordinate will be whatever was passed
for the flag's Y coordinate
plus the Y spacing for stars minus 1/2 the height of each star.
Now we have 5 sets
of 2 rows of stars
except the last set only has one row.
The first row is 6 stars
and the second row is 5 stars
CurrentX and CurrentY are the coordinates for the Print method,
which specifies the star character.
The next x position is calculated
and the inner loop continues for the first row.
Then the X coordinate is set
to the beginning of the line plus some space
The Y coordinate moves down
and the row with 5 stars is drawn
if j isn't on 5 for the last set of rows.
The Y position for the next row is set
and the loop continues.
Finally, a box is drawn around the whole flag image.
Only the B parameter is specified,
so it will be a box not a line, and it isn't filled.
That's it. Now you can draw an American Flag with Access
Do you have a logo, or other graphic that Access could draw?
Let's connect
I can help you figure it out.
While this might not be our best year on record,
and we clearly have a long way to go
to be a nation of equality,
I am grateful and proud to call this country my home.
Thanks for joining me
When the tide comes in, all the boats rise
Through sharing, we all get better.