<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-777975398841809391</id><updated>2026-03-24T00:56:31.679-07:00</updated><category term="VBA"/><category term="forms"/><category term="query"/><category term="functions"/><category term="tutorial"/><category term="Controls"/><category term="calculated control"/><category term="combo box"/><category term="design"/><category term="external data"/><category term="reports"/><category term="text box"/><category term="DAO"/><category term="intermediate"/><category term="many to many"/><category term="properties"/><category term="relationships"/><category term="tables"/><category term="Action Query"/><category term="MS Access"/><category term="MS Excel"/><category term="SQL"/><category term="calculated field"/><category term="filters"/><category term="sub procedures"/><category term="subform"/><category term="Access Options"/><category term="DateDiff"/><category term="If Then Else"/><category term="Loops"/><category term="Option Button"/><category term="Option Group"/><category term="access tip"/><category term="advanced"/><category term="class module"/><category term="client/server"/><category term="custom function"/><category term="dLookUp"/><category term="events"/><category term="export"/><category term="expressions"/><category term="graphical user interface"/><category term="import"/><category term="intermediate tip"/><category term="linking"/><category term="module"/><category term="one to many relationship"/><category term="parameter"/><category term="recordset object"/><category term="scope"/><category term="static"/><category term="summary data"/><category term="variables"/><category term="Append Query"/><category term="Conditional Formatting"/><category term="Crosstab Query"/><category term="DSum"/><category term="DateAdd"/><category term="DatePart"/><category term="Debug"/><category term="FormatDateTime"/><category term="GUI"/><category term="IIf"/><category term="Immediate Window"/><category term="LIKE operator"/><category term="MS Word"/><category term="Mail Merge"/><category term="Quick Tip"/><category term="Update Query"/><category term="access screen"/><category term="argument"/><category term="class object"/><category term="custom&#xa; object"/><category term="data access"/><category term="data analysis"/><category term="database objects"/><category term="dialog"/><category term="enabled"/><category term="formatting"/><category term="group by"/><category term="inner join"/><category term="make table query"/><category term="not in list"/><category term="order management"/><category term="order management system"/><category term="outer join"/><category term="primary key"/><category term="project"/><category term="record source"/><category term="rich text formatting"/><category term="subquery"/><category term="sum"/><category term="table relationships"/><category term="wildcard"/><title type='text'>Microsoft Access Tips</title><subtitle type='html'>Tips and Information for people wanting to explore the Microsoft Access Database.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default?start-index=26&amp;max-results=25'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>76</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-64619937163422682</id><published>2025-08-25T14:10:00.000-07:00</published><updated>2025-08-25T14:10:22.015-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="data analysis"/><title type='text'>Analysing Data with Access Crosstab Queries</title><content type='html'>&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;In the previous blog post, we used a data set
downloaded from the UK based HM Land Registry website to demonstrate how Access
can be used in the context of &lt;a href=&quot;https://ms-access-tips.blogspot.com/2025/05/using-access-for-data-analysis.html&quot; target=&quot;_blank&quot;&gt;Data Analysis&lt;/a&gt;.&amp;nbsp;
As you may remember, the data set contained details of 2023 house sales
in the Salford area of Greater Manchester, and we created a series of Access
Queries to count the number of sales which occurred in seven separate price
bands. This gave us an overview of what had occurred in the Salford area
housing market that year.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;In today’s post we are going to process the
same data set with an &lt;i&gt;Access Crosstab Query&lt;/i&gt; to give us a breakdown of &lt;i&gt;average
house sale price&lt;/i&gt; by &lt;i&gt;property type&lt;/i&gt; and &lt;i&gt;postcode&lt;/i&gt; area.&amp;nbsp; This will show us the differences in average
house sale price according to where a property is located and the type of
building it is (ie whether the property is detached, semi-detached, terraced,
or a flat).&amp;nbsp; As we shall see, our
crosstab query will restructure the dataset in such a way that &lt;i&gt;property type&lt;/i&gt;
and &lt;i&gt;postcode&lt;/i&gt; values from the original table become row and column
headings in the resulting new table.&amp;nbsp;
Furthermore, the values produced in the new table are derived from an
aggregated average of individual house sale amounts from the original.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;



&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Let’s consider what this means in
practice.&amp;nbsp; The original table is
comprised of rows which represent individual house sales with each column containing
a specific piece of information about the sale.&amp;nbsp;
Here is a sample of the 2,942 record dataset we downloaded and cleansed in
the last blog post (see &lt;b&gt;Using Access for Data Analysis&lt;/b&gt;).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijPHdvDfPCJr4Mh2H6GAtQ03XZ7W0VZgM2SliBFgPy-ZjH55yoL4fTp01bsn99xzYUiWLi9gDrSPc_foRz5jxyT306s-u0As1io9HhyIdCtIPPLKRl_X1Rq5O7IzLTT-kGrdJlQF8Mjhyphenhyphene2yfWvUBTKuZDzpcdehyPBw8XvSbMPNSmcs9JdmVq0oVnvc/s512/orginal%20table%20sample.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Salford House Sales 2023&quot; border=&quot;0&quot; data-original-height=&quot;421&quot; data-original-width=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijPHdvDfPCJr4Mh2H6GAtQ03XZ7W0VZgM2SliBFgPy-ZjH55yoL4fTp01bsn99xzYUiWLi9gDrSPc_foRz5jxyT306s-u0As1io9HhyIdCtIPPLKRl_X1Rq5O7IzLTT-kGrdJlQF8Mjhyphenhyphene2yfWvUBTKuZDzpcdehyPBw8XvSbMPNSmcs9JdmVq0oVnvc/s16000/orginal%20table%20sample.jpg&quot; title=&quot;Salford House Sales 2023&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Figure&amp;nbsp;1: Sample from original dataset of house sales in Salford during 2023.&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;As we can see each house sale record has its
own unique id, sale amount (price_paid), date (deed_date), postcode and
property type. As stated above, we are going to create a crosstab query which
will restructure the table so that each row represents a &lt;b&gt;property type&lt;/b&gt;
and each column a &lt;b&gt;postcode&lt;/b&gt; area. Each value in the table is the average
sale amount (ie price_paid) for all properties for the property type and
postcode area of its particular row and column respectively.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;The table below shows how the crosstab query
results will look:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;

&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableGrid&quot; style=&quot;border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;&quot;&gt;
 &lt;tbody&gt;&lt;tr style=&quot;mso-yfti-firstrow: yes; mso-yfti-irow: 0;&quot;&gt;
  &lt;td style=&quot;border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 84.8pt;&quot; valign=&quot;top&quot; width=&quot;113&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.4pt;&quot; valign=&quot;top&quot; width=&quot;87&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Postcode&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Postcode &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Postcode &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Postcode&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Postcode&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr style=&quot;mso-yfti-irow: 1;&quot;&gt;
  &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 84.8pt;&quot; valign=&quot;top&quot; width=&quot;113&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Property type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.4pt;&quot; valign=&quot;top&quot; width=&quot;87&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr style=&quot;mso-yfti-irow: 2;&quot;&gt;
  &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 84.8pt;&quot; valign=&quot;top&quot; width=&quot;113&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Property type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.4pt;&quot; valign=&quot;top&quot; width=&quot;87&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr style=&quot;mso-yfti-irow: 3;&quot;&gt;
  &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 84.8pt;&quot; valign=&quot;top&quot; width=&quot;113&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Property type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.4pt;&quot; valign=&quot;top&quot; width=&quot;87&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr style=&quot;mso-yfti-irow: 4; mso-yfti-lastrow: yes;&quot;&gt;
  &lt;td style=&quot;border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 84.8pt;&quot; valign=&quot;top&quot; width=&quot;113&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Property type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 65.4pt;&quot; valign=&quot;top&quot; width=&quot;87&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
  &lt;td style=&quot;border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 75.15pt;&quot; valign=&quot;top&quot; width=&quot;100&quot;&gt;
  &lt;p class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin-bottom: 0cm; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 9.0pt; mso-ansi-language: EN-US;&quot;&gt;Average
  £&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Before we look at how to create the crosstab
query itself, let us first clarify what the &lt;b&gt;property type&lt;/b&gt; and &lt;b&gt;postcode&lt;/b&gt;
data actually means. Property type data can be one of four different letters – &lt;b&gt;D&lt;/b&gt;,
&lt;b&gt;S&lt;/b&gt;, &lt;b&gt;T&lt;/b&gt; or &lt;b&gt;F&lt;/b&gt;.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;These
are the first letters of the following property types – &lt;b&gt;Detached&lt;/b&gt;, &lt;b&gt;Semi-detached&lt;/b&gt;,
&lt;b&gt;Terraced&lt;/b&gt; or &lt;b&gt;Flat&lt;/b&gt;. For those of you outside of the UK and
unfamiliar with these property types: &lt;i&gt;Detached&lt;/i&gt; means a stand-alone
building containing a single home; &lt;i&gt;Semi-detached&lt;/i&gt; means a single building
comprised of two separate homes; &lt;i&gt;Terraced&lt;/i&gt; means a row of multiple
adjoining homes; and &lt;i&gt;Flat&lt;/i&gt; means a large building divided into multiple
apartments. Detached homes tend to be the most expensive property type,
followed by Semi-detached, Terraced and Flats respectively. However, location
has a direct bearing on the property’s sale price, so a semi-detached property
in a desirable area may be more expensive than a detached property located
somewhere less desirable.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;This is where
the properties &lt;b&gt;postcode&lt;/b&gt; value comes in.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;
&lt;/span&gt;Postcodes are comprised of two separate parts eg &lt;b&gt;M28 1FU&lt;/b&gt;.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp; &lt;/span&gt;The full postcode tells us which part of a
street the property is located, so each full postcode may be shared by a small
number of other properties on the same street.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;
&lt;/span&gt;The first part of the postcode eg &lt;b&gt;M28&lt;/b&gt;, on the other hand, relates
to the general area where the property is located, so there can be hundreds of
other properties sharing this part of the code.&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;
&lt;/span&gt;As such this can give us a good idea about the desirability of the
properties location, and it is this part that we shall use for the column
headings in our crosstab query.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-size: 18.0pt; line-height: 107%; mso-ansi-language: EN-US;&quot;&gt;Creating the
Access Crosstab Query&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;

&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;mso-ansi-language: EN-US;&quot;&gt;Let us now
look at how the crosstab query is created. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;In the
previous blog post on &lt;b&gt;Using Access for Data Analysis&lt;/b&gt; we downloaded a
dataset from the UK based HM Land Registry website and imported it into an
Access table.&amp;nbsp; We called the table &lt;b&gt;tblSalfordHouseSales
&lt;/b&gt;(after data cleansing).&amp;nbsp; We shall be
using this table to create the crosstab query below.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Here are the step by step instructions:&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;/p&gt;&lt;ol&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Open the Access database in which &lt;b&gt;tblSalfordHouseSales&lt;/b&gt;
is located and select the CREATE tribbon.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Click the QUERY DESIGN icon from the
QUERIES group to open the QUERY DESIGN window.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Click the ADD TABLES icon from the
QUERY SETUP group of the QUERY DESIGN ribbon. This opens the ADD TABLES sidebar
(if it is not open already).&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Select the TABLES tab from the ADD
TABLES sidebar, and drag the &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;table onto the top
section of the QUERY DESIGN window.&lt;/li&gt;&lt;li&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Next, we need to click the CROSSTAB
icon from the QUERY TYPE group of the QUERY DESIGN ribbon.&amp;nbsp; This adds CROSSTAB row to the QUERY DESIGN
grid in the lower half of the QUERY DESIGN window.&lt;/div&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigu9LJx3lviaeXqu47KBDlli03SitBl0BGymvv7NOdfJCXouwFYuhnU8WjEZrH0LSpEPpBuSoc2Rj2lqI12NrWcc2kiNxxyfpnBnAldxx9EcVfNyJh3CT16HQq4Mgw0Y9bGGyCYjdGoZWoQwSV4OvgoExgd2BhFa98RA_mjiHeBiMFd96kQ0n_rIj-5Qk/s412/crosstab%20query%20type%20icon.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;103&quot; data-original-width=&quot;412&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigu9LJx3lviaeXqu47KBDlli03SitBl0BGymvv7NOdfJCXouwFYuhnU8WjEZrH0LSpEPpBuSoc2Rj2lqI12NrWcc2kiNxxyfpnBnAldxx9EcVfNyJh3CT16HQq4Mgw0Y9bGGyCYjdGoZWoQwSV4OvgoExgd2BhFa98RA_mjiHeBiMFd96kQ0n_rIj-5Qk/s16000/crosstab%20query%20type%20icon.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Figure 2:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Aptos, sans-serif; line-height: 107%;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;:
The &lt;b&gt;CROSSTAB&lt;/b&gt; icon in the QUERY TYPE group of the QUERY DESIGN ribbon.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid66CDab2JvBYgfvWbXpvDIvKzSZFqYio-i8NGwfMXww2NSqcQ_gLGt51D1mYEbOuhpYP9t0ux6IFxt6hd-fwQZMvclcgzUWa5TOvAmeK2yI9lNmRjPD-A4oRy4WUnjes8QivSmt8OFSb8gfcQl4KZDXwZ6UOCmC94pZ6N6W_y1CORctHEBdOUC_N9HEY/s396/Screenshot%202025-08-22%20220049.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;396&quot; data-original-width=&quot;288&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid66CDab2JvBYgfvWbXpvDIvKzSZFqYio-i8NGwfMXww2NSqcQ_gLGt51D1mYEbOuhpYP9t0ux6IFxt6hd-fwQZMvclcgzUWa5TOvAmeK2yI9lNmRjPD-A4oRy4WUnjes8QivSmt8OFSb8gfcQl4KZDXwZ6UOCmC94pZ6N6W_y1CORctHEBdOUC_N9HEY/s16000/Screenshot%202025-08-22%20220049.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Figure 3: The &lt;b style=&quot;text-align: justify;&quot;&gt;QUERY DESIGN &lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;grid
after selecting &lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;property_type&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt; in first column. Notice the extra &lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;CROSSTAB
&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;row heading appear after clicking the CROSSTAB icon in the QUERY TYPE
ribbon group.&lt;/span&gt;&lt;/span&gt;&lt;p class=&quot;MsoCaption&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;The first field we are going to add to the QUERY&lt;span style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;DESIGN grid is &lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;property_type&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;.&amp;nbsp; &amp;nbsp; Do this
by&amp;nbsp; selecting the &lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;property_type&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt; field from the drop down list in the
first column of the &lt;/span&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;FIELD row of the
QUERY DESIGN grid, or by dragging &lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;property_type&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt; down from the&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;tblSalfordHouseSales&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;
table box in the top half of the window.&lt;/span&gt;&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;As explained above, each data value
in the &lt;b&gt;property_type&lt;/b&gt; field will act as a row heading in our crosstab
query.&amp;nbsp; To set this up on the QUERY
DESIGN grid, we go down to the CROSSTAB row on the property type column, and
select ROW HEADING from the drop down list as in figure 3 above.&lt;/li&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;The next field we are going to add
to the QUERY DESIGN grid is &lt;b style=&quot;text-indent: -18pt;&quot;&gt;postcode&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;However, as explained above, we are not interested in the &lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;full&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;
postcode, &lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;just&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; the general postcode area.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;You may remember that we discussed how UK
postcodes are comprised of two parts and it is the first part which tells us
the general area.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;As such, we need to use
a string function to extract the first part of the code from the full field
value.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;We are going to achieve this end
using the &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;InStr&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; function to count the number of characters in the first
part of the code, and then using the &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;Left&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; function to extract these
characters from the full field value. We use the &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;InStr&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; function to
search for the space character which separates the two parts of the code.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;The value the function returns is the
numerical character &lt;/span&gt;&lt;i style=&quot;text-indent: -18pt;&quot;&gt;position&lt;/i&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; of the space.&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;The syntax for this is as follows:&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;display: inline !important; margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #002060; font-family: &amp;quot;Verdana&amp;quot;,sans-serif; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #002060; font-family: &amp;quot;Verdana&amp;quot;,sans-serif; mso-ansi-language: EN-US;&quot;&gt;InStr([postcode], “ “) -1&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;By
subtracting 1 from the return value, we get the character count of the first
part of the code. For example, if the postcode was “SK14 5RP”, our function
returns &lt;u&gt;5&lt;/u&gt; for the space position, and then &lt;u&gt;4&lt;/u&gt; for the character
count after we subtract 1. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;We
then use the &lt;b&gt;Left &lt;/b&gt;function to extract the number of characters in the character
count from the left side of the string. The syntax for this is as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #002060; font-family: &amp;quot;Verdana&amp;quot;,sans-serif; mso-ansi-language: EN-US;&quot;&gt;Left([postcode], InStr([postcode], “
“)-1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: #002060; font-family: &amp;quot;Verdana&amp;quot;,sans-serif; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;… and
this returns the first part of the postcode as a new string value ie “SK14” for
the example used above.&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;As
such, we can now add this function to the field row in the second column of the
QUERY DESIGN grid. The string data this function will return will form the
column headings in our crosstab query result, so select COLUMN HEADING in the
crosstab row drop down list as in the screenshot below:&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6IkdPfCnMon6EMgGMiHh4GGcssoZT0pVR0AhzDpKkIJzBMYBsRYNxESnCQdWy2C2TELcIFzvOQ1_5zXB-8G0xIG60zL-rhfaQ8AMKRqUtOIM28iGQisMrEfEd4Qa2r9-00WuvBwkS4-L3y9AorLo4HdmdP0O2v6ibjdGbFxzfEArxgAgxdj4TyASRe00/s762/postcode%20area%20function.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;128&quot; data-original-width=&quot;762&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6IkdPfCnMon6EMgGMiHh4GGcssoZT0pVR0AhzDpKkIJzBMYBsRYNxESnCQdWy2C2TELcIFzvOQ1_5zXB-8G0xIG60zL-rhfaQ8AMKRqUtOIM28iGQisMrEfEd4Qa2r9-00WuvBwkS4-L3y9AorLo4HdmdP0O2v6ibjdGbFxzfEArxgAgxdj4TyASRe00/s16000/postcode%20area%20function.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Figure 4:&amp;nbsp;&lt;span style=&quot;font-family: Aptos, sans-serif; line-height: 107%;&quot;&gt;NB
Once you enter the expression, Access gives the column it’s own alias of &lt;b&gt;Exp1&lt;/b&gt;.&amp;nbsp; You can overtype this with &lt;b&gt;postcode_area&lt;/b&gt;
to give it a more meaningful name. Doing so does not affect the query result in
any way.&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;margin-left: 25.05pt; text-align: justify;&quot;&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -18pt;&quot;&gt;10.&lt;span style=&quot;font-feature-settings: normal; font-kerning: auto; font-optical-sizing: auto; font-size-adjust: none; font-size: 7pt; font-stretch: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-emoji: normal; font-variant-numeric: normal; font-variant-position: normal; font-variation-settings: normal; line-height: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -18pt;&quot;&gt;Now that we have sorted our row and
column headings, we just need to take care of the actual values where the rows
and columns intersect. As you may remember, these are going to be the average
price paid for a property of a specific type (ie the &lt;b&gt;property_type&lt;/b&gt; row)
in a specific area (ie the &lt;b&gt;postcode_area&lt;/b&gt; column). &lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;Do this by selecting the &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;price_paid&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; field from
the drop down list in the third column of the&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;&amp;nbsp;
&lt;/span&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;FIELD row of the QUERY DESIGN grid, or by dragging &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;price_paid&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;
down from the &lt;/span&gt;&lt;b style=&quot;text-indent: -18pt;&quot;&gt;tblSalfordHouseSales&lt;/b&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt; table box in the top half of the
window.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span style=&quot;text-indent: -18pt;&quot;&gt;11.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -18pt;&quot;&gt;Next, we need to change the value in
the &lt;b&gt;TOTAL&lt;/b&gt; row of the &lt;b&gt;price_paid&lt;/b&gt; column in the QUERY DESIGN
grid.&amp;nbsp; Change the value from GROUP BY to &lt;b&gt;AVG&lt;/b&gt;.&amp;nbsp; This will give us the average price_paid
aggregate for properties of a specific type in a specific area.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;text-indent: -18pt;&quot;&gt;12.&amp;nbsp;&lt;/span&gt;This is where we set the &lt;b&gt;CROSSTAB
&lt;/b&gt;row of the &lt;b&gt;price_paid &lt;/b&gt;column in the QUERY DESIGN grid. Select &lt;b&gt;VALUE
&lt;/b&gt;from the dropdown list as in figure 4 above. This simply tells Access that
the &lt;b&gt;price_ paid&lt;/b&gt; field is constituting the values in the crosstab query.&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;13. Finally, we just need to set field
properties for &lt;b&gt;price_paid &lt;/b&gt;so that we get a whole number without any
decimal places. Do this by clicking anywhere in the &lt;b&gt;price_paid &lt;/b&gt;QUERY
DESIGN GRID column, and then clicking the PROPERTY SHEET icon in the SHOW/HIDE
group of the QUERY DESIGN ribbon, and then set the &lt;b&gt;FORMAT&lt;/b&gt; property to &lt;b&gt;CURRENCY
&lt;/b&gt;and the &lt;b&gt;DECIMAL PLACES&lt;/b&gt; property to 0.&amp;nbsp; This will make the query results much easier
to read.&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;line-height: normal; margin-left: 7.05pt; mso-add-space: auto; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;All we need to do now is click &lt;b&gt;RUN&lt;/b&gt; in the &lt;b&gt;RESULTS &lt;/b&gt;group of
the &lt;b&gt;QUERY DESIGN &lt;/b&gt;ribbon to see the results of our crosstab query!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;line-height: normal; margin-left: 7.05pt; mso-add-space: auto; text-align: justify;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxr1Djuqft0WyXeKmGju3W2epnEZI6AZsmKuqgiRY9ajnXpOImiwKhPAKTAzKmJ2KNeNSAI1kw58-qYrIgawtl4pGzJ5a8OvhS5pvdYFZ5x-LeZ8ocTsNA7v3C3mnbAsl2dPnsPykg0zueWP10D3_aNe-WavNDdljSWwhPlASVEY35yCe4aP8EsfumjBw/s1071/query%20results.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;130&quot; data-original-width=&quot;1071&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxr1Djuqft0WyXeKmGju3W2epnEZI6AZsmKuqgiRY9ajnXpOImiwKhPAKTAzKmJ2KNeNSAI1kw58-qYrIgawtl4pGzJ5a8OvhS5pvdYFZ5x-LeZ8ocTsNA7v3C3mnbAsl2dPnsPykg0zueWP10D3_aNe-WavNDdljSWwhPlASVEY35yCe4aP8EsfumjBw/s16000/query%20results.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Figure 5: Average price paid for property types in the different Salford poscode areas (data taken from sales during 2023).&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;As we can see, the different property type
codes from data in our original table form the row headings in the crosstab
query, and the postcode areas form the column headings. The actual table
values, as we have learnt above, are an aggregated price_paid average of all
properties of a specific type in a specific area.&amp;nbsp; So, for example, the average price paid of
all &lt;i&gt;detached&lt;/i&gt; properties in the &lt;i&gt;M27&lt;/i&gt; postcode area is £335,592. If
we compare this to the average price paid of the same property type in the &lt;i&gt;M28&lt;/i&gt;
postcode area we see the value of £440,601 is more expensive, thereby
suggesting that the latter area is more desirable. As such, the crosstab query
has given us a meaningful summary of the 2,942 rows of data from our original
table.&amp;nbsp; In so doing it has helped us
understand what the original data was telling us.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left: 7.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left: 7.05pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoListParagraph&quot; style=&quot;margin-left: 25.05pt; mso-add-space: auto; mso-list: l0 level1 lfo1; text-align: justify; text-indent: -18.0pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/64619937163422682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2025/08/analysing-data-with-access-crosstab.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/64619937163422682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/64619937163422682'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2025/08/analysing-data-with-access-crosstab.html' title='Analysing Data with Access Crosstab Queries'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijPHdvDfPCJr4Mh2H6GAtQ03XZ7W0VZgM2SliBFgPy-ZjH55yoL4fTp01bsn99xzYUiWLi9gDrSPc_foRz5jxyT306s-u0As1io9HhyIdCtIPPLKRl_X1Rq5O7IzLTT-kGrdJlQF8Mjhyphenhyphene2yfWvUBTKuZDzpcdehyPBw8XvSbMPNSmcs9JdmVq0oVnvc/s72-c/orginal%20table%20sample.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-7184765078704439406</id><published>2025-05-26T03:29:00.000-07:00</published><updated>2025-05-26T03:29:32.636-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="export"/><category scheme="http://www.blogger.com/atom/ns#" term="external data"/><category scheme="http://www.blogger.com/atom/ns#" term="import"/><category scheme="http://www.blogger.com/atom/ns#" term="MS Access"/><category scheme="http://www.blogger.com/atom/ns#" term="MS Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="query"/><category scheme="http://www.blogger.com/atom/ns#" term="subquery"/><category scheme="http://www.blogger.com/atom/ns#" term="summary data"/><title type='text'>Using Access for Data Analysis</title><content type='html'>&lt;p style=&quot;text-align: justify;&quot;&gt;Normally, when we think of&amp;nbsp; MS Access, we do so in the context of database development; that is to say, as software to create database applications for long term use to keep track of data such as customer orders, income and expenditure, and stock control. Such database applications are used by one or more people over a period of time to store, process and retrieve information, and often support the day to day operation of a business.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In this tutorial, however, we are&amp;nbsp; going to look at how MS Access can be used in the context of &lt;i&gt;data analysis&lt;/i&gt;.&amp;nbsp; This use is very much different from the database development model described above. Rather than setting up a database for long term use in the day to running of a business operation for example,&amp;nbsp; we are going to use Access in a short term context, as a tool to import data from an external source, and then analyse that data through Access Queries to make it meaningful from a particular perspective. This summarised data can be presented to, say, a management team to make informed decisions based on what the information reveals.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;To do this we are going to be working with 2023 house sale data for the Salford area of Greater Manchester.&amp;nbsp; The process will involve extracting a dataset from the UK based HM Land Registry website, importing the dataset into Access, creating query&#39;s to categorise and aggregate the data, and then create a report containing a clustered column chart to present the data visually.&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Downloading the Dataset&lt;/h3&gt;&lt;div&gt;The first step in the process is to download the dataset from the &lt;a href=&quot;https://landregistry.data.gov.uk/app/ppd/&quot; target=&quot;_blank&quot;&gt;HM Land Registry&lt;/a&gt; website. This will involve filling in an online webform to specify the data we require. In our case this is &lt;b&gt;all data&lt;/b&gt; between &lt;b&gt;1st January and 31st December 2023&lt;/b&gt; in the district of &lt;b&gt;SALFORD&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;1. Click this link the &lt;a href=&quot;https://landregistry.data.gov.uk/app/ppd/&quot; target=&quot;_blank&quot;&gt;HM Land Registry&lt;/a&gt; link to open the web form in your browser.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5kLbnhTzFZoYk-cFwqyiZiLjVtV_dlV1dyhRTuhKcI3VOb6Eknzki1DrUHfcwSkIBxCnHk0hR0PRzddpFIEtky8oPSt2L3WOxo9JL4z6Q3NbMe3bAmZ1kK-4t-QLE7KEjW260HIV3e2nlpOKb8_pI-AOeXZsYSv7exzZpM2lgBGHZFxbYAtFj6rf4RkM/s733/hm%20land%20registry%20form.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;678&quot; data-original-width=&quot;733&quot; height=&quot;592&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5kLbnhTzFZoYk-cFwqyiZiLjVtV_dlV1dyhRTuhKcI3VOb6Eknzki1DrUHfcwSkIBxCnHk0hR0PRzddpFIEtky8oPSt2L3WOxo9JL4z6Q3NbMe3bAmZ1kK-4t-QLE7KEjW260HIV3e2nlpOKb8_pI-AOeXZsYSv7exzZpM2lgBGHZFxbYAtFj6rf4RkM/w640-h592/hm%20land%20registry%20form.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;2. Enter &quot;&lt;b&gt;SALFORD&lt;/b&gt;&quot; in the DISTRICT textbox, &lt;b&gt;01/01/2023&lt;/b&gt; and &lt;b&gt;31/12/2023&lt;/b&gt; for the DATE range (note the UK date format) , and select &quot;&lt;b&gt;ALL&lt;/b&gt;&quot; from the HOW MANY RESULTS option group at the bottom.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;3. Click the SHOW RESULTS button.&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;This opens a new web page showing 2947 property sale transactions for 2915 properties. We now need to download the results into a CSV file.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbYDC4lPKSrH_-w-LT6StvxPq5jsWBUk_pN-8UwtkLExcdtPWDM0SzpVb75it97nLQkexHIp2zrDJB-EA-5F1EeMxgby3n6Djy0q-rligdpG57PtXdinmkrE6mpcLb0CfOWKYDy0mbzjhEcNvTBaLwLOx1Bl8dLNiCJcomjXiMoq52ibcc-4vqL_W9mSg/s751/hm%20land%20registry%20results.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;393&quot; data-original-width=&quot;751&quot; height=&quot;334&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbYDC4lPKSrH_-w-LT6StvxPq5jsWBUk_pN-8UwtkLExcdtPWDM0SzpVb75it97nLQkexHIp2zrDJB-EA-5F1EeMxgby3n6Djy0q-rligdpG57PtXdinmkrE6mpcLb0CfOWKYDy0mbzjhEcNvTBaLwLOx1Bl8dLNiCJcomjXiMoq52ibcc-4vqL_W9mSg/w640-h334/hm%20land%20registry%20results.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;4. Click the&amp;nbsp;&amp;nbsp;&lt;b&gt;DOWLOAD DATA &lt;/b&gt;button at the top of the form.&amp;nbsp; This opens a web page giving us options for downloading:&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqASZWw3GACCOdXA9P65BczsL56MMJSKFEB3tLex1pp8mrdyZrnRxW7rju_EGfadblWFFywrBUW2HFCV0eoV61oeqmR7wC0R6tqqeo5VtU_eQDEqQ-CnjCWNSpLppXHklj6WbUQEbdzlKtx4nO9jSXSxHA22aWwrGvjvZTWgkgCkmWq8VZyzRcYIH1ik0/s713/download%20csv.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;493&quot; data-original-width=&quot;713&quot; height=&quot;442&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqASZWw3GACCOdXA9P65BczsL56MMJSKFEB3tLex1pp8mrdyZrnRxW7rju_EGfadblWFFywrBUW2HFCV0eoV61oeqmR7wC0R6tqqeo5VtU_eQDEqQ-CnjCWNSpLppXHklj6WbUQEbdzlKtx4nO9jSXSxHA22aWwrGvjvZTWgkgCkmWq8VZyzRcYIH1ik0/w640-h442/download%20csv.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;5. Click &lt;b&gt;GET ALL RESULTS AS CSV WITH HEADERS&amp;nbsp;&lt;/b&gt;button to start the download.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;A dataset called &lt;b&gt;ppd_data.csv&lt;/b&gt; will be saved to your downloads folder.&amp;nbsp; You can now open the file to inspect the data.&amp;nbsp; It will open in MS Excel by default and if you scroll to the bottom of the worksheet there should be 2947 rows.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Importing the Dataset into Access&lt;/h3&gt;&lt;div&gt;We can now go ahead and import the data into our Access Database.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1. Click&lt;b&gt; NEW DATA SOURCE &lt;/b&gt;on the Access&amp;nbsp;&lt;b&gt;EXTERNAL DATA&lt;/b&gt; ribbon. Choose &lt;b&gt;FROM FILE&lt;/b&gt; when the context menu opens, and then click &lt;b&gt;TEXT FILE&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEippt0Hlz09NO1jMBN49trdNnFiVKJ5mDeZ5gZuDm6q5e1vAi5uZiHDM2L1B4ninMXj3QKHfUQ8-ULCTlyae6_eSgP3u9iybQ0GGFPJI6SfAPtisdkW2DFC5EnWfpjO_gcJ9HEYV1eHTbQgVcfThyphenhyphenby_jo9EELT18CXH3pdaqgkCpHQzivce9mIXMo00Wo/s363/import%20contex%20menu.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;280&quot; data-original-width=&quot;363&quot; height=&quot;247&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEippt0Hlz09NO1jMBN49trdNnFiVKJ5mDeZ5gZuDm6q5e1vAi5uZiHDM2L1B4ninMXj3QKHfUQ8-ULCTlyae6_eSgP3u9iybQ0GGFPJI6SfAPtisdkW2DFC5EnWfpjO_gcJ9HEYV1eHTbQgVcfThyphenhyphenby_jo9EELT18CXH3pdaqgkCpHQzivce9mIXMo00Wo/s320/import%20contex%20menu.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;This will start the&lt;b&gt;&amp;nbsp;GET EXTERNAL DATA - TEXT FILE&lt;/b&gt;&amp;nbsp;wizard.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Click the &lt;b&gt;BROWSE &lt;/b&gt;button on the first page of the wizard and select the text file which has been saved in your downloads folder.&amp;nbsp; Leave the top radio button selected - it reads &quot;&lt;b&gt;import the source data into a new table in the current database&lt;/b&gt;&quot;.&amp;nbsp; Click &lt;b&gt;OK &lt;/b&gt;at the bottom of the wizard window.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpHV1YIap2WvvxhjwWY6molsrufgh8IhjU3hla42hZ51JOVpj7DBvX4m4_rVF6F2T6Xh-w0rQXAxrCC61hbzvF_8gPqgWulYDbFlNnISDJImorwIUhAEXkVQnHX2ESjINEb_0oleif14ljz5jJak_KmFrdhkShQZ_eLBfQPVjyy2gdE7ICvNiXr_D0YDU/s767/select%20source%20and%20destination%20.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;544&quot; data-original-width=&quot;767&quot; height=&quot;454&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpHV1YIap2WvvxhjwWY6molsrufgh8IhjU3hla42hZ51JOVpj7DBvX4m4_rVF6F2T6Xh-w0rQXAxrCC61hbzvF_8gPqgWulYDbFlNnISDJImorwIUhAEXkVQnHX2ESjINEb_0oleif14ljz5jJak_KmFrdhkShQZ_eLBfQPVjyy2gdE7ICvNiXr_D0YDU/w640-h454/select%20source%20and%20destination%20.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. The next page (see screenshot below) shows a sample of the data we are importing.&amp;nbsp; At the top it reads &quot;&lt;i&gt;Your data seems to be in a delimited format.&amp;nbsp; If it isn&#39;t, choose the format that more correctly describes your data&lt;/i&gt;&quot;.&amp;nbsp; If you look at the sample of data displayed, you see each field is separated by a comma.&amp;nbsp; We can therefore leave the &quot;&lt;i&gt;Delimited&lt;/i&gt;&quot; radio button checked, and click NEXT.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf_lfIhtf0IKiNM4u44RQVDgexE7xDHhXZ4JHzpa96bMxxl_nDTaWZ6jTaY2zu4MRzHzHBpp1rw0DRyYOksGrZ5JV-L9Rb9xMtjV2Oela27gcB0UpLniKsC6LMJKhQPCLfQcBYTZ8Yq_wEPALPCGZDBfojOj10pocAEmfHV5JkcXHsGf7pzs1iOysEj9g/s738/comma-delimited.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;540&quot; data-original-width=&quot;738&quot; height=&quot;468&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf_lfIhtf0IKiNM4u44RQVDgexE7xDHhXZ4JHzpa96bMxxl_nDTaWZ6jTaY2zu4MRzHzHBpp1rw0DRyYOksGrZ5JV-L9Rb9xMtjV2Oela27gcB0UpLniKsC6LMJKhQPCLfQcBYTZ8Yq_wEPALPCGZDBfojOj10pocAEmfHV5JkcXHsGf7pzs1iOysEj9g/w640-h468/comma-delimited.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. The next page of the wizard (see screenshot below) asks us to choose the delimiter that separates our fields. As we noted above, our data is separated by commas, so we should now select the &quot;&lt;b&gt;Comma&lt;/b&gt;&quot; radio button.&amp;nbsp; We also need to click the &quot;&lt;b&gt;First Row Contains Field Names&lt;/b&gt;&quot; tickbox.&amp;nbsp; You may get pop up message explaining some of the field names have been modified to make them compatible with Access.&amp;nbsp; This is fine. Just click OK. We can now click &lt;b&gt;NEXT &lt;/b&gt;to move on to the next page of the wizard.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZeOM1cZqYKv6q25e1TtbqvdMsr4Y0sDnp3stJdSOzfJz8TyfXH1R1SpouOd5fq65icWLLU29_ZGVW0294EaT4Wh9gPYbedG3jPwh7SNXbKRHrpFl2oaf_IdMtMZ8I_k0GjD0TagqZ8HIcYTwDhyphenhyphenNZWzgmrnPMzNybUlT6ODbvuGTU3mPAEu3Je6l6wAE/s740/select-delimiter.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;539&quot; data-original-width=&quot;740&quot; height=&quot;466&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZeOM1cZqYKv6q25e1TtbqvdMsr4Y0sDnp3stJdSOzfJz8TyfXH1R1SpouOd5fq65icWLLU29_ZGVW0294EaT4Wh9gPYbedG3jPwh7SNXbKRHrpFl2oaf_IdMtMZ8I_k0GjD0TagqZ8HIcYTwDhyphenhyphenNZWzgmrnPMzNybUlT6ODbvuGTU3mPAEu3Je6l6wAE/w640-h466/select-delimiter.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;5. This page (see screenshot below) gives us the option to specify information about each of the fields we are importing.&amp;nbsp; This includes specifying the data type for the field. We are going to change the data type for the &lt;b&gt;price_paid&lt;/b&gt; field from SHORT TEXT to &lt;b&gt;CURRENCY.&lt;/b&gt;&amp;nbsp; To do this, highlight the &lt;b&gt;price_paid &lt;/b&gt;column and select &lt;b&gt;CURRENCY&amp;nbsp;&lt;/b&gt;from the &lt;b&gt;DATA TYPE &lt;/b&gt;combo box. We will also change the data type on the &lt;b&gt;deed_date &lt;/b&gt;field from SHORT TEXT to &lt;b&gt;DATE WITH TIME. &lt;/b&gt;Another thing we are going to change is the index type (ie the&amp;nbsp;&lt;b&gt;Indexed&amp;nbsp;&lt;/b&gt;field option)&amp;nbsp;on the&amp;nbsp;&lt;b&gt;unique_id&amp;nbsp;&lt;/b&gt;field from &quot;&lt;i&gt;Yes (Duplicates OK)&lt;/i&gt;&quot; to &quot;&lt;i&gt;Yes (No Duplicates). &lt;/i&gt;This will ensure the data set does not contain any duplicate records.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;At this stage we can clean the data set further by excluding any fields that we do not need.&amp;nbsp; To do this, highlight the field for exclusion and tick the &quot;&lt;b&gt;Do not import field&lt;/b&gt;&quot; tick-box in the &lt;b&gt;Field Options &lt;/b&gt;section.&amp;nbsp; We are going exclude the &lt;b&gt;estate_type&lt;/b&gt; field, and all the fields from &lt;b&gt;transaction_category&lt;/b&gt; and after.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;i&gt;&lt;/i&gt;We can then click &lt;b&gt;NEXT &lt;/b&gt;to continue.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB1ZMNiaH3r6-vMvwg7VZqLQxkQh208WZVoU8g4k_P0E8Db6Sz4SGYeiT0oQ40DWV0ciLrM3BiZu8zVTti7PoF4e4ne7JnFRWxsk1UHp-wOH8kJPMY2azhN_pcZfay6UGTkYQyHTfzce6IwIeoQnVDeVONftqXttOj3zLzSfpL3Yy-Zc7j5KVL1n3E5SI/s737/specify-field-info.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;538&quot; data-original-width=&quot;737&quot; height=&quot;468&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB1ZMNiaH3r6-vMvwg7VZqLQxkQh208WZVoU8g4k_P0E8Db6Sz4SGYeiT0oQ40DWV0ciLrM3BiZu8zVTti7PoF4e4ne7JnFRWxsk1UHp-wOH8kJPMY2azhN_pcZfay6UGTkYQyHTfzce6IwIeoQnVDeVONftqXttOj3zLzSfpL3Yy-Zc7j5KVL1n3E5SI/w640-h468/specify-field-info.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;6. The next page of the wizard lets us choose a primary key.&amp;nbsp; There are three options: these are &quot;&lt;i&gt;Let Access add primary key&lt;/i&gt;&quot;, &quot;&lt;i&gt;Choose my own primary key&lt;/i&gt;&quot; and &quot;&lt;i&gt;No primary key&lt;/i&gt;&quot;.&amp;nbsp; We are going to select our own primary key, so tick the middle option and select the &quot;&lt;b&gt;unique_id&lt;/b&gt;&quot; field from the combo box list. Then click NEXT.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Z4FLW08GRvAfAtASWsrTYZRKeIkv5uu2YMYavAtDj5KXkwo9g-k5w3zScCLFM6CLnDmuszqDybD6xzC1O3FHHB67FzVWcMCymT7Vxwf6yGcCLi6NkZiPb-ZWbPGpWCNkUomDk2_8dK-oaUjHvYETv2MVFEtyaBMMbp_Vm3SFsleiXPkjl5vvcTQslCM/s737/select-primary-key.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;539&quot; data-original-width=&quot;737&quot; height=&quot;468&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Z4FLW08GRvAfAtASWsrTYZRKeIkv5uu2YMYavAtDj5KXkwo9g-k5w3zScCLFM6CLnDmuszqDybD6xzC1O3FHHB67FzVWcMCymT7Vxwf6yGcCLi6NkZiPb-ZWbPGpWCNkUomDk2_8dK-oaUjHvYETv2MVFEtyaBMMbp_Vm3SFsleiXPkjl5vvcTQslCM/w640-h468/select-primary-key.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;7. In the last page of the wizard we are asked to choose a name for the table into which our data is to be imported.&amp;nbsp; Entry the table name &quot;tblSalfordHouseSales&quot; and click FINISH.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2Q_79YvsnQ3Fs4O_6mvaXi0Hu6N6GdcdcLPSvVvPAIAw-AYmbpEjlXAwoWQwZl7B2TokcjkMs2DdMvF-JZKMdiHObN__F7qPFt_nxMbt-3uwjeduO6p0HgoZYAKvlJpdnyXTTnqRucy1jWD_EbFnol5C_DUkOe-6NIZTkQ5IjYj7cbgQnBv_hJGv9On8/s740/save-table.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;543&quot; data-original-width=&quot;740&quot; height=&quot;470&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2Q_79YvsnQ3Fs4O_6mvaXi0Hu6N6GdcdcLPSvVvPAIAw-AYmbpEjlXAwoWQwZl7B2TokcjkMs2DdMvF-JZKMdiHObN__F7qPFt_nxMbt-3uwjeduO6p0HgoZYAKvlJpdnyXTTnqRucy1jWD_EbFnol5C_DUkOe-6NIZTkQ5IjYj7cbgQnBv_hJGv9On8/w640-h470/save-table.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;We can now take an initial look at the table of data we have imported.&amp;nbsp; Go to the Access navigation pane and open &lt;b&gt;tblSalfordHouseSales&lt;/b&gt; (see screenshot below).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEialJEqxALN9CSzjRGpM-UMtg6bGvSUaH6-mefIcUd9rpkcADr_SjW4h4957aN_ekKWoN3Q5iNq9i4CgD4Mdz4xLkxWfxuIWkR_K5Qgck9xstmhltwP4SqbPUw7EDvb0CjjcdVAwXyqwReqeIBH5x3qHFUApp4b6DJQ52omkIZX8kuVzab16yyIoNvvKPs/s1157/tblSalfordHouseSales-datasheet.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;680&quot; data-original-width=&quot;1157&quot; height=&quot;376&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEialJEqxALN9CSzjRGpM-UMtg6bGvSUaH6-mefIcUd9rpkcADr_SjW4h4957aN_ekKWoN3Q5iNq9i4CgD4Mdz4xLkxWfxuIWkR_K5Qgck9xstmhltwP4SqbPUw7EDvb0CjjcdVAwXyqwReqeIBH5x3qHFUApp4b6DJQ52omkIZX8kuVzab16yyIoNvvKPs/w640-h376/tblSalfordHouseSales-datasheet.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As we can see, the data set contains 2946 records.&amp;nbsp; Each record provides information about the sale of a given property and consists of&amp;nbsp; 13 fields.&amp;nbsp; Some of&amp;nbsp; most useful fields we shall be using for data analysis in this tutorial are &lt;b&gt;price_paid&lt;/b&gt;, &lt;b&gt;deed_date&lt;/b&gt; and &lt;b&gt;postcode&lt;/b&gt;.&amp;nbsp;We also have the option of analysing house sales by &lt;b&gt;property_type&lt;/b&gt; and whether the property is a&amp;nbsp;&lt;b&gt;new_build&lt;/b&gt;.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Checking the Data&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now we have imported the data set into Access, we can start checking it&#39;s accuracy.&amp;nbsp; However, before we start, lets make a copy of the imported table so we can undo any changes that we make without having to repeat the download and import process.&amp;nbsp; Do this by right clicking &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;in the navigation pane and select &lt;b&gt;COPY &lt;/b&gt;from the context menu.&amp;nbsp; Then simply right click a blank space in the navigation pane and select &lt;b&gt;PASTE&lt;/b&gt;.&amp;nbsp; A window opens where we can enter a new name to call the table we are pasting, and select which paste option we would like.&amp;nbsp; We are going to call the new table &quot;&lt;b&gt;tblSalfordHouseSalesOriginalData&lt;/b&gt;&quot;&lt;b&gt;&amp;nbsp;&lt;/b&gt;and select the &lt;b&gt;Structure and Data &lt;/b&gt;paste option.&amp;nbsp; This will paste a new table based on the same structure, and containing the same data, as the one we copied. Then click &lt;b&gt;OK&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjudIAbGsWuJAULmTQ8DmY0FinNtEIw5yhoLkkcqStslKCCwkWq3zXCZVn7Kz9twtftBO7GP7GdN3mTmLj3Xx7DgPmwOtZD7Ztii1lQJ43uInhbpRI4btdAftQt2NaPKntp0DGZQa_n0vkPO83VGvM7SNSOq6y6cUInCvqy1u7jq2vToUA5HG3eLRfwsB4/s349/paste-table.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;185&quot; data-original-width=&quot;349&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjudIAbGsWuJAULmTQ8DmY0FinNtEIw5yhoLkkcqStslKCCwkWq3zXCZVn7Kz9twtftBO7GP7GdN3mTmLj3Xx7DgPmwOtZD7Ztii1lQJ43uInhbpRI4btdAftQt2NaPKntp0DGZQa_n0vkPO83VGvM7SNSOq6y6cUInCvqy1u7jq2vToUA5HG3eLRfwsB4/s16000/paste-table.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first thing we are going to check are the &lt;b&gt;postcodes &lt;/b&gt;(zip codes) in our dataset.&amp;nbsp; Since&amp;nbsp; the data we have downloaded is for the Salford area of Greater Manchester, each record in the dataset should start with one of the following values in the &lt;b&gt;postcode &lt;/b&gt;field: - M3, M5,&amp;nbsp; M6, M7, M27, M28, M30, M38, M44, and M50 (after which there is a space followed by the second part of the postcode) . As such, we are going to create a query which groups the data into groups comprised of the first three values of the postcode, and provide some basic aggregate information for each grouping. From this information, we should be able to pick out any obvious anomalies contained in the data.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Create Query to Group &amp;amp; Aggregate Postcode Data&lt;/h3&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj24rhr_St3PVtmi0AXM7kTb2KtvUT-s_Yv0YvEAZb5pf5QkAvLQSi1Rww4vPqAJ6EVqHXlNf29eVcmocg7YPOfA9ndgVyK4kO3A7EeVJ0OWcDaNC6wrxHVOJ9ID8P08OjL75nIILerxALRyulM3NbNftEURLtbf7C-0UdYl7QezMhriYoyS5MHr1vxGu0/s702/qryValidatePostCodes.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;454&quot; data-original-width=&quot;702&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj24rhr_St3PVtmi0AXM7kTb2KtvUT-s_Yv0YvEAZb5pf5QkAvLQSi1Rww4vPqAJ6EVqHXlNf29eVcmocg7YPOfA9ndgVyK4kO3A7EeVJ0OWcDaNC6wrxHVOJ9ID8P08OjL75nIILerxALRyulM3NbNftEURLtbf7C-0UdYl7QezMhriYoyS5MHr1vxGu0/s16000/qryValidatePostCodes.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Create a new query by clicking the &lt;b&gt;QUERY DESIGN &lt;/b&gt;icon on the &lt;b&gt;CREATE &lt;/b&gt;ribbon.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Click the&amp;nbsp;&lt;b&gt;ADD TABLES &lt;/b&gt;icon (on the &lt;b&gt;QUERY DESIGN &lt;/b&gt;ribbon) to display the ADD TABLES sidebar if it is not visible already.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Drag the &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;table from the &lt;i&gt;tables &lt;/i&gt;list in the sidebar over to the QUERY DESIGN window.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. Click the &lt;b&gt;TOTALS &lt;/b&gt;icon in the &lt;b&gt;SHOW/HIDE &lt;/b&gt;group of the &lt;b&gt;QUERY DESIGN &lt;/b&gt;ribbon.&amp;nbsp; This adds a &lt;b&gt;TOTAL &lt;/b&gt;row to the &lt;b&gt;QUERY DESIGN &lt;/b&gt;grid.&amp;nbsp; This enables us to specify whether the field is to group the data contained therein, or perform an aggregation on it.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;5. The &lt;i&gt;first&lt;/i&gt;&amp;nbsp;column in the query grid (see screenshot above) is going give us a list of postcode groups.&amp;nbsp; All the post code groups in the Salford area (see above) are 2 or 3 characters long.&amp;nbsp; So to extract the postcode group value from the value stored in the&amp;nbsp;&lt;b&gt;postcode &lt;/b&gt;field&lt;b&gt;&amp;nbsp;&lt;/b&gt;, we are going to create a calculated field in the first row of the first column of the query grid. The calculation is based on the &lt;b&gt;postcode &lt;/b&gt;field in &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;and utilises the &lt;b&gt;Left &lt;/b&gt;string function to take the first 3 characters of the field value.&amp;nbsp; This is enclosed within a&amp;nbsp;&lt;b&gt;RTrim &lt;/b&gt;function to remove the right blank space if the postcode group is two characters rather than three. It is written as follows:&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;b&gt;RTrim(Left([postcode], 3))&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We will use the alias &lt;b&gt;PCode &lt;/b&gt;as the field name. This is written ...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;PCode:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;... directly before the RTrim&amp;nbsp; function syntax. So altogether the first row of the first column in the query grid (see screenshot above) will read ...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;PCode:&amp;nbsp;&lt;/b&gt;&lt;b style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;RTrim(Left([postcode], 3))&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;We then set this field to &lt;b&gt;GROUP BY &lt;/b&gt;in the &lt;b&gt;TOTALS &lt;/b&gt;row.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;6. In the &lt;i&gt;second &lt;/i&gt;column of the query grid,&amp;nbsp; we are going to count the number of records within each postcode group.&amp;nbsp; So, in the ADD TABLES side bar, drag the&amp;nbsp;&lt;b&gt;unique_id &lt;/b&gt;field&lt;b&gt;&amp;nbsp;&lt;/b&gt;from &lt;b&gt;tblSalfordHouseSales&lt;/b&gt;&amp;nbsp;down to the first row of the second column in the query grid, and select &lt;b&gt;COUNT &lt;/b&gt;from the drop down list in the &lt;b&gt;TOTAL&lt;/b&gt;s&lt;b&gt;&amp;nbsp;&lt;/b&gt;row.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;7. In the &lt;i&gt;third&lt;/i&gt; column of the query grid we are going to &lt;b&gt;SUM &lt;/b&gt;the total of price_paid to give us the total price paid within each postcode group.&amp;nbsp; So drag &lt;b&gt;price_paid&lt;/b&gt;&amp;nbsp;from &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;down to the first row of the &lt;i&gt;third &lt;/i&gt;column in the grid, and select&amp;nbsp;&lt;b&gt;SUM &lt;/b&gt;in the &lt;b&gt;TOTALs &lt;/b&gt;row&lt;b&gt;.&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;8. Click the &lt;b&gt;RUN &lt;/b&gt;or &lt;b&gt;DATASHEET &lt;/b&gt;icon&amp;nbsp; in the &lt;b&gt;RESULTS &lt;/b&gt;group of the &lt;b&gt;QUERY DESIGN &lt;/b&gt;ribbon to see the query results.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBNGoIoCu16LHFCs9XjY3RKvH4kliJcqAegW-ddoAM4oyZw475AvHsbCWB2AP_W6cnlzkrhD7oNP2QPidAg656DYyx6wBde9UkctpQgzMQv4oQWN7A-BFW5HW2xwg895Yqjmz5EM8CxY6AFv70hPUzx3DxR6HP13VzfL92LQdOsOYp67yoko7t6EXf7cY/s406/validate-postcode-query.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;295&quot; data-original-width=&quot;406&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBNGoIoCu16LHFCs9XjY3RKvH4kliJcqAegW-ddoAM4oyZw475AvHsbCWB2AP_W6cnlzkrhD7oNP2QPidAg656DYyx6wBde9UkctpQgzMQv4oQWN7A-BFW5HW2xwg895Yqjmz5EM8CxY6AFv70hPUzx3DxR6HP13VzfL92LQdOsOYp67yoko7t6EXf7cY/s16000/validate-postcode-query.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Looking at the query results above, we can see that most of the properties have a post code in the Salford area - these are M3, M5,&amp;nbsp; M6, M7, M27, M28, M30, M38, M44, and M50.&amp;nbsp; However there are three properties which do not have any postcode, and one property which has a postcode starting with WA1.&amp;nbsp; Taken together these come to a total value of £10,249,999.&amp;nbsp; In order to ensure our data set is accurate, we need to investigate why these properties do not have a Salford post code and remove them if necessary.&amp;nbsp; To do this we shall create another query to get the full information for the dubious records.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Repeat steps 1 to 3 above to create a new query based on the &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;table.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Drag the asterix&amp;nbsp;*&amp;nbsp;from the&amp;nbsp;&amp;nbsp;&lt;b&gt;tblSalfordHouseSales &lt;/b&gt;table down to the &lt;i&gt;first &lt;/i&gt;row of the &lt;i&gt;first &lt;/i&gt;column on the query design grid.&amp;nbsp; The asterix is a quick way to include all the fields in the table without having to drag each one individually.&amp;nbsp; However, if we need to enter a criteria for a particular field (which we do) we can still drag that field down separately ..&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. As such, drag the &lt;b&gt;postcode &lt;/b&gt;field down to the &lt;i&gt;first &lt;/i&gt;row of the &lt;i&gt;second &lt;/i&gt;column in the grid.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4 Click the &lt;b&gt;CRITERIA &lt;/b&gt;row in the postcode column and enter the following expression:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;b&gt;Is Null&amp;nbsp; or Like &quot;WA1*&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOraJp9ppJu6au16EdjyDF7KuJ0eJNYOphgcYU5B2Pgdf1bmPtYDsmxJF2t4pVs_vDIHqbeZnAW43ofLmLAytjFcCtly4Ugp3dH3VqSM-REoSqzCwhh01tnDvHbQN0D8P7cEfZmmS_OBZd1giFh3Uuep7piwoVw8-o8tzseIYNeJKv5sg0zezwTzjq7l4/s483/qryDubiousRecords-query-design.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;483&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOraJp9ppJu6au16EdjyDF7KuJ0eJNYOphgcYU5B2Pgdf1bmPtYDsmxJF2t4pVs_vDIHqbeZnAW43ofLmLAytjFcCtly4Ugp3dH3VqSM-REoSqzCwhh01tnDvHbQN0D8P7cEfZmmS_OBZd1giFh3Uuep7piwoVw8-o8tzseIYNeJKv5sg0zezwTzjq7l4/s16000/qryDubiousRecords-query-design.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;The criteria &lt;span style=&quot;color: #073763; font-family: verdana;&quot;&gt;Is Null Or Like &quot;wa1*&quot; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;will pull out any record containing a &lt;br /&gt;postcode with a null value or&amp;nbsp;a value starting with &quot;wa1&quot;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;5. Click the &lt;b&gt;RUN &lt;/b&gt;or &lt;b&gt;DATASHEET &lt;/b&gt;view icon in the &lt;b&gt;RESULTS &lt;/b&gt;group of the &lt;b&gt;QUERY DESIGN &lt;/b&gt;ribon the see the query results&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWmLlRgRNUlQf09f3Q5VLmwFDvNjBF4nBoTpKLeRXObAPgdtAi1EwpdATRGWaNcVhf87IIfNxlzoNpo7e-ccxt2mhesWr5AZkBK4N05sneHz2msAmdg5LO2dzDfqIApBIZ9ch3W3hWnqsUMZRhj4wegTRuUM04EwmvrxpMuD0v7yWOec_TC7Foze41YFs/s1192/qryDubiousRecord-query-results.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;138&quot; data-original-width=&quot;1192&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWmLlRgRNUlQf09f3Q5VLmwFDvNjBF4nBoTpKLeRXObAPgdtAi1EwpdATRGWaNcVhf87IIfNxlzoNpo7e-ccxt2mhesWr5AZkBK4N05sneHz2msAmdg5LO2dzDfqIApBIZ9ch3W3hWnqsUMZRhj4wegTRuUM04EwmvrxpMuD0v7yWOec_TC7Foze41YFs/s16000/qryDubiousRecord-query-results.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The first record returned by our query is for a property with the postcode WA14 5DY which (if you scroll across) is actually located in the town of Altrincham.&amp;nbsp; If you are familiar with the geography of Greater Manchester you will know that this town is in the borough of Trafford rather than Salford. As such, this record does not belong in our dataset and should be removed.&amp;nbsp; When we examine the data for the remaining three records, it is apparent that they pertain to land in a commerce park, a parking space, and a brown field site. As such they fall outside the scope of our interest in house sales, and can also be removed from our dataset. Its worth reflecting that had we not done this check, our dataset would have inaccurate to the value of £10,249,999.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;A good way to remove these records from the dataset is to go back into QUERY DESIGN view and change the query type from &lt;b&gt;SELECT &lt;/b&gt;to &lt;b&gt;DELETE&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDwwN2m6Ghtgh4vhA4aLeYo42JAhykSJXVsdeGd-Lo9_PVed-RyCxlzFYFHkdDSKzMKmDZTcStGVjuKHLYY9uP5xalt6Q9RpBrxNI7xB984bFwWiFTuJEx0rXAO3NBU7skPfVO7fRn-X7PHbowAa5Uy87vUVwlRvXIYZYScTybZWBEFNOxtPMxMnfFS-k/s586/delete-query.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;586&quot; data-original-width=&quot;501&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDwwN2m6Ghtgh4vhA4aLeYo42JAhykSJXVsdeGd-Lo9_PVed-RyCxlzFYFHkdDSKzMKmDZTcStGVjuKHLYY9uP5xalt6Q9RpBrxNI7xB984bFwWiFTuJEx0rXAO3NBU7skPfVO7fRn-X7PHbowAa5Uy87vUVwlRvXIYZYScTybZWBEFNOxtPMxMnfFS-k/s16000/delete-query.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;After changing the query type from SELECT to DELETE, you will see an addition row appear in the query grid entitled &quot;Delete&quot;.&amp;nbsp; You will also see that Access has filled in the values for this row.&amp;nbsp; In the first column it has added &quot;From&quot; which means the records are being deleted from the &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;table, and in the second column it has added &quot;Where&quot; which means all records in the table matching our criterion &lt;span style=&quot;color: #073763; font-family: verdana;&quot;&gt;&lt;b&gt;Is Null Or Like &quot;WA1*&quot;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt; &lt;/span&gt;will be deleted.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the &lt;b&gt;RUN &lt;/b&gt;icon in the &lt;b&gt;RESULTS &lt;/b&gt;group of the &lt;b&gt;QUERY DESIGN &lt;/b&gt;ribbon to run the delete query.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Access will display a warning dialog saying that the 4 rows containing dubious records are going to be deleted from our table.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZz3wHUtVgnrw73Un2YA7SNu0JHPiT2IABettxX7sJdtbLkKOWCGQCoW56-k_tq6sF9lldzC1rHlGX8hwb4dxGw7-IWK0GPaufuBWfQrhA0rv9Oxw82rboaOtsEmYObwGXijV51Dd0hNtSNBL2NuMvcqXFlhnWWA57Iem-tyMKRRaYelDPWBDYYNCAfBA/s475/delete%20query%20dialog%20warning.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;131&quot; data-original-width=&quot;475&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZz3wHUtVgnrw73Un2YA7SNu0JHPiT2IABettxX7sJdtbLkKOWCGQCoW56-k_tq6sF9lldzC1rHlGX8hwb4dxGw7-IWK0GPaufuBWfQrhA0rv9Oxw82rboaOtsEmYObwGXijV51Dd0hNtSNBL2NuMvcqXFlhnWWA57Iem-tyMKRRaYelDPWBDYYNCAfBA/s16000/delete%20query%20dialog%20warning.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click &lt;b&gt;YES &lt;/b&gt;to continue the delete operation.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If we now go back and reopen &lt;b&gt;tblSalfordHouseSales &lt;/b&gt;the record count will now show 2942 records, 4 less than the 2946 records we had previously.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiN6YAtUERBYPVTfeKXkmChLViD5Vte1BldlB3_kvPGDfbV7mOUJnSUxx3KHqYbnZmm7Lm6dEa-JSiEN20uHwoXWYoKBfqiyoTy610CKXG-vhFnNbDGxtIWFNGyWCKBril8Ei0_w-P7VsNRNC-Ghy_2Uj7WuWLQRQ0ySVGukQKnnx1roGyMQD1QoJeGJ3M/s195/record%20count.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;22&quot; data-original-width=&quot;195&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiN6YAtUERBYPVTfeKXkmChLViD5Vte1BldlB3_kvPGDfbV7mOUJnSUxx3KHqYbnZmm7Lm6dEa-JSiEN20uHwoXWYoKBfqiyoTy610CKXG-vhFnNbDGxtIWFNGyWCKBril8Ei0_w-P7VsNRNC-Ghy_2Uj7WuWLQRQ0ySVGukQKnnx1roGyMQD1QoJeGJ3M/s16000/record%20count.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are many other checks that we can do to ensure our dataset is clean, but the steps mentioned above give us an idea of how we can use Access&#39;s queries and other features in this process.&amp;nbsp; Let us now move on and see how we can use Access to analyse our dataset.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Analysing Data with Access Queries&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To illustrate how Access can be used to make sense of our housing sale dataset, we are going to create a number of price bands and count the number of sales in each band. This will give us a basic understanding of the housing market in Salford during 2023.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This task will involve the creation of a subquery for each individual price band, and a parent query to pull together the sale counts within each band, showing them all in one row of aggregate data.&amp;nbsp; Lets begin with the subqueries.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We are going to create a total of seven price bands as follows:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;PRICE BAND&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;SUBQUERY&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;lt; £100,000&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;qrySubBelow100K&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= £100,000 and &amp;lt; £200,000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; qrySub100Kto200K&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= £200,000 and &amp;lt; £300,000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; qrySub200Kto300K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= £300,000 and &amp;lt; £400,000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; qrySub300Kto400K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= £400,000 and &amp;lt; £500,000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; qrySub400Kto500K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= £500,000 and &amp;lt; £1,000,000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;qrySub500Kto1000K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= £1,000,000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;qrySubAbove1000K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span&gt;Each of the above queries is based on the &lt;b&gt;unique_id&lt;/b&gt; and &lt;b&gt;price_paid&lt;/b&gt; fields of &lt;b&gt;tblSalfordHouseSales.&amp;nbsp; &lt;/b&gt;Once again, the query is going to use the &lt;b&gt;TOTALS &lt;/b&gt;row in the &lt;b&gt;QUERY DESIGN&lt;/b&gt; grid because we need to aggregate the data returned.&amp;nbsp; We are going to set up our query to count the number of rows returned in the dataset when we add a criterion to the &lt;b&gt;price_paid&lt;/b&gt; field. To do this we shall set the value in the TOTALS row of the &lt;b&gt;unique_id &lt;/b&gt;column to &lt;b&gt;COUNT&lt;/b&gt;,&amp;nbsp; and the value of the &lt;b&gt;TOTALS &lt;/b&gt;row of the &lt;b&gt;price_paid &lt;/b&gt;column to &lt;b&gt;WHERE&lt;/b&gt;.&amp;nbsp; All we need to do then is enter the criterion in the &lt;b&gt;CRITERIA &lt;/b&gt;row of the &lt;b&gt;price_paid &lt;/b&gt;column.&amp;nbsp; For example, when we create &lt;b&gt;qrySubBelow100K &lt;/b&gt;to count the number of sales less than £100,000&amp;nbsp; the criterion we enter is&amp;nbsp;&amp;nbsp;&lt;b&gt;&amp;lt;100000 &lt;/b&gt;as in the screenshot below:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3IJIjYLT8DFeh_PMb0jVeQQfA1OUBTlbJyAR8OReXSL-t0saMcnnnfD4JdAPP6Sb5GlNbby6nhdEOIhDF5EKUqk37vLueLqEmYFHrSxppfyLwrMs4Lag-AKhrdc_lAgGsDDbluz2sOgyNCeM5oG2HzeXajgbUEsm1McGS86HIpCrTgQWfspQfvYuRBbo/s428/subqueries.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;428&quot; data-original-width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3IJIjYLT8DFeh_PMb0jVeQQfA1OUBTlbJyAR8OReXSL-t0saMcnnnfD4JdAPP6Sb5GlNbby6nhdEOIhDF5EKUqk37vLueLqEmYFHrSxppfyLwrMs4Lag-AKhrdc_lAgGsDDbluz2sOgyNCeM5oG2HzeXajgbUEsm1McGS86HIpCrTgQWfspQfvYuRBbo/s16000/subqueries.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;You may have noticed how the tickbox in the SHOW row &lt;br /&gt;of the&amp;nbsp;QUERY DESIGN grid is unticked when we select WHERE&amp;nbsp;&lt;br /&gt;in the TOTAL row for &lt;b&gt;price_paid&lt;/b&gt;. This is because the only purpose&amp;nbsp;&lt;br /&gt;of the &lt;b&gt;price_paid&lt;/b&gt; column is to filter the rows to be included in the &lt;br /&gt;count&amp;nbsp;of&amp;nbsp;&lt;b&gt;unique_id&lt;/b&gt;&#39;s.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;When we run the query a single row and column is returned with the count of &lt;b&gt;unique_id&lt;/b&gt;&#39;s matching the query criterion entered for &lt;b&gt;price_paid&lt;/b&gt;. For records with a price paid value less than £100,000 this should value should be &lt;b&gt;140&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilE5UK53QOoo6Uh-QteIpbhyXWzcKt0cXgOpZsss_eTl5TYL9ZoY1ktWH7R20bvzA0uLybqFYLurgWt3AVXNq6788t0zsIYzpUifg2-fnTmvamtzw2p6NLGee39Htauhw8GAxYk-v4OjT1v70H1j7LtooFJ7-QRln_WSwRmQrR0Kbn25tvUn1m4wvoQnY/s189/subquery-results.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;99&quot; data-original-width=&quot;189&quot; height=&quot;99&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilE5UK53QOoo6Uh-QteIpbhyXWzcKt0cXgOpZsss_eTl5TYL9ZoY1ktWH7R20bvzA0uLybqFYLurgWt3AVXNq6788t0zsIYzpUifg2-fnTmvamtzw2p6NLGee39Htauhw8GAxYk-v4OjT1v70H1j7LtooFJ7-QRln_WSwRmQrR0Kbn25tvUn1m4wvoQnY/s1600/subquery-results.jpg&quot; width=&quot;189&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Here are the instructions for creating the subqueries for the seven price bands.&amp;nbsp; We will need to repeat this process seven times for each of the subquerie:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;div&gt;1. Create a new query by clicking the&amp;nbsp;&lt;b&gt;QUERY DESIGN&amp;nbsp;&lt;/b&gt;icon on the&amp;nbsp;&lt;b&gt;CREATE&amp;nbsp;&lt;/b&gt;ribbon.&lt;/div&gt;&lt;div&gt;2. Click the&amp;nbsp;&lt;b&gt;ADD TABLES&amp;nbsp;&lt;/b&gt;icon (on the&amp;nbsp;&lt;b&gt;QUERY DESIGN&amp;nbsp;&lt;/b&gt;ribbon) to display the ADD TABLES sidebar if it is not visible already.&lt;/div&gt;&lt;div&gt;3. Drag the&amp;nbsp;&lt;b&gt;tblSalfordHouseSales&amp;nbsp;&lt;/b&gt;table from the&amp;nbsp;&lt;i&gt;tables&amp;nbsp;&lt;/i&gt;list in the sidebar over to the QUERY DESIGN window.&lt;/div&gt;&lt;div&gt;4. Click the&amp;nbsp;&lt;b&gt;TOTALS&amp;nbsp;&lt;/b&gt;icon in the&amp;nbsp;&lt;b&gt;SHOW/HIDE&amp;nbsp;&lt;/b&gt;group of the&amp;nbsp;&lt;b&gt;QUERY DESIGN&amp;nbsp;&lt;/b&gt;ribbon&lt;/div&gt;&lt;div&gt;5.In the first column of the &lt;b&gt;QUERY DESIGN &lt;/b&gt;grid, select the &lt;b&gt;unique_id &lt;/b&gt;field from the drop down list in the top row.&lt;/div&gt;&lt;div&gt;6. We now need to go down to the &lt;b&gt;TOTAL &lt;/b&gt;row in the first column and select &lt;b&gt;COUNT &lt;/b&gt;from the drop down list.&lt;/div&gt;&lt;div&gt;7. In the second column of the &lt;b&gt;QUERY DESIGN &lt;/b&gt;grid, select the &lt;b&gt;price_paid &lt;/b&gt;field from the drop down list.&lt;/div&gt;&lt;div&gt;8. Going down to the &lt;b&gt;TOTAL&amp;nbsp;&lt;/b&gt;row of the second column, select &lt;b&gt;WHERE &lt;/b&gt;from the drop down list.&lt;/div&gt;&lt;div&gt;9. We now need to enter the criterion in the &lt;b&gt;CRITERIA &lt;/b&gt;row of the second column.&amp;nbsp; The criterion we enter depends which of the seven subqueries we are working on.&amp;nbsp; The criterion for&amp;nbsp;&lt;b&gt;qrySubBelow100K&lt;/b&gt;, for example, is &lt;b&gt;&amp;lt;100000&lt;/b&gt;. The criteria for all seven queries are listed in the table below.&lt;/div&gt;&lt;div&gt;10. Click the &lt;b&gt;SAVE &lt;/b&gt;icon at the top left of the screen and the name of subquery that we were creating.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;WHERE CRITERIA&lt;/b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&lt;b&gt;SUBQUERY&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;lt; 100000&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;qrySubBelow100K&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= 100000 AND &amp;lt; 200000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;qrySub100Kto200K&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= 200000 AND&amp;nbsp;&amp;lt; 300000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;qrySub200Kto300K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= 300000 AND&amp;nbsp;&amp;nbsp;&amp;lt; 400000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; qrySub300Kto400K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= 400000 AND&amp;nbsp;&amp;lt; 500000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;qrySub400Kto500K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= 500000 AND&amp;nbsp;&amp;lt; 100000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;qrySub500Kto1000K&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;gt;= 1000000&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;qrySubAbove1000K&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;In addition to the seven subqueries above, we shall also create another subquery (&lt;/span&gt;&lt;b style=&quot;text-align: justify;&quot;&gt;qrySubCountAll&lt;/b&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;) to give us a grand total for 2023 Salford house sales across all price bands.&amp;nbsp; This subquery is the same as those we created above, except we do NOT need the &lt;b&gt;price_paid &lt;/b&gt;column or any &lt;b&gt;WHERE &lt;/b&gt;clause therein. We just need the COUNT in the &lt;b&gt;unique_id &lt;/b&gt;column as in all the previous subqueries:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4DphMXV2ncXWZM2DKTw0Xood4IHXip8ofK94lNM4z7ycwyStlQ9Z1ou2B19DMEwuOJDxyHW0yDo-KIIlQXk35k52bBjD9pnnwLWK8IImZAEok3Kffe8d3M9nVtApxbJNU_eGljhLYZvwLQTvwt8H_kk8qQvg-pCuYEtWUpiqQGMFJBwIUGrOLk3kkLv0/s360/qrySubCountAll.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;360&quot; data-original-width=&quot;281&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4DphMXV2ncXWZM2DKTw0Xood4IHXip8ofK94lNM4z7ycwyStlQ9Z1ou2B19DMEwuOJDxyHW0yDo-KIIlQXk35k52bBjD9pnnwLWK8IImZAEok3Kffe8d3M9nVtApxbJNU_eGljhLYZvwLQTvwt8H_kk8qQvg-pCuYEtWUpiqQGMFJBwIUGrOLk3kkLv0/s16000/qrySubCountAll.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;When this query is run we get the same output format as the previous seven subqueries (see screenshot below).&amp;nbsp; The result is a count of all house sales in &lt;b&gt;tblSalfordHouseSales&lt;/b&gt;.&amp;nbsp; This should be 2942.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn_an3HXsIt1gemuq2ntpOsf2hCkd1N7be68UPIXsTgyfe2az75-in786jkeRiXLvFUUPjyaBNIG5mxVEedOihYW3S1YCYYIVQEARz9hTHlB44PV4_wadU3zf0qCKjd_LDQxiu6bS945dzKWC3EEhz8MQhLHGHCYwazNdEjU8cKLcBrnhgm24d07a5GoY/s179/count-all-subquery-output.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;77&quot; data-original-width=&quot;179&quot; height=&quot;77&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn_an3HXsIt1gemuq2ntpOsf2hCkd1N7be68UPIXsTgyfe2az75-in786jkeRiXLvFUUPjyaBNIG5mxVEedOihYW3S1YCYYIVQEARz9hTHlB44PV4_wadU3zf0qCKjd_LDQxiu6bS945dzKWC3EEhz8MQhLHGHCYwazNdEjU8cKLcBrnhgm24d07a5GoY/s1600/count-all-subquery-output.jpg&quot; width=&quot;179&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now we have created all our subqueries we can begin work on the parent query which pulls all the subquery results together in one row of aggregate data.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;The Parent Query&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We are going to call our parent query &lt;b&gt;qryHousePriceGroups&lt;/b&gt;.&amp;nbsp; Each column in the query will display the aggregate total count of house sales for each of the price bands.&amp;nbsp; The last column will display the grand total.&amp;nbsp; To do this we will need to add all 8 subqueries we created to the &lt;b&gt;QUERY DESIGN &lt;/b&gt;grid window and use the appropriate subquery as the data source for each of the parent query columns.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI2lgWnw6T3ekid6uCdkO1VPE3N3Bo6VfIvua01jc0fswcQzClD0HEcKxcR9_qzqyrtk6cE4t9zLMVBrVaujQWepLUHGJFiapzb8IZtjq_XNIgH_lXAuKD3tgGCgYM5F4v_Z1_m-dkOPmw4L1PFpZUQRHKH9AP0Jyj7I7blaN03mbvXu9lRwf3X0pMyIw/s1283/qryHousePriceGroups.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;645&quot; data-original-width=&quot;1283&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI2lgWnw6T3ekid6uCdkO1VPE3N3Bo6VfIvua01jc0fswcQzClD0HEcKxcR9_qzqyrtk6cE4t9zLMVBrVaujQWepLUHGJFiapzb8IZtjq_XNIgH_lXAuKD3tgGCgYM5F4v_Z1_m-dkOPmw4L1PFpZUQRHKH9AP0Jyj7I7blaN03mbvXu9lRwf3X0pMyIw/s16000/qryHousePriceGroups.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As we can see in the screenshot above, we have given each column name an alias such as &quot;Below 100K&quot; and &quot;100K to 200K&quot;.&amp;nbsp; This will make the query output easier for users to read and understand.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Here are the step by step instructions for creating the parent query.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Create a new query by clicking the&amp;nbsp;&lt;b&gt;QUERY DESIGN&amp;nbsp;&lt;/b&gt;icon on the&amp;nbsp;&lt;b&gt;CREATE&amp;nbsp;&lt;/b&gt;ribbon.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Click the&amp;nbsp;&lt;b&gt;ADD TABLES&amp;nbsp;&lt;/b&gt;icon (on the&amp;nbsp;&lt;b&gt;QUERY DESIGN&amp;nbsp;&lt;/b&gt;ribbon) to display the ADD TABLES sidebar if it is not visible already.&amp;nbsp; Then select the &lt;b&gt;QUERIES &lt;/b&gt;tab at the top of the sidebar.&amp;nbsp; You should see all the subqueries that we have created previously.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Drag all 8 subqueries over to the &lt;b&gt;QUERY DESIGN &lt;/b&gt;window.&amp;nbsp; We will now start to dragging the &lt;b&gt;CountOfUnique_id &lt;/b&gt;fields from each subquery onto the &lt;b&gt;QUERY DESIGN &lt;/b&gt;grid below.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. The first &lt;b&gt;CountOfUnique_id &lt;/b&gt;field we are going to drag is from the &lt;b&gt;qrySubBelow100K &lt;/b&gt;subquery.&amp;nbsp; Drag this down to the cell in the top row of the first column in the grid.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;5. We shall now enter the alias name for the column.&amp;nbsp; We do this by typing the name &lt;b&gt;Below 100K&amp;nbsp;&lt;/b&gt;in the same cell just before &lt;b&gt;CountOfUnique_id &lt;/b&gt;separated from it by a colon as follows:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;Below 100K: CountOfUnique_id&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;6. In the top row of the next column, we are going to drag &lt;b&gt;CountOfUnique_id &lt;/b&gt;from the&amp;nbsp;&lt;b&gt;qrySub100Kto200K&lt;/b&gt;&amp;nbsp;subquery.&amp;nbsp; We shall give this the alias &lt;b style=&quot;color: #20124d; font-family: verdana;&quot;&gt;100K to 200K&lt;/b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;7. Repeat step 6 for each of the subqueries using the following alias&#39;s:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;200K to 300K:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;300K to 400K:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;400K to 500K:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;500K to 1000K:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;Above 1000K:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #20124d; font-family: verdana;&quot;&gt;&lt;b&gt;All:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When we run the query we should get this result:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAv99SZFDSQ5jCZ-t_R1MIaGSVnf95AYGMYl4nB_jzZXsfy_KU_w4piFKgW7fPu97BeBftwKQLf3vQDtWo-bL3yN9eNGAirUo44us2ypXVqXRUiFNc8N4ElVjxWhB_freGMqeuiJspYqZuY9Ty7pGt3pjQosZ_jY0eEv-w2dCm3g8da9cY_Jg1pytnB5c/s923/qryHousePriceGroups-output.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;86&quot; data-original-width=&quot;923&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAv99SZFDSQ5jCZ-t_R1MIaGSVnf95AYGMYl4nB_jzZXsfy_KU_w4piFKgW7fPu97BeBftwKQLf3vQDtWo-bL3yN9eNGAirUo44us2ypXVqXRUiFNc8N4ElVjxWhB_freGMqeuiJspYqZuY9Ty7pGt3pjQosZ_jY0eEv-w2dCm3g8da9cY_Jg1pytnB5c/s16000/qryHousePriceGroups-output.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As we can see, out of a total of 2,942 house sales, the vast majority fall within the 100K to 200K, and 200k to 300K price groups.&amp;nbsp; The 100K to 200K group contains 1,258 sales, and the 200K to 300K group contains 992 sales, giving a total of&amp;nbsp; 2,250 sales out of 2,942, or 76% of the total 2023 Salford housing sale count. The figures also reflect the fact that Salford has some poorer districts as well as those which are very affluent.&amp;nbsp; There were 140 house sales (5%) with&amp;nbsp; property values of less than £140,000, but 100 sales (5%) with values between £500,000 and £1000,000, and 26 sales (1%) above £1000,000.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Lets end by showing this data visually in a clustered column chart embedded&amp;nbsp; in an Access report.&amp;nbsp; Here are the step by step instructions:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Click the &lt;b&gt;REPORT DESIGN &lt;/b&gt;icon in the &lt;b&gt;REPORTS &lt;/b&gt;group of the &lt;b&gt;CREATE &lt;/b&gt;ribbon.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Resize the &lt;b&gt;REPORT DESIGN &lt;/b&gt;grid so we get a larger section of screen in which to create the chart.&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Click the &lt;b&gt;INSERT MODERN CHART &lt;/b&gt;drop down menu in the &lt;b&gt;CONTROLS &lt;/b&gt;group of the &lt;b&gt;REPORT DESIGN &lt;/b&gt;ribbon.&amp;nbsp; We are going to select the &lt;b&gt;CLUSTERED COLUMN CHART &lt;/b&gt;from the &lt;b&gt;COLUMN &lt;/b&gt;submenu.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6FGxNN8QGuhAJjUXPrhXV-xcKCFexUdvaOQHbmXrqwZAyBFPJBBSBy55TDwbCB-jg2F0bAlp8iBuBMGsGEEsCFxfyIsnMpCLY8SNBDpNAp-eVfm_tv8CHFR18hzxAsdAEau9YY7g34q53DCb5NrccIMaeeeqkN__Hs1DSSjZtUl4RNY-xJANUO553wlQ/s396/clustered%20column%20chart%20icon.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;368&quot; data-original-width=&quot;396&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6FGxNN8QGuhAJjUXPrhXV-xcKCFexUdvaOQHbmXrqwZAyBFPJBBSBy55TDwbCB-jg2F0bAlp8iBuBMGsGEEsCFxfyIsnMpCLY8SNBDpNAp-eVfm_tv8CHFR18hzxAsdAEau9YY7g34q53DCb5NrccIMaeeeqkN__Hs1DSSjZtUl4RNY-xJANUO553wlQ/s320/clustered%20column%20chart%20icon.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. The cursor will now change to a small chart symbol.&amp;nbsp; Position the cursor in the top left hand corner of the &lt;b&gt;DETAIL &lt;/b&gt;section of the design grid.&amp;nbsp; A small chart will embed itself on the grid.&amp;nbsp; At this stage we just have sample data displayed in the chart.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;5. Resize the chart by clicking it&#39;s border on the bottom left corner and dragging the corner down and across so we get a bigger chart.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs_Igs8UeCypb8Reit6kxm8JhLa0SsHiw9pKV_gSDHAZ4zQNtBqcQU8BhFbgM59Eie-3v8ItACoDj9vImPpRbFKNbfMRbjQH0CvQ15fq_rYdufqM_FyeOoxZf0KA13E7Sqlnv32QVaPnQqx5XWENAyXOLB1E4vHZfOq1bSeeBjhid27RR_lGlygHWCU_E/s945/embed%20chart.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;643&quot; data-original-width=&quot;945&quot; height=&quot;218&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs_Igs8UeCypb8Reit6kxm8JhLa0SsHiw9pKV_gSDHAZ4zQNtBqcQU8BhFbgM59Eie-3v8ItACoDj9vImPpRbFKNbfMRbjQH0CvQ15fq_rYdufqM_FyeOoxZf0KA13E7Sqlnv32QVaPnQqx5XWENAyXOLB1E4vHZfOq1bSeeBjhid27RR_lGlygHWCU_E/s320/embed%20chart.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;New chart showing sample data.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;6. We will now connect the chart to our parent query. We can do this from the&amp;nbsp;&lt;b&gt;CHART SETTINGS&lt;/b&gt;&amp;nbsp;sidebar. Click anywhere inside the chart so it is selected. Then click the &lt;b&gt;CHART SETTINGS &lt;/b&gt;icon in the &lt;b&gt;TOOLS &lt;/b&gt;group of the &lt;b&gt;REPORT DESIGN &lt;/b&gt;ribbon (if the sidebar is not displayed already).&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzIDsYS2vCnj_oYXhmmcg4KWFHrMoQ7x2vioABSiBGNb5p3GkD0ym9CgKSQ2HDhLAtXA4LZ2uAkrDis0XLVTl2K6PLXbr0JYUk_LBq2RGCTHRFB9G52eNgl9gsd3ZXLgypcwHfIGn9tN_bsOQ9GpefgZ3Cyy4IOIS2TVP25xpQjwrL8bhZm7xHDK4KdfM/s504/chart%20settings%20sidebar.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;504&quot; data-original-width=&quot;321&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzIDsYS2vCnj_oYXhmmcg4KWFHrMoQ7x2vioABSiBGNb5p3GkD0ym9CgKSQ2HDhLAtXA4LZ2uAkrDis0XLVTl2K6PLXbr0JYUk_LBq2RGCTHRFB9G52eNgl9gsd3ZXLgypcwHfIGn9tN_bsOQ9GpefgZ3Cyy4IOIS2TVP25xpQjwrL8bhZm7xHDK4KdfM/s16000/chart%20settings%20sidebar.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;7.&amp;nbsp; Click the &lt;b&gt;QUERIES &lt;/b&gt;radio button under &lt;b&gt;DATA SOURCE, &lt;/b&gt;then select the parent query that we created earlier from the drop down list.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;8. Go down to the &lt;b&gt;VALUES (Y axis) &lt;/b&gt;section below.&amp;nbsp; You will see a list of checkboxes with the price bands we created in our query. Tick each of the boxes except &lt;b&gt;ALL&lt;/b&gt;. That is from &lt;b&gt;Below 100K &lt;/b&gt;down to &lt;b&gt;Above 1000K&lt;/b&gt;. You will notice there is a&amp;nbsp;&lt;b&gt;COUNT OF &lt;/b&gt;aggregate function contained within brackets after each of the check box labels. We need to change the aggregate function to &lt;b&gt;NONE &lt;/b&gt;by clicking the drop down list which appears when you hover the mouse over the text. You should now see the data from our parent query appear on the chart. We now need to customise the appearance of the chart to make it more user friendly.&lt;/div&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0xFH5E_QTkjg4XGDnuu9GyA9M1q-Pgj1LZT1sxKvTPRDxCKKrhIsR_0OgjwKNpLfnBkEWd4xiWRD8cPd4laafKmYeA_vAgVN_D8C3lT8GXXcCjTjiD9es0wQKv8gUSJV6WWkv3VGkvKVKw2hq5NntcmvBe3U9M8o9y2oMMFNUBKIoQHl-oQIR_UAUwpE/s846/customise%20chart.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;421&quot; data-original-width=&quot;846&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0xFH5E_QTkjg4XGDnuu9GyA9M1q-Pgj1LZT1sxKvTPRDxCKKrhIsR_0OgjwKNpLfnBkEWd4xiWRD8cPd4laafKmYeA_vAgVN_D8C3lT8GXXcCjTjiD9es0wQKv8gUSJV6WWkv3VGkvKVKw2hq5NntcmvBe3U9M8o9y2oMMFNUBKIoQHl-oQIR_UAUwpE/s320/customise%20chart.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Chart showing parent query data ready&lt;br /&gt;to be customised.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;9. The first customisation we shall make is the addition of a data label above each chart column.&amp;nbsp; This shows the value for the count of sales for each of the price bands. To do this select the &lt;b&gt;FORMAT &lt;/b&gt;tab at the top of the &lt;b&gt;CHART SETTINGS&lt;/b&gt; side bar. Select the first price band &lt;b&gt;Below 100K &lt;/b&gt;from the drop down list under the&amp;nbsp;&lt;b&gt;DATA SERIES &lt;/b&gt;title. Then tick the &lt;b&gt;Display Data Label&lt;/b&gt;&amp;nbsp;checkbox.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirQyFz6w1Wp4JvvE8uGA3bTpENqFIv7UFFz4fsOfQox86Haf7uc4_2BzeU0eWvbmoxWb_Ld2wYd7XpqNitfSRMi4l2LGoqZc29tqYGeT3PjQHWFU1A-drUxeKrjLrRlV1v0BluhJDcWmyNRmAWgnfRjWO7-ajtzxWDqF54OcCM7BU-EYAaRVlms9aRXnE/s513/format%20tab.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;513&quot; data-original-width=&quot;337&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirQyFz6w1Wp4JvvE8uGA3bTpENqFIv7UFFz4fsOfQox86Haf7uc4_2BzeU0eWvbmoxWb_Ld2wYd7XpqNitfSRMi4l2LGoqZc29tqYGeT3PjQHWFU1A-drUxeKrjLrRlV1v0BluhJDcWmyNRmAWgnfRjWO7-ajtzxWDqF54OcCM7BU-EYAaRVlms9aRXnE/s16000/format%20tab.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;You should now see the value 140 appear above the &lt;b&gt;Below 100K &lt;/b&gt;column on the chart.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;10. Select the next price band from the &lt;b&gt;Data Series &lt;/b&gt;drop down list and tick the &lt;b&gt;Display Data Label &lt;/b&gt;checkbox. Do this for the rest of the price band columns on the chart.&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;11. For the remaining customisations, we are going to use the chart property sheet. Click anywhere inside the chart so it is selected, then click the &lt;b&gt;PROPERTY SHEET &lt;/b&gt;icon from the &lt;b&gt;TOOLS &lt;/b&gt;group of the &lt;b&gt;REPORT DESIGN &lt;/b&gt;ribbon.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;12. The next customisation we are going to make is the addition of a chart title. Select the &lt;b&gt;FORMAT &lt;/b&gt;tab on the property sheet and locate the &lt;b&gt;HAS TITLE &lt;/b&gt;and &lt;b&gt;CHART TITLE &lt;/b&gt;properties further down the sheet.&amp;nbsp; Ensure the &lt;b&gt;HAS TITLE &lt;/b&gt;property is set to &lt;b&gt;YES&lt;/b&gt;, and enter &quot;&lt;b&gt;2023 Salford House Sales&lt;/b&gt;&quot; for the &lt;b&gt;CHART TITLE&lt;/b&gt;&amp;nbsp;property value.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1IMYF9CPEItQZhm9GZqrSUxS2eBVJdb-UCmB6cYHzpKmGn-qFVWemZghJC_2riIqXxNzkbN8dFOJJ9_tTiodlNGV1M_ezazb_jCRJx8JqGKbS44OcFOsUWdB_BCKjytreKTqQ-SuBemA8Pmi233M9pUSU-y5rnw9Mj0vW1r7GVwIC1MyDGtHhawlwgyg/s379/chart%20title%20properties.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;356&quot; data-original-width=&quot;379&quot; height=&quot;301&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1IMYF9CPEItQZhm9GZqrSUxS2eBVJdb-UCmB6cYHzpKmGn-qFVWemZghJC_2riIqXxNzkbN8dFOJJ9_tTiodlNGV1M_ezazb_jCRJx8JqGKbS44OcFOsUWdB_BCKjytreKTqQ-SuBemA8Pmi233M9pUSU-y5rnw9Mj0vW1r7GVwIC1MyDGtHhawlwgyg/s320/chart%20title%20properties.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;13. We shall next move the legend from the top of the chart to the bottom.&amp;nbsp; To do this locate &lt;b&gt;Legend Position &lt;/b&gt;also on the &lt;b&gt;FORMAT &lt;/b&gt;tab of&amp;nbsp;the property sheet.&amp;nbsp; Change the property value to &quot;&lt;b&gt;bottom&lt;/b&gt;&quot;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;14. The final customisations we are going to make involve adding a title to the vertical axis and remove the text saying &quot;140&quot; below the horizonal axis.&amp;nbsp; To do this locate the &lt;b&gt;primary values axis title &lt;/b&gt;on the property sheet and change the value to &quot;&lt;b&gt;Count of Sales&lt;/b&gt;&quot;;&amp;nbsp; and then locate the &lt;b&gt;category axis font color &lt;/b&gt;property, click the ellipse button (...) in the value cell, and select &lt;b&gt;white &lt;/b&gt;from the colour chart.&amp;nbsp; This will hide the unwanted text from view.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-B3rxz66_7EQ-6ir3245TwEaSLQOgjWGTDs6ComAb1mZysDM3qk0zlED-NYScVhC3dWaDMmb5SDkkr_kFCw6iRIH6HZ98Os4FKwQAp1-ygbH0wOcN6AgrVpkf41V7bEBUh_d9m1cakoWVyUUjUrCZrUcc7dJIhgGnCag_rI39PwmL9lK75YGBW8j9Y2A/s652/legend%20and%20axis%20properties.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;652&quot; data-original-width=&quot;384&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-B3rxz66_7EQ-6ir3245TwEaSLQOgjWGTDs6ComAb1mZysDM3qk0zlED-NYScVhC3dWaDMmb5SDkkr_kFCw6iRIH6HZ98Os4FKwQAp1-ygbH0wOcN6AgrVpkf41V7bEBUh_d9m1cakoWVyUUjUrCZrUcc7dJIhgGnCag_rI39PwmL9lK75YGBW8j9Y2A/s16000/legend%20and%20axis%20properties.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;15. We can now open the report by clicking the &lt;b&gt;REPORT VIEW &lt;/b&gt;button on the &lt;b&gt;VIEWS &lt;/b&gt;group of the&amp;nbsp;&lt;b&gt;&amp;nbsp;REPORT DESIGN &lt;/b&gt;ribbon. The result should look like the screenshot below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0Tr1GrUnwcfbyEaWXuiTZgvSb-c-NGG3LH1Ocv8QPegKig_AlQotdsdmLJ817a1hBAa1c6zV57ZbM86VR4Fk7TYpXURg7gXplJg9iuEgBUA_wv7J3fQZofJJqHz61CB5lz2Q43GBYVRvWlgcoiRGXDlIvMFAR7lBKDid3QTDvRT0OMVmwya2Zrfg6vvk/s838/property%20sale%20count%20chart.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;415&quot; data-original-width=&quot;838&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0Tr1GrUnwcfbyEaWXuiTZgvSb-c-NGG3LH1Ocv8QPegKig_AlQotdsdmLJ817a1hBAa1c6zV57ZbM86VR4Fk7TYpXURg7gXplJg9iuEgBUA_wv7J3fQZofJJqHz61CB5lz2Q43GBYVRvWlgcoiRGXDlIvMFAR7lBKDid3QTDvRT0OMVmwya2Zrfg6vvk/s16000/property%20sale%20count%20chart.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We can now see the data from our parent query in visual form, thereby gaining a clearer view of the concentration of house sales in the 100K to 200K, and 200K to 300K price bands.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are, of course, many other dimensions we can use to analyse our data.&amp;nbsp; For example, we can create queries to group house sales according to property type, and find out the average value in each group.&amp;nbsp; We could also have downloaded a larger dataset which includes sales over a number of years, and create a chart showing how prices have changes over particular timespans. I intend to cover areas such as these in future posts.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/7184765078704439406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2025/05/using-access-for-data-analysis.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/7184765078704439406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/7184765078704439406'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2025/05/using-access-for-data-analysis.html' title='Using Access for Data Analysis'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5kLbnhTzFZoYk-cFwqyiZiLjVtV_dlV1dyhRTuhKcI3VOb6Eknzki1DrUHfcwSkIBxCnHk0hR0PRzddpFIEtky8oPSt2L3WOxo9JL4z6Q3NbMe3bAmZ1kK-4t-QLE7KEjW260HIV3e2nlpOKb8_pI-AOeXZsYSv7exzZpM2lgBGHZFxbYAtFj6rf4RkM/s72-w640-h592-c/hm%20land%20registry%20form.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-8162789827068000953</id><published>2024-03-24T14:07:00.000-07:00</published><updated>2024-03-24T14:14:59.714-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="scope"/><category scheme="http://www.blogger.com/atom/ns#" term="static"/><category scheme="http://www.blogger.com/atom/ns#" term="sub procedures"/><category scheme="http://www.blogger.com/atom/ns#" term="variables"/><title type='text'>Static Variables Part 2: the Advantage of Static Variables </title><content type='html'>&lt;p style=&quot;text-align: justify;&quot;&gt;In part one of this tutorial - &lt;a href=&quot;https://ms-access-tips.blogspot.com/2024/03/using-vba-static-variables.html&quot; target=&quot;_blank&quot;&gt;Using Static Variables&lt;/a&gt; - we examined the difference in behaviour between an ordinary &lt;i&gt;local variable&lt;/i&gt; and a &lt;i&gt;static variable&lt;/i&gt;.&amp;nbsp; We learnt that whilst both types can only be referenced within the same sub procedure or function in which they were declared, the value of a static variable is retained after code in the sub procedure or function has completed execution.&amp;nbsp; The terms we used to understand this behaviour were &lt;i&gt;scope &lt;/i&gt;and &lt;i&gt;lifetime &lt;/i&gt;respectively.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In part two, this current post, we are going to consider how we can use the unique &lt;i&gt;scope&lt;/i&gt; and &lt;i&gt;lifetime &lt;/i&gt;of a static variable to our advantage.&amp;nbsp; In order to illustrate this we shall examine the workings of an &lt;i&gt;order counter &lt;/i&gt;custom control&amp;nbsp;comprised of a textbox and two control buttons.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinMcdczyG6doMgub3BTgvZRcwC2X_9FcGwv-7a6_kQT96Z3AyZ8lGZFGtcxkq0HzWCFRm1EVOjm1PYX_UYHKCzXO4lkLyzVqU3jxHHR7oqbE1MrPq-ug1hyphenhyphenMcZO_OXiP_YQ83T2R5fLZifNfqJy3loNnNPzSsKlUa7RRYvUpx48D8Ms3FQEl18PxoL524/s426/order-counter-control.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;337&quot; data-original-width=&quot;426&quot; height=&quot;253&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinMcdczyG6doMgub3BTgvZRcwC2X_9FcGwv-7a6_kQT96Z3AyZ8lGZFGtcxkq0HzWCFRm1EVOjm1PYX_UYHKCzXO4lkLyzVqU3jxHHR7oqbE1MrPq-ug1hyphenhyphenMcZO_OXiP_YQ83T2R5fLZifNfqJy3loNnNPzSsKlUa7RRYvUpx48D8Ms3FQEl18PxoL524/w320-h253/order-counter-control.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;An Order Counter Control&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;This sort of control may be familiar to you if you order your groceries online.&amp;nbsp;It usually appears under an image of a product and allows the customer to set the order amount by clicking the plus and minus buttons without having to type in the actual number in the textbox.&amp;nbsp; It is of interest to us because it lends itself to the use of a static variable to keep track of the order amount.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;The advantage of Static Variables&lt;/h3&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;So what is it about static variables that make them advantageous to use in contexts such as that of our order counter control?&amp;nbsp; To understand this lets take look at how the VBA code used to power this it is organised.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1jGQnHGfjoo-pi5hUR8WF1D5nZuS85jyZLIcxpKFjRn3ZAckwxFevoHOOMpcm_tr0DcuDtOG7EHMjDkqdEtl7kccnFNbuDA1xL7gUmMSIYTfCqftKNGmAGPbbJuOPPV-a1mkS0plTCJVKnYHK96oy2zWA0TFLmjnR_ym7l3ISUANJNflYc_X1Uccf18A/s715/order-counter-code.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;VBA Code Powering the Order Counter&quot; border=&quot;0&quot; data-original-height=&quot;715&quot; data-original-width=&quot;652&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1jGQnHGfjoo-pi5hUR8WF1D5nZuS85jyZLIcxpKFjRn3ZAckwxFevoHOOMpcm_tr0DcuDtOG7EHMjDkqdEtl7kccnFNbuDA1xL7gUmMSIYTfCqftKNGmAGPbbJuOPPV-a1mkS0plTCJVKnYHK96oy2zWA0TFLmjnR_ym7l3ISUANJNflYc_X1Uccf18A/s16000/order-counter-code.jpg&quot; title=&quot;VBA Code Powering the Order Counter&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;VBA Code Powering the Order Counter&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;As we can see, the coding for the form containing the order counter is comprised of five sub-procedures and a general declarations section where three constants, INITIALIZE, INCREMENT, and&amp;nbsp;DECREMENT are declared.&amp;nbsp; Three of these sub-procedures, &lt;b&gt;Form_Load()&lt;/b&gt;, &lt;b&gt;cmdMinus_Click()&lt;/b&gt;, and &lt;b&gt;cmdPlus_Click()&lt;/b&gt;,&amp;nbsp; contain event handling code which execute when the form opens, or the minus and plus buttons are clicked, respectively.&amp;nbsp; Each consist of one statement calling &lt;b&gt;changeOrderAmount(...)&lt;/b&gt;, the sub-procedure used to calculate the order amount displayed in the &lt;b&gt;txtOrderValue &lt;/b&gt;textbox.&amp;nbsp; This is the location where our static variable, &lt;b&gt;intOrderAmount&lt;/b&gt;, is declared.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;It is in the &lt;b&gt;changeOrderAmount(...)&lt;/b&gt; sub-procedure where the value of &lt;b&gt;intOrderAmount &lt;/b&gt;is &lt;i&gt;initialized&lt;/i&gt;, &lt;i&gt;incremented &lt;/i&gt;or &lt;i&gt;decremented&lt;/i&gt; within a&amp;nbsp;&lt;b&gt;SELECT...CASE&lt;/b&gt;&amp;nbsp;statement, which is, in turn, based on the value of the &lt;b&gt;intApplyChange&lt;/b&gt; argument it received when called. For example, if the&amp;nbsp; INCREMENT constant was received, the value of&amp;nbsp;&lt;b&gt;intOrderAmount&amp;nbsp;&lt;/b&gt;is incremented by 1.&amp;nbsp; Likewise, DECREMENT decreases the value by 1, and INITIALIZE sets the value to 0. Note the fact that the actual order amount is not set &lt;i&gt;directly &lt;/i&gt;when incremented or decremented, but is calculated from its previous value.&amp;nbsp; For this reason &lt;b&gt;intOrderAmount&amp;nbsp;&lt;/b&gt;has to &lt;i&gt;persist&lt;/i&gt; across multiple calls to the sub procedure, and is why it is declared as &lt;i&gt;Static&lt;/i&gt;.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In order to achieve the above &lt;i&gt;without &lt;/i&gt;using a static variable, we could instead declare&amp;nbsp;&lt;b&gt;intOrderAmount&amp;nbsp;&lt;/b&gt;in the&amp;nbsp;&lt;i&gt;general declarations&lt;/i&gt;&amp;nbsp;section of the form&#39;s code module using a&amp;nbsp;&lt;b&gt;Dim&amp;nbsp;&amp;nbsp;&lt;/b&gt;statement or the&amp;nbsp;&lt;b&gt;Private &lt;/b&gt;keyword. This gives the variable a&amp;nbsp;&lt;i&gt;module level&lt;/i&gt;&amp;nbsp;scope and lifetime: it can now be referenced from any sub-procedure or function within the same module, and any value it contains will be retained while the form connected to the module remains open.&amp;nbsp; As such, the module level version of&amp;nbsp;&lt;b&gt;intOrderAmount&amp;nbsp;&lt;/b&gt;has the same&amp;nbsp;&lt;i&gt;lifetime&lt;/i&gt;&amp;nbsp;as our original static version declared within the&amp;nbsp;&lt;b&gt;changeOrderAmount(...)&amp;nbsp;&lt;/b&gt;sub-procedure. However, since the variable only needs to be referenced from&amp;nbsp;&lt;i&gt;within&amp;nbsp;&lt;/i&gt;the sub-procedure, to give it module level scope in the above mentioned way will leave it unnecessarily exposed to accidental editing as well as making our code less easy to read.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;These issues arising from module level scope become more pronounced as more code is added to the module.&amp;nbsp; Other functions and sub procedures are likely to use their own variables, some of which may also have module level scope. These are generally less easy to keep track of because they can be modified from any location in the module, often under a variety of different conditions. In this sort of context it becomes increasingly difficult to read and understand our code, and&amp;nbsp; there is a greater chance of accidentally referencing a different variable to the one intended, especially if it has a similar name or performs a similar role. As such, using a static variable with a scope local to the sub-procedure or function in which it is declared, whilst also retaining it value over multiple calls, is the much better option.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Conclusion&lt;/h3&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;The advantage of using static variables lies in the fact that they are, on the one hand,&amp;nbsp; declared within a sub-procedure or function, and thereby have a local scope; and on the other hand, retain their value once code in the parent sub-procedure or function has completed execution.&amp;nbsp; As a result, the variable is protected against accidental editing from code elsewhere in the project, whilst retaining its value in order to keep a running total over multiple calls to its parent sub procedure or function.&amp;nbsp; Furthermore, since static variables are declared within sub-procedures or functions, as opposed to an external location in the project, our code is more manageable, and hence easier to read and understand.&amp;nbsp; Generally speaking, our code is more streamlined and robust.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/8162789827068000953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2024/03/static-variables-part-2-advantage-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/8162789827068000953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/8162789827068000953'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2024/03/static-variables-part-2-advantage-of.html' title='Static Variables Part 2: the Advantage of Static Variables '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinMcdczyG6doMgub3BTgvZRcwC2X_9FcGwv-7a6_kQT96Z3AyZ8lGZFGtcxkq0HzWCFRm1EVOjm1PYX_UYHKCzXO4lkLyzVqU3jxHHR7oqbE1MrPq-ug1hyphenhyphenMcZO_OXiP_YQ83T2R5fLZifNfqJy3loNnNPzSsKlUa7RRYvUpx48D8Ms3FQEl18PxoL524/s72-w320-h253-c/order-counter-control.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-420646493652718317</id><published>2024-03-09T13:05:00.000-08:00</published><updated>2024-03-24T14:09:47.906-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="static"/><category scheme="http://www.blogger.com/atom/ns#" term="sub procedures"/><category scheme="http://www.blogger.com/atom/ns#" term="variables"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Using VBA Static Variables </title><content type='html'>&lt;p style=&quot;text-align: justify;&quot;&gt;In this post we are going to look at what static variables are, how they work, and how they are different from ordinary local variables.&amp;nbsp; In a future post we will build upon this and consider &lt;a href=&quot;https://ms-access-tips.blogspot.com/2024/03/static-variables-part-2-advantage-of.html&quot; target=&quot;_blank&quot;&gt;the advantage of&amp;nbsp; using static variables&lt;/a&gt; over locals, and look at an example of how they may be used in practice.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;The Difference between Local and Static Variables&lt;/h3&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;So what are static variables exactly? To understand this, let&#39;s begin by examining how ordinary local variables work. All variable types have there own particular&amp;nbsp;&lt;i&gt;scope &lt;/i&gt;and &lt;i&gt;lifetime&lt;/i&gt;.&amp;nbsp; The first of these determines the locations within the program from which the variable can be accessed, and the latter determines how long the variable is active.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: justify;&quot;&gt;Local Variables&lt;/h4&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Local variables have a scope which is limited to the sub procedure or function from which it is declared. For example:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Private Sub testThis()&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; Dim intExample As Integer&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; intExample = 10&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; MsgBox (&quot;The value of our test variable is &quot; &amp;amp; intExample)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Here we have&amp;nbsp;declared an integer variable called &lt;b&gt;intExample&amp;nbsp;&lt;/b&gt;&lt;i&gt;within&lt;/i&gt; a sub procedure called &lt;b&gt;testThis().&amp;nbsp; &lt;/b&gt;Since the variable was declared within the sub procedure, it is &lt;i&gt;local &lt;/i&gt;in scope - the value of &lt;b&gt;10 &lt;/b&gt;it&amp;nbsp; subsequently contains can only be accessed&lt;i&gt;&amp;nbsp;&lt;/i&gt;within the &lt;b&gt;testThis()&lt;/b&gt; sub after the declaration statement. So if the &lt;b&gt;MsgBox &lt;/b&gt;Statement&amp;nbsp; referencing the &lt;b&gt;intExample&lt;/b&gt; variable is used outside the sub, the variable is not recognised.&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Furthermore, once code in the sub procedure completes execution, the &lt;b&gt;intExample &lt;/b&gt;variable ceases to exist, and it&#39;s value of &lt;b&gt;10 &lt;/b&gt;is lost. The next time the &lt;b&gt;testThis()&lt;/b&gt; sub executes,&amp;nbsp;&lt;b&gt;intExample&lt;/b&gt;&#39;s value will need to be set anew. As such ordinary local variables are limited to the length of time the sub procedure or function is executing. This is an example what is meant by a variables&amp;nbsp;&lt;i&gt;lifetime&lt;/i&gt;.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: justify;&quot;&gt;Static Variables&lt;/h4&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Now let&#39;s take a look at how the &lt;i&gt;scope &lt;/i&gt;and &lt;i&gt;lifetime &lt;/i&gt;of a static variable works in contrast to an ordinary local variable.&amp;nbsp;&amp;nbsp;Consider the following code snippet:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Private Sub testThis()&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; Static intExampleStatic As Integer&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; Dim intExampleLocal As Integer&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; intExampleStatic = intExampleStatic + 1&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; intExampleLocal = intExampleLocal + 1&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;response = MsgBox(&quot;The value of intExampleStatic is &quot; &amp;amp; intExampleStatic &amp;amp; _&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;, whereas the value of intExampleLocal is &quot; &amp;amp; intExampleLocal &amp;amp; &quot;.&quot;, &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;vbInformation, &quot;Static &amp;amp; Local Variable Output&quot;)&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Here we have created another sub procedure called &lt;b&gt;testThis(&lt;/b&gt;), and declared a static variable and an ordinary local variable,&amp;nbsp;&lt;b&gt;intExampleStatic &lt;/b&gt;and &lt;b&gt;intExampleLocal&lt;/b&gt;&amp;nbsp;respectively.&amp;nbsp; Notice how the declaration statement for the static variable uses the &lt;b&gt;Static &lt;/b&gt;keyword rather than &lt;b&gt;Dim &lt;/b&gt;ie:&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Static intExampleStatic As Integer&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;in contrast to ...&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Dim intExampleLocal As Integer&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Since both variables are declared as Integer, they are automatically initialized with a value of &lt;b&gt;0&lt;/b&gt;.&amp;nbsp; Then in the following lines of code we increment the value of&amp;nbsp; each of the variables by &lt;b&gt;1:&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;intExampleStatic = intExampleStatic + 1&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;intExampleLocal = intExampleLocal + 1&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;... and display both values using a message box statement:&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;response = MsgBox(&quot;The value of intExampleStatic is &quot; &amp;amp; intExampleStatic &amp;amp; _&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;, whereas the value of intExampleLocal is &quot; &amp;amp; intExampleLocal &amp;amp; &quot;.&quot;, vbInformation, &quot;Static &amp;amp; Local Variable Output&quot;)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Now the &lt;i&gt;scope &lt;/i&gt;of both kinds of variable, local and static, work in exactly the same way.&amp;nbsp; That is to say, static variables, along with ordinary local variables, can only be accessed from within the same sub procedure or function from which they were declared.&amp;nbsp; Where they differ is in their respective &lt;i&gt;lifetimes&lt;/i&gt;.&amp;nbsp; Whereas a local variable ceases to exist after the code within the same sub or function completes execution, the value contained in a static variable will be retained - at least until the codes&#39;&amp;nbsp; underlying form or report is closed, or in the case of a global module, until the database itself is closed. To demonstrate this in action, lets see what happens when the &lt;b&gt;testThis()&lt;/b&gt; sub procedure starts being called.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;The first time &lt;b&gt;testThis()&lt;/b&gt; is called the message box output shows that the &lt;b&gt;intExampleStatic &lt;/b&gt;and &lt;b&gt;intExampleLocal &lt;/b&gt;variables have the same value ie 1:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj70_kq7NVl9mKRUXzg0JA6SrX8Utvw9GOAz46jIsZDpBqWBwhgoIf-9jIrAwfJnOTPQJj3WR1dx0W5PTH8_NpD-2OzpVpthvQM2Jy7yzgjef3exRGpkXsAem3A_n6PgF0wWIgSCXHZCsYPWsAo1UArmLOYb1t45vgB7gXvvC3XqLFwg5i_uwk7xNIfnLo/s384/output1.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Message Box Output&quot; border=&quot;0&quot; data-original-height=&quot;158&quot; data-original-width=&quot;384&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj70_kq7NVl9mKRUXzg0JA6SrX8Utvw9GOAz46jIsZDpBqWBwhgoIf-9jIrAwfJnOTPQJj3WR1dx0W5PTH8_NpD-2OzpVpthvQM2Jy7yzgjef3exRGpkXsAem3A_n6PgF0wWIgSCXHZCsYPWsAo1UArmLOYb1t45vgB7gXvvC3XqLFwg5i_uwk7xNIfnLo/s16000/output1.jpg&quot; title=&quot;Message box output from first call to testThis().&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;It is not until the second and subsequent calls that we see the difference in lifetime between static and local variables taking effect.&amp;nbsp; This is because the value stored in the local variable is lost each time the sub procedure completes, and then re-initialized the next time it is called.&amp;nbsp; The static variable, on the other hand, retains its value from the previous call.&amp;nbsp; Hence, the output after the second call shows the static variable to have a value of 2, but the local variable again has a value of 1:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmp6v9DrrPIL2taaNkb_uh6FVpVBkYMpKNN8WAlDzuX44ybmdkGGffjfkoKGRZpWTl7Z3jTos230V8C-eBI1JJV82eWa-tbHQQJNW1PyiyZa9EBEUVvgxTJzW2tRpuAYt3_qYS3HkE4l4BBOvR4VhWnvfOrdBbzXN1FKfiYPlM0hcfgCgTGIK99IzFlEg/s384/output2.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;154&quot; data-original-width=&quot;384&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmp6v9DrrPIL2taaNkb_uh6FVpVBkYMpKNN8WAlDzuX44ybmdkGGffjfkoKGRZpWTl7Z3jTos230V8C-eBI1JJV82eWa-tbHQQJNW1PyiyZa9EBEUVvgxTJzW2tRpuAYt3_qYS3HkE4l4BBOvR4VhWnvfOrdBbzXN1FKfiYPlM0hcfgCgTGIK99IzFlEg/s16000/output2.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;This pattern continues each time the sub procedure is called: the value of the static variable is retained and any increments are added to this retained value, whereas the local variable is created anew and any increments are applied to its initialization value of 0.&amp;nbsp; Hence the third time &lt;b&gt;testThis()&lt;/b&gt; is called, the value of the static variable is increased to 3, and the value of the local variable remains at 1:&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEEMR2vFVZ5s3rudJq7Qu8FWcFKIbdV_GV9kmHkqRtQbRANipxP30KKYneNKFEU0bvs8ixfYZivcDSjY4_I_mDQBJ8Zx9GKSz76cwVPgyxr1E-dVGjs2MYwFWTSb4JcV6wsIUEF2M8DLljRBxi4zXXdvYAB6uOA1Qmo7YfxfWWQRosnBlwPKISk84g1EI/s383/output3.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;154&quot; data-original-width=&quot;383&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEEMR2vFVZ5s3rudJq7Qu8FWcFKIbdV_GV9kmHkqRtQbRANipxP30KKYneNKFEU0bvs8ixfYZivcDSjY4_I_mDQBJ8Zx9GKSz76cwVPgyxr1E-dVGjs2MYwFWTSb4JcV6wsIUEF2M8DLljRBxi4zXXdvYAB6uOA1Qmo7YfxfWWQRosnBlwPKISk84g1EI/s16000/output3.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;... and so on until the sub procedures&#39;s underlying form or report is closed.&amp;nbsp; It is not until the next time the form or report is reopened that the static variable&#39;s value is re-initialized to 0.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;So this has shown us how static variables work and how they differ from ordinary local variables.&amp;nbsp; In the next blog post we are going to consider the advantages of using static variables over local variables, and will demonstrate this by creating a a simple order counter control where a user clicks two buttons to increment or decrement the quantity of an item to be ordered without having to type the actual number.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/420646493652718317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2024/03/using-vba-static-variables.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/420646493652718317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/420646493652718317'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2024/03/using-vba-static-variables.html' title='Using VBA Static Variables '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj70_kq7NVl9mKRUXzg0JA6SrX8Utvw9GOAz46jIsZDpBqWBwhgoIf-9jIrAwfJnOTPQJj3WR1dx0W5PTH8_NpD-2OzpVpthvQM2Jy7yzgjef3exRGpkXsAem3A_n6PgF0wWIgSCXHZCsYPWsAo1UArmLOYb1t45vgB7gXvvC3XqLFwg5i_uwk7xNIfnLo/s72-c/output1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2154985831953002669</id><published>2024-02-21T03:00:00.000-08:00</published><updated>2024-02-21T03:00:04.297-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DAO"/><category scheme="http://www.blogger.com/atom/ns#" term="filters"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Display a Random Customer Record using VBA and Form Filter</title><content type='html'>&lt;p style=&quot;text-align: justify;&quot;&gt;Suppose you are responsible for managing an Access Database containing customer records.&amp;nbsp; You have been asked to introduce a contact management feature whereby the person operating the database can extract a random customer record.&amp;nbsp; This blog post walks you through the VBA code needed to generate a random number and use it to filter out a customer record, all at the click of a form button.&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;In order to demonstrate this we will be using the following data:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTU6DFWlJl7vwAwuS8rt892KuN-A3PrkMbmEaIV7912qAskSAvZYnjcI0JSCx3S7mV62fiTYfBEkWHnlVvM9sIr0ANw4S7BpLC-Mz5vIWQgJ9J1urXABke6vdxF0ZeWPc-JKy1xcVE_SFFgUNSpVY3Xry8ICUK4Jrl6UeAkR-xf9NpRGH6QSfadxs-fH8/s750/data.jpg&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;221&quot; data-original-width=&quot;750&quot; height=&quot;189&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTU6DFWlJl7vwAwuS8rt892KuN-A3PrkMbmEaIV7912qAskSAvZYnjcI0JSCx3S7mV62fiTYfBEkWHnlVvM9sIr0ANw4S7BpLC-Mz5vIWQgJ9J1urXABke6vdxF0ZeWPc-JKy1xcVE_SFFgUNSpVY3Xry8ICUK4Jrl6UeAkR-xf9NpRGH6QSfadxs-fH8/w640-h189/data.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;text-align: left;&quot;&gt;Table of Fictitious Customer Records&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We will display the random customer record on the following form:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8RcSdbUhaL-wyEw52UYp7rVlmChHV0DTNAhJzA2GP9B8xQIxT9vnVNHkRXKfNPOf-nicmVB-M1q2bKLf1vNe5ZcZx7Ma3av1Sz-lD4pzbIEDxhq26KX9wM2RYnGkfkBsFavbiFPcy5MS2U7wOAnmLgqnCqe2IKOwe031NYr7Wki08LD8uRhR5dcAeTQY/s753/form.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;546&quot; data-original-width=&quot;753&quot; height=&quot;464&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8RcSdbUhaL-wyEw52UYp7rVlmChHV0DTNAhJzA2GP9B8xQIxT9vnVNHkRXKfNPOf-nicmVB-M1q2bKLf1vNe5ZcZx7Ma3av1Sz-lD4pzbIEDxhq26KX9wM2RYnGkfkBsFavbiFPcy5MS2U7wOAnmLgqnCqe2IKOwe031NYr7Wki08LD8uRhR5dcAeTQY/w640-h464/form.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;The VBA code starts when the user clicks the &quot;Get Random&quot; button to display a random customer record on the form. Lets begin by creating the control button.&lt;/p&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Creating the Control Button&lt;/h4&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Open the form in DESIGN VIEW&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Click the BUTTON icon in the CONTROLS group on the FORM DESIGN ribbon.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Click the location on the form grid where we will be positioning the button.&amp;nbsp; Resize the control button by clicking on one of the buttons&#39; corner or edges and dragging to enlarge or contract as appropriate.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. Click the PROPERTY SHEET icon from the TOOLS group of the FORM DESIGN ribbon if it is not already open.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span&gt;5. Ensure the control button is selected. Click the button to select if it is not. Now the property &lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sheet is displaying the properties specific to our button.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;6. Change the button CAPTION property on the FORMAT tab to &quot;Get Random&quot;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;7. Change the button NAME property on the OTHER tab to &quot;btnRnd&quot;&lt;/div&gt;&lt;/blockquote&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Check how the button looks by changing&amp;nbsp; to FORM VIEW from the VIEWS group of the FORM DESIGN ribbon. If its OK, we are now ready to add the VBA code which runs when the command button is clicked.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Adding the VBA Code&lt;/h4&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Open the form in DESIGN VIEW, and reopen the PROPERTY SHEET if it isn&#39;t already.&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. Select the control button by clicking on it.&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;3. Select the EVENT TAB on the PROPERTY SHEET, and click inside the grid cell adjacent to where it says ON CLICK.&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4. Click the ellipse button (&quot;&lt;b&gt;...&lt;/b&gt;&quot;) at the end of the cell to open the CHOOSE BUILDER dialog, Select CODE BUILDER from the drop down list and click OK to open the VBA editor.&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/blockquote&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;You should now see an empty sub procedure called &lt;b&gt;btnRnd_Click()&lt;/b&gt;. This is the control button&#39;s event handler.&amp;nbsp; This means the code we enter here will run when the user clicks the command button at runtime.&lt;/p&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/blockquote&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;The VBA to Generate a Random Number&lt;/h4&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In order to retrieve a random customer record we need to generate a random number which corresponds to one of the customers in the database table. We can do this using an inbuilt VBA function called&amp;nbsp;&lt;b&gt;Rnd&lt;/b&gt;.&amp;nbsp; This generates a random decimal number between 0 and 1. For example, it&amp;nbsp; may return the value 0.5924582.&amp;nbsp; For this to be of any use to us, we need change the decimal number to an integer and multiply it by the number of customer records in the table.&amp;nbsp; So, for example, our table contains 10 customer records so we need to multiply the value returned by rnd by 10 and use another function called &lt;b&gt;int &lt;/b&gt;to convert it from decimal to integer. We do this as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Int(rnd * 10)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This returns a value between 0 and 9.&amp;nbsp; &amp;nbsp;We now need to add 1 to the value to get a number between 1 and 10:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;Int(rnd * 10)+&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;1&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Just one more thing to note: computers are unable to return a &lt;i&gt;true&amp;nbsp;&lt;/i&gt;random number on their own.&amp;nbsp; They return a seed number based on a pre-existing sequence of numbers. However, when we initialize the random number generator with the &lt;b&gt;Randomize &lt;/b&gt;statement, the seed number returned is based on the system timer, which effectively makes the returned value a &lt;i&gt;true &lt;/i&gt;random number.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So to put all this together we are going to create our own custom function to return a random integer number based on the number of records in our database table. The number returned will correspond to a particular record in the table. We shall call our function &lt;b&gt;getRandom&lt;/b&gt; and will pass the number of customer records as the parameter. The code for the function is as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Private Function getRandom(intRecordCount As Integer) As Integer&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; Randomize&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; getRandom = Int((intRecordCount * Rnd) + 1)&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;End Function&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;For more information on how custom functions work, please check out my post on&amp;nbsp;&lt;a href=&quot;https://ms-access-tips.blogspot.com/2012/05/writing-custom-functions-for-access-vba.html&quot; target=&quot;_blank&quot;&gt;Writing Custom Functions for Access VBA&lt;/a&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next step is to write the VBA code to connect the random number returned by our &lt;b&gt;getRandom &lt;/b&gt;function with it&#39;s corresponding customer record in the database table.&amp;nbsp; We shall do this by looping through a &lt;a href=&quot;https://ms-access-tips.blogspot.com/2012/03/accessing-data-with-vba-code.html&quot; target=&quot;_blank&quot;&gt;DAO Recordset&lt;/a&gt; containing records from the customer table.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Looping through the DAO Recordset&lt;/h4&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Before we can create the code to filter a customer record based on our random number, we need to find a way of mapping any potential number returned by the &lt;b&gt;getRandom &lt;/b&gt;function&amp;nbsp; (in our case this is between 1 and 10) against the records in the database table. Whilst it is tempting to use the returned random number directly against the value stored in the &lt;b&gt;customer_id&lt;/b&gt; field in a form filter WHERE clause - ie&amp;nbsp;&lt;span style=&quot;color: #0b5394;&quot;&gt;&quot;customer_id = &quot; &amp;amp; getRandom(intRecordCount)&lt;/span&gt; - there is a problem with this.&amp;nbsp; That is to say, although the customer id&#39;s in our table go up in &lt;i&gt;an unbroken sequence&lt;/i&gt; from 1 to 10, it is possible that one of these records will be deleted in the future.&amp;nbsp; If and when this happens, no customer record would be found using the above WHERE clause if the random number corresponded to the deleted record. Moreover, the record count would not include the deleted record so the random number returned would be within a range which did NOT include the last record in the table.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;What we must do, therefore, is create a DAO Recordset containing all the records in our customer table and use the value returned by&amp;nbsp;&lt;b&gt;getRandom&lt;/b&gt;&amp;nbsp;to step through each customer record in the set until this value has been reached - eg if &lt;b&gt;getRandom &lt;/b&gt;returns the value 8, we simply loop though the recordset to the 8th record contained therein.&amp;nbsp; Once we get to this record we can look up the &lt;i&gt;actual &lt;/i&gt;value in the customer_id field, and then use this as the basis of our form filter WHERE clause.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you are unfamiliar with how DAO recordsets work, you may want to check out my post on&amp;nbsp;&lt;a href=&quot;https://ms-access-tips.blogspot.com/2012/03/accessing-data-with-vba-code.html&quot; target=&quot;_blank&quot;&gt;Accessing Data with VBA Code - Introducing the DAO Recordset&lt;/a&gt;; otherwise, lets jump straight in, and run through the code we will be using.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first step is to create a new instance of a DAO recordset object and set its value to that of our&amp;nbsp; &lt;b&gt;tblCustomer&lt;/b&gt;&amp;nbsp;table.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Dim rstCustomers As DAO.Recordset&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Set rstCustomers = Application.CurrentDb.OpenRecordset(&quot;tblCustomer&quot;, dbOpenSnapshot)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You may have noticed the second parameter we have used when opening the recordset is &lt;b&gt;dbOpenSnapshot&lt;/b&gt;.&amp;nbsp; This means our recordset will be a static&amp;nbsp;&lt;i&gt;snapshot &lt;/i&gt;of the customer table. Unlike the versatile&amp;nbsp;&lt;b&gt;dbOpenDynaset &lt;/b&gt;type, records cannot be updated using &lt;b&gt;dbOpenSnapshot&lt;/b&gt;, but in cases where editing is not required, the snapshot type is the more efficient option.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the next step we are going to count the number of records in the &lt;b&gt;rstCustomers &lt;/b&gt;recordset and store the value in an integer variable called &lt;b&gt;intCount&lt;/b&gt;.&amp;nbsp; To count the number of records in &lt;b&gt;rstCustomers &lt;/b&gt;we will read&amp;nbsp;the&amp;nbsp;&lt;b&gt;RecordCount&lt;/b&gt; property using the following syntax:&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;rstCustomer.RecordCount&lt;/span&gt;.&amp;nbsp; However, before doing so, it is first necessary to visit all the records in the recordset so they can all be counted. The best way to do this is to use the recordset &lt;b&gt;MoveLast &lt;/b&gt;method&lt;b&gt;&amp;nbsp;&lt;/b&gt;which moves the recordset cursor though each of the records before pointing to the last record in the set. The syntax for this is&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;rstCustomers.MoveLast.&amp;nbsp;&lt;/span&gt;All this is done in three lines of code as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Dim intCount As Integer&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;rstCustomers.MoveLast&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;intCount = rstCustomers.RecordCount&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now that we know how many records are in the customer table, we can use our &lt;b&gt;getRandom &lt;/b&gt;function, passing &lt;b&gt;intCount &lt;/b&gt;as the parameter, to obtain a random number.&amp;nbsp; We then step through the records in the recordset until we reach this number.&amp;nbsp; Once this record has been reached, we can read the value contained in the&amp;nbsp;&lt;b&gt;customer_id &lt;/b&gt;field.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To do all this we shall begin by defining an integer variable called &lt;b&gt;intCustomerId&lt;/b&gt;.&amp;nbsp; This will be used to store the customer id once we have arrived at the random customer record.&amp;nbsp; Before we set up the loop, we need to move the recordset cursor back to the first record using the &lt;b&gt;MoveFirst&amp;nbsp; &lt;/b&gt;method.&amp;nbsp; This is because the cursor is still at the last record from when did the record count in the section of code above.&amp;nbsp; We will use a &lt;a href=&quot;https://ms-access-tips.blogspot.com/2011/11/introduction-to-vba-loops-learning.html&quot; target=&quot;_blank&quot;&gt;For...Next loop&lt;/a&gt; to step through the recordset, starting at the first record and ending at the record which corresponds to the value returned by our&amp;nbsp;&lt;b&gt;getRandom &lt;/b&gt;function. This is done with the following line of code:&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;For i = 1 To getRandom(intCount)&lt;/span&gt;.&amp;nbsp; The first statement within the loop sets the value of the&amp;nbsp;&lt;b&gt;intCustomerId &lt;/b&gt;variable to the value contained in the &lt;b&gt;customer_id&lt;/b&gt; field of the record where the recordset cursor is located. We reference the field value using the recordset name (&quot;&lt;b&gt;rstCustomers&lt;/b&gt;&quot;) followed by an exclamation mark (&quot;&lt;b&gt;!&lt;/b&gt;&quot;) and then the field name (&quot;&lt;b&gt;Customer_Id&lt;/b&gt;&quot;) as follows:&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;intCustomerId = rstCustomers!Customer_Id&lt;/span&gt;. Once this value is stored in our &lt;b&gt;intCustomer&lt;/b&gt;&amp;nbsp;variable we can move the recordset cursor to the next record using the &lt;b&gt;MoveNext&lt;/b&gt; method:&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;rstCustomers.MoveNext&lt;/span&gt;. Finally the loop counter is incremented by 1 with&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Next i&lt;/span&gt;.&amp;nbsp; If the end value of the loop counter had been reached before the &lt;b&gt;Next &lt;/b&gt;statement had executed, the loop counter will still increment by 1, but the program flow will exit the loop and move to the statement following &lt;b&gt;Next i&lt;/b&gt;.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Dim intCustomerId As Integer&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;rstCustomers.MoveFirst&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;For i = 1 To getRandom(intCount)&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;intCustomerId = rstCustomers!Customer_Id&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;rstCustomers.MoveNext&lt;/span&gt;&lt;br /&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;Next i&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So we have stepped through the recordset and arrived at our random record storing the value of it&#39;s &lt;b&gt;customer_id &lt;/b&gt;field in the &lt;b&gt;intCustomerId &lt;/b&gt;variable.&amp;nbsp; Now the program flow has exited the loop we are going to use the&amp;nbsp;&lt;b&gt;intCustomerId &lt;/b&gt;value to display the record on our form.&amp;nbsp; This will be done by means of a form filter containing a WHERE clause based on the stored&amp;nbsp;&lt;b&gt;customer_id. &lt;/b&gt;The syntax for the WHERE clause is&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&quot;Customer_id = &quot; &amp;amp; intCustomerId &lt;/span&gt;and the syntax to create form filter is&amp;nbsp;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;DoCmd.ApplyFilter filtername, whereclause, controlname.&amp;nbsp;&amp;nbsp;&lt;/span&gt;Although the &lt;b&gt;ApplyFilter &lt;/b&gt;method has three parameters, we are just going to use the second - the WHERE clause.&amp;nbsp; As such we write the full statement as follows:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;DoCmd.ApplyFilter , &quot;Customer_id = &quot; &amp;amp; intCustomerId&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;(NB Although the first parameter is left blank we still need the separating coma just before the WHERE clause string.&amp;nbsp; The last parameter is also left blank, but a separating coma after the WHERE clause is not needed.)&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;Lastly we need to close the &lt;b&gt;rstCustomer &lt;/b&gt;recordset and set its value to NOTHING.&amp;nbsp; This clears the memory that it had been taking up and allows us to reopen the recordset again the next time the user clicks the getRandom button. We place this code within a IF conditional statement which checks the recordset is still open before it executes thereby avoiding any error from occurring if it is not.&lt;/p&gt;&lt;blockquote style=&quot;border: none; margin: 0px 0px 0px 40px; padding: 0px; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;If Not rstCustomers Is Nothing Then&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;rstCustomers.Close: Set rstCustomers = Nothing&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;End If&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #0b5394; font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;All we need to do now is look at how all the code we have run through above is organised in the&amp;nbsp;code module for the frmCustomer form.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB7n4zRCH-MZHQcPE87zwvKeecylhA9eWBqlrLiMrTk-NhsPmyZVhIBQi9hyphenhyphenK_YIy_KBA6Bd4Ly8b1vNgSDVBQQFaH3ZGLVgya09z8SmFWSLOyeJjGGi35sUNcFth65YW02Fth9cw6tQ5FprnrLuKT3tcPLRia5E4suX2rNc5a-vQV2VnBGb8uVpx2J5Y/s747/code.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;655&quot; data-original-width=&quot;747&quot; height=&quot;562&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB7n4zRCH-MZHQcPE87zwvKeecylhA9eWBqlrLiMrTk-NhsPmyZVhIBQi9hyphenhyphenK_YIy_KBA6Bd4Ly8b1vNgSDVBQQFaH3ZGLVgya09z8SmFWSLOyeJjGGi35sUNcFth65YW02Fth9cw6tQ5FprnrLuKT3tcPLRia5E4suX2rNc5a-vQV2VnBGb8uVpx2J5Y/w640-h562/code.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As you can see from the screenshot above, our code is divided into two Sub Procedures and one Function, &lt;b&gt;btnRnd_Click()&lt;/b&gt;, &lt;b&gt;RandomCustomerRecord()&lt;/b&gt; and &lt;b&gt;getRandom() &lt;/b&gt;respectively.&amp;nbsp; When the user clicks the Get Random button on the Customer Form, the code in the&amp;nbsp;&lt;b&gt;btnRnd_Click()&amp;nbsp;&lt;/b&gt;sub executes first. This is the event handling sub that Access created automatically when we set up the control button at the start of the tutorial.&amp;nbsp; There is just one statement here calling the second sub procedure which is &lt;b&gt;RandomCustomerRecord()&lt;/b&gt;.&amp;nbsp; This contains the main body of the code for retrieving the random customer record from the database and displaying it on the form.&amp;nbsp; The reason for giving this it&#39;s own sub rather than placing it in the code handler, is that we can potentially reuse this code by calling it from different locations in the program as required.&amp;nbsp; The only task this code does not do is generate the random number representing a specific customer record for selection.&amp;nbsp; This code is located in the &lt;b&gt;getRandom()&lt;/b&gt; Function which is called from the &lt;b&gt;FOR &lt;/b&gt;statement of the &lt;b&gt;FOR...NEXT&lt;/b&gt; loop. The number returned from the function determines how many records are stepped through in the &lt;b&gt;rstCustomers&lt;/b&gt; recordset before getting to the record which is to be displayed right at the end of the process.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once &lt;b&gt;RandomCustomerRecord()&lt;/b&gt; has the random number and retrieved the customer record from the recordset, the form filter is applied using the value of cutomer id.&amp;nbsp; The form will then display the record with the same&amp;nbsp;&lt;b&gt;customer_id&amp;nbsp;&lt;/b&gt;as that&lt;b&gt;&amp;nbsp;&lt;/b&gt;stored in the sub&#39;s&amp;nbsp;&lt;b&gt;intCustomerId&amp;nbsp;&lt;/b&gt;variable.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibBn5AZ23SNZCbin8nZQg__k6A7HEYpWa62Ga0K8RmtnmtBABL1VNoQ6P_q0heBGng7J5vqt2o6bXdA34g_qb_Off2mA9OrP1JYwxqO_tlRMJ2RYaKEYQacVF9bAFNc_np_lUHfIoS09Q4lX_nFk91bdZ6KEdsMQBZ0CkfV2V1IN_AdoJXDFbARxM4KnQ/s748/filtered-form.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;546&quot; data-original-width=&quot;748&quot; height=&quot;468&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibBn5AZ23SNZCbin8nZQg__k6A7HEYpWa62Ga0K8RmtnmtBABL1VNoQ6P_q0heBGng7J5vqt2o6bXdA34g_qb_Off2mA9OrP1JYwxqO_tlRMJ2RYaKEYQacVF9bAFNc_np_lUHfIoS09Q4lX_nFk91bdZ6KEdsMQBZ0CkfV2V1IN_AdoJXDFbARxM4KnQ/w640-h468/filtered-form.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;And there we have it: a random customer record at the click of a button!&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/2154985831953002669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2024/02/display-random-customer-record-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2154985831953002669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2154985831953002669'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2024/02/display-random-customer-record-using.html' title='Display a Random Customer Record using VBA and Form Filter'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTU6DFWlJl7vwAwuS8rt892KuN-A3PrkMbmEaIV7912qAskSAvZYnjcI0JSCx3S7mV62fiTYfBEkWHnlVvM9sIr0ANw4S7BpLC-Mz5vIWQgJ9J1urXABke6vdxF0ZeWPc-JKy1xcVE_SFFgUNSpVY3Xry8ICUK4Jrl6UeAkR-xf9NpRGH6QSfadxs-fH8/s72-w640-h189-c/data.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-6230687830629009481</id><published>2021-06-23T02:58:00.892-07:00</published><updated>2021-07-03T03:15:21.750-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Controls"/><category scheme="http://www.blogger.com/atom/ns#" term="events"/><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Option Button"/><category scheme="http://www.blogger.com/atom/ns#" term="Option Group"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Programming Access Option Groups with VBA</title><content type='html'>&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;In my previous post on &lt;a href=&quot;https://ms-access-tips.blogspot.com/2021/06/how-to-use-option-buttons.html&quot; target=&quot;_blank&quot;&gt;How to Use Option Buttons&lt;/a&gt;, we learnt how to set up an &lt;b&gt;Option Button Group&lt;/b&gt; bound to a field in the form&#39;s underlying database table.&amp;nbsp; We learnt that an Option Button Group is comprised of two separate types of control - the &lt;b&gt;Option Group&lt;/b&gt; control itself, and the individual &lt;b&gt;Option Buttons&lt;/b&gt;&amp;nbsp;within it. Once set up, these function together as a single unit.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Today we are going to learn how to set up a similar Option Button Group, but this time, we are going to use VBA to determine which button has been selected, and change the behaviour of the form based upon the selection.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFUamNZWue9WlFgJ9pw1SOGl5TWj2zoKn8uqmE_LIYxT3AuGHuPRXD-ILAv5NRJT5NaUOfjuhyFManjCxLgtAzPD18JbEt6GIfkJvfhZKnazMYc9RVgRMoGwxq3v5Ujf-m-Dbnj1VU-18/s307/screen-colour-option-group.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;212&quot; data-original-width=&quot;307&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFUamNZWue9WlFgJ9pw1SOGl5TWj2zoKn8uqmE_LIYxT3AuGHuPRXD-ILAv5NRJT5NaUOfjuhyFManjCxLgtAzPD18JbEt6GIfkJvfhZKnazMYc9RVgRMoGwxq3v5Ujf-m-Dbnj1VU-18/s0/screen-colour-option-group.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-small;&quot;&gt;Screen Colour Option Group&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;font-family: verdana;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;To do this we are going to set up an Option Group containing three Option Buttons (see screenshot above).&amp;nbsp; When the user clicks one of the buttons in the Option Group,&amp;nbsp; VBA subprocedures are called, and the background colour of the form changes in accordance with the users&#39; selection. Here is a video of how it works in practice.&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;599&#39; height=&#39;469&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dxw2YAcMnmYm1FP9_us5q3pZPsjp4U5cDmWiW68bHgNbBbLuVBQdXPu7VTD7DYHIb5O9l9dWOYp8t9AV7MUSg&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;The process for setting up the form with the Option Group is very similar to that which we went through in my last blog post on&amp;nbsp;&lt;a href=&quot;https://ms-access-tips.blogspot.com/2021/06/how-to-use-option-buttons.html&quot; target=&quot;_blank&quot;&gt;How to Use Option Buttons&lt;/a&gt;.&amp;nbsp; The main difference is that previously we bound the data selected in the Option Group to a field in the form&#39;s underlying database table.&amp;nbsp; This time, however, we are going to leave the Option Group unbound, and reference the data selected in the Option Group with VBA code.&amp;nbsp; To do this we will need to make use of the Option Groups &lt;b&gt;On Click &lt;/b&gt;event to trigger the subprocedure containing that code when the user clicks any button in the Option Group.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Setting up the Form and Option Group&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Here is the procedure for setting up the Option Group:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;1) Create a new form by clicking the FORM DESIGN icon on the CREATE ribbon.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;2) Go to the CONTROLS section of the DESIGN ribbon and drag an OPTION GROUP control down onto the design grid.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;3) Open the PROPERTY SHEET while the OPTION GROUP CONTROL is highlighted and enter the name &quot;opGrp&quot; in the NAME property (under the OTHER tab)&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;4) Next go back to the CONTROLS section and drag an OPTION BUTTON control onto the OPTION GROUP which we placed on the grid in the previous step.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;5) Enter the name &quot;optRed&quot; in OPTION BUTTON&#39;s NAME property whilst the control is highlighted.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;6) Repeat steps 4 and 5 twice, creating two more&amp;nbsp; OPTION BUTTONS called &quot;optGreen&quot; and &quot;optBlue&quot; respectively.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfnBSOg81qbUSL_xdWPPXHWXHdPZY9n9KKa4bvclTHDak2zY-dxX-o8B3b5djFr1HKHBq9U8yD-gonVbxLEXy1ZKwH1XShv28BnQx_mUcWP-BeAU2s7pHR2_hEyn_WgVO47UmlVJnWYRQ/s517/screen-colour-design-view.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;304&quot; data-original-width=&quot;517&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfnBSOg81qbUSL_xdWPPXHWXHdPZY9n9KKa4bvclTHDak2zY-dxX-o8B3b5djFr1HKHBq9U8yD-gonVbxLEXy1ZKwH1XShv28BnQx_mUcWP-BeAU2s7pHR2_hEyn_WgVO47UmlVJnWYRQ/s16000/screen-colour-design-view.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-small;&quot;&gt;Design View of our &lt;i&gt;Option Group&lt;/i&gt; containing the three &lt;i&gt;Option Buttons&lt;/i&gt; - optRed, optGreen and optBlue&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;The next step in the process is to check the &lt;b&gt;OPTION VALUE&lt;/b&gt;&amp;nbsp;property is set up correctly for each of the buttons.&amp;nbsp; To do this you will need to select each Option Button in turn, and go to the property sheet&amp;nbsp;&lt;b&gt;DATA &lt;/b&gt;tab. The values are set automatically when you drag the Option Button controls into the Option Group, but just to be sure, check the value for optRed is &quot;1&quot;, optGreen is &quot;2&quot; and optBlue is &quot;3&quot;.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhByI_M2Bb0t7Dse2dSPevemV2cVdkjQSCHi4IHLhINXgPc5sqvTLgfM3PcthMMuoJdaSkjQS7cWgd17Kjw8lmMfMz6464BmtB6NEeBYVMLjSaJZDacKxJjI8O2E1Ls4hl-yH6-Qv2n3IU/s294/option-value-property.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;229&quot; data-original-width=&quot;294&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhByI_M2Bb0t7Dse2dSPevemV2cVdkjQSCHi4IHLhINXgPc5sqvTLgfM3PcthMMuoJdaSkjQS7cWgd17Kjw8lmMfMz6464BmtB6NEeBYVMLjSaJZDacKxJjI8O2E1Ls4hl-yH6-Qv2n3IU/s0/option-value-property.jpg&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-small;&quot;&gt;The &lt;i&gt;Option Value &lt;/i&gt;property for optRed.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;As you may recall from my last blog post, the &lt;i&gt;Option Button &lt;/i&gt;selected by the user at runtime determines the &lt;b&gt;Value &lt;/b&gt;of the &lt;b&gt;Option Button Group &lt;/b&gt;as a whole. As such, if the user selects optGreen, the value of the group is &quot;2&quot; etc.&amp;nbsp; It is this value that our VBA code needs to reference when the subprocedure runs.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: medium;&quot;&gt;&lt;b&gt;Programming the Option Group&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Let us now turn our attention to the VBA code which executes when the user clicks one of the Option Buttons at runtime. In order for our code to detect when any button within the Option Button Group is selected, we need to make use of the Option Group&#39;s &lt;b&gt;ON CLICK &lt;/b&gt;event.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;This is done as follows:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;1) Select the Option Group Control (which we have called &quot;&lt;i&gt;&lt;b&gt;optGrp&lt;/b&gt;&lt;/i&gt;&quot;) on the design grid so it is highlighted orange.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;2) Go to the &lt;b&gt;PROPERTY SHEET&lt;/b&gt; and select the &lt;b&gt;EVENTS &lt;/b&gt;tab.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;3) Click the ellipse button (&quot;&lt;i&gt;&lt;b&gt;...&lt;/b&gt;&lt;/i&gt;&quot;) at the end of the &lt;b&gt;ON CLICK&lt;/b&gt; property row to open the VBA editor.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH8abE2TRTmhKEcfNvp_ZT3UO2kKPh2XS6KDDE8D7aL0JCs7zI1pcnnd5m5nVR_P5miQ43LLmsKWpf-KDqYFeSPty0n-FZm1Dzop__zP0TfZuADCdVIHXXiAwP2XWZy3JvFD7cQFj91Ds/s518/on-click-property.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;340&quot; data-original-width=&quot;518&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH8abE2TRTmhKEcfNvp_ZT3UO2kKPh2XS6KDDE8D7aL0JCs7zI1pcnnd5m5nVR_P5miQ43LLmsKWpf-KDqYFeSPty0n-FZm1Dzop__zP0TfZuADCdVIHXXiAwP2XWZy3JvFD7cQFj91Ds/s16000/on-click-property.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: verdana; font-size: x-small;&quot;&gt;Selecting the ON CLICK event for the &quot;optGrp&quot; OPTION GROUP.&amp;nbsp; Clicking the&amp;nbsp;&lt;br /&gt;ellipse button (&quot;...&quot;) opens the VBA editor.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;After clicking the ellipse button on the ON CLICK row of the PROPERTY SHEET, the VBA editor will have opened and automatically created a sub procedure called &quot;&lt;b&gt;optGrp_Click&lt;/b&gt;&quot;.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;This is the ON CLICK&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: verdana;&quot;&gt;event-handler&lt;/i&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Any code we enter here will be executed when the user clicks any button in the option group at runtime.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Our first programming task is to determine which Option Button the user clicked.&amp;nbsp; This is done by referencing the Option Groups VALUE property as follows:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #073763; font-family: verdana;&quot;&gt;formname!optiongroupname.Value&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;In our case the code will be:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #073763; font-family: verdana;&quot;&gt;Me!opGrp.Value&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&quot;&lt;b&gt;Me&lt;/b&gt;&quot; is a quick and simple way to reference the form name within which the code module is contained;&amp;nbsp; &quot;&lt;b&gt;opGrp&lt;/b&gt;&quot; is the name of our Option Group; and &lt;b&gt;Value &lt;/b&gt;is a reference to the value property of the Option Group as a whole.&amp;nbsp; Note the &lt;i&gt;form name&lt;/i&gt; and &lt;i&gt;control name&lt;/i&gt; is separated by the &quot;&lt;b&gt;!&lt;/b&gt;&quot; character, and the &lt;i&gt;control name&lt;/i&gt; and &lt;i&gt;property &lt;/i&gt;is separated by a full stop &quot;&lt;b&gt;.&lt;/b&gt;&quot;.&amp;nbsp;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Referencing the OPTION GROUPS&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;VALUE &lt;/b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;property in this way gives us the &lt;/span&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;OPTION VALUE&lt;/b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt; of the button selected by the user.&amp;nbsp; As you may recall the &lt;/span&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;OPTION VALUE &lt;/b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;for the red button was &quot;1&quot;, green was &quot;2&quot; and blue was &quot;3&quot;.&amp;nbsp; So if the user clicked the green button, the above statement will return &quot;2&quot; when it executes at runtime.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;In order to use the OPTION GROUPS &lt;b&gt;VALUE &lt;/b&gt;property to change the background colour of the form, we are going to do two things.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Firstly we are going to call a separate VBA sub procedure from the OPTION GROUPS &lt;/span&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;ON CLICK &lt;/b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;i&gt;event-handler&lt;/i&gt;, &lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;passing the &lt;/span&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;VALUE &lt;/b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;property as the parameter; secondly, we are going to create this subprocedure which will process the VALUE property and then change the background colour of the form.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;The event-handler code is as follows:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Private Sub opGrp_Click()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;Call setBackgroundColour(Me!opGrp.Value)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As we learnt above, the first and last line of this event handler is created automatically when we clicked the ellipse button (&quot;&lt;b&gt;...&lt;/b&gt;&quot;) in the &lt;b&gt;ON CLICK &lt;/b&gt;row of the Option Groups property sheet.&amp;nbsp; All we have done is add the middle line to call a sub procedure called &lt;b&gt;setBackgroundColour&amp;nbsp;&lt;/b&gt;(yet to be created), and pass the referenced value of the Option Group as the parameter.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let us take a look at the code for our&amp;nbsp;&lt;b&gt;setBackgroundColour &lt;/b&gt;sub procedure:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Private Sub setBackgroundColour(intOpValue)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; Dim lngRed As Long, lngGreen As Long, lngBlue As Long&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; lngRed = RGB(255, 230, 230)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; lngGreen = RGB(242, 255, 230)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; lngBlue = RGB(230, 240, 255)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; Select Case intOpValue&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Case 1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.Detail.BackColor = lngRed&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Case 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.Detail.BackColor = lngGreen&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Case 3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.Detail.BackColor = lngBlue&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; End Select&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;End Sub&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Here is a breakdown of how the code works:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;1) The first line of the sub procedure receives the &lt;b&gt;option value&lt;/b&gt; argument (&lt;b&gt;intOpValue&lt;/b&gt;) which was passed to it from the calling statement we wrote in the ON CLICK event handler.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;2)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;The next section sets up three variables of the LONG data type and assigns each one a colour value which is used to set the forms BackColor property to red, green or blue as required.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;3) Next we have set up a SELECT CASE statement to determine the value of the &lt;b&gt;intOpValue&lt;/b&gt; variable which, as we have learnt above, contains the OPTION VALUE of the OPTION BUTTON clicked by the user at runtime.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;4) Then each respective CASE statement tests whether it&#39;s value matches intOpValue.&amp;nbsp; When it comes to one that does, the BackColor property of form is set accordingly. So if the value of intOpValue is &quot;2&quot;, the second Case statement invokes ...&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #073763;&quot;&gt;&lt;b&gt;Me.Detail.BackColor = lngGreen&lt;/b&gt;&lt;/span&gt;&amp;nbsp;... to set the form&#39;s background colour to green.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;There is just one more thing we need to do before we can see our form and code in action. This involves calling the &lt;b&gt;setBackgroundColour &lt;/b&gt;sub procedure as soon as the form has opened.&amp;nbsp; This is so the form&#39;s background colour is set in accordance with the &lt;i&gt;default &lt;/i&gt;option button selection in the first instance.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;To do this we are going to make use of the forms &lt;/span&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;ON CURRENT &lt;/b&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;event which fires just after the form opens.&amp;nbsp; The procedure is similar to how we set up the ON CLICK event-handler for the Option Group.&amp;nbsp; This time we need to select the form in the design grid by clicking the square at the top right and then open the property sheet for the FORM.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAUHV2bcTOQTw_TTS4i7MdnsvMDBJaSFshs_GnViMLc1UU4i0wdeUql6ld7RwaNHcfh4KXhr0szOCgLpQwtqvahxgpc1yfmB4EM31Xz8V5nOmslrGNkFh0UWz2i-2eq9rlcS7ENwfMY4w/s247/form-selection.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;169&quot; data-original-width=&quot;247&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAUHV2bcTOQTw_TTS4i7MdnsvMDBJaSFshs_GnViMLc1UU4i0wdeUql6ld7RwaNHcfh4KXhr0szOCgLpQwtqvahxgpc1yfmB4EM31Xz8V5nOmslrGNkFh0UWz2i-2eq9rlcS7ENwfMY4w/s0/form-selection.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Selecting the FORM in design view.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Then we need to open the &lt;b&gt;EVENT &lt;/b&gt;tab (of the FORMS property sheet) and click the ellipse (&quot;&lt;b&gt;...&lt;/b&gt;&quot;) button at the end of the &lt;b&gt;ON CURRENT &lt;/b&gt;row.&amp;nbsp; This creates the event-handler in the VBA editor.&amp;nbsp; Once that has been created we just need to enter the same code as previously to call the &lt;b&gt;setBackgroundColour &lt;/b&gt;sub procedure as follows:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;Private Sub Form_Current()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;Call setBackgroundColour(Me!opGrp.Value)&lt;/b&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #073763;&quot;&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That&#39;s it!&amp;nbsp; Our form with the programmed option group is now ready to open and use.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/6230687830629009481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2021/06/programming-access-option-groups.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6230687830629009481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6230687830629009481'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2021/06/programming-access-option-groups.html' title='Programming Access Option Groups with VBA'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFUamNZWue9WlFgJ9pw1SOGl5TWj2zoKn8uqmE_LIYxT3AuGHuPRXD-ILAv5NRJT5NaUOfjuhyFManjCxLgtAzPD18JbEt6GIfkJvfhZKnazMYc9RVgRMoGwxq3v5Ujf-m-Dbnj1VU-18/s72-c/screen-colour-option-group.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-277959715368250136</id><published>2021-06-05T06:23:00.006-07:00</published><updated>2021-07-03T05:56:26.746-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Controls"/><category scheme="http://www.blogger.com/atom/ns#" term="design"/><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Option Button"/><category scheme="http://www.blogger.com/atom/ns#" term="Option Group"/><title type='text'>How to Use Option Buttons (aka Radio Buttons or Option Groups)</title><content type='html'>&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;span style=&quot;font-family: verdana;&quot;&gt;What are Option Buttons?&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;So what are &lt;i&gt;Option Buttons,&lt;/i&gt;&amp;nbsp;and what are they used for?&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Option Buttons are a user-friendly form control that enables users to select a single value from a group of given options.&amp;nbsp; This is done by clicking one of a number of boxes, with each box representing one of the available options.&amp;nbsp; When the user clicks a box to select the value, any previously selected boxes are unselected as a result.&amp;nbsp; In this way, only one value can be selected at any one time.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg33Xs40Q5o3wD_2LArT3jA8l_um7mXi85k7PCfyWgFG2pzTCsdai4fBNrhkOkou9Chmk120oGZUutnbnM1SWPd6TuVxXdoqCEMpWt8dZpIEfNnA31NXV9_YMOV05E5OYIo06Uk-sgMzqw/s180/Option+Group.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;134&quot; data-original-width=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg33Xs40Q5o3wD_2LArT3jA8l_um7mXi85k7PCfyWgFG2pzTCsdai4fBNrhkOkou9Chmk120oGZUutnbnM1SWPd6TuVxXdoqCEMpWt8dZpIEfNnA31NXV9_YMOV05E5OYIo06Uk-sgMzqw/s0/Option+Group.jpg&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Example of an &lt;i&gt;&lt;b&gt;Option Button Group&lt;/b&gt;&lt;/i&gt;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;For example, in the screenshot above, there are three options for the user to select one out of a possible three teams - &lt;i&gt;team 1&lt;/i&gt;, &lt;i&gt;team 2&lt;/i&gt; and &lt;i&gt;team 3&lt;/i&gt;.&amp;nbsp; The advantage of using an option button group over a combo box with the same available list of values is that it is quick and simple for the user to enter data.&amp;nbsp; It is also preferable to a textbox in so far as it limits the value entered to one in the group of options.&amp;nbsp; On the downside, an option button group tends to take up more space of the form, particularly if there are many options to choose from.&amp;nbsp; If this is the case, a combo box with data entry restricted to items in the list, maybe a better choice.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;In the following exercise, we are going to re-create the Option Button Group from the above screenshot.&amp;nbsp; To begin with, let take a look at the underlying database table.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOtsbBy6AALf7JCYupdfyFE16Sv2OpHgCt7My6JHKM23o2ghxle8C-Z9q_0hrXjZArVIhBAVcN4zROMcyyrUJiFGfJTkkxL0hmUOq1yYO2pC7h1Cu6HTT05uIdF03eZYcd_0eMwg2Tq8o/s390/database+table.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;158&quot; data-original-width=&quot;390&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOtsbBy6AALf7JCYupdfyFE16Sv2OpHgCt7My6JHKM23o2ghxle8C-Z9q_0hrXjZArVIhBAVcN4zROMcyyrUJiFGfJTkkxL0hmUOq1yYO2pC7h1Cu6HTT05uIdF03eZYcd_0eMwg2Tq8o/s320/database+table.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;The underlying database table containing the &quot;&lt;b&gt;team&lt;/b&gt;&quot; field&amp;nbsp;&lt;br /&gt;for the Option Group&#39;s &lt;b&gt;Control Source&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;As we can see, the underlying table contains four fields - &lt;i&gt;ID&lt;/i&gt;, &lt;i&gt;firstName&lt;/i&gt;, &lt;i&gt;surname &lt;/i&gt;and &lt;i&gt;team&lt;/i&gt;.&amp;nbsp; It is the latter field,&amp;nbsp;&lt;i&gt;team&lt;/i&gt;,&lt;i&gt;&amp;nbsp;&lt;/i&gt;which is going to be the &lt;b&gt;Control Source &lt;/b&gt;for our Option Button Group. Before we start the exercise it is worth mentioning that the Option Button Group is actually comprised of two separate types of control: first, we have the &lt;b&gt;Option Group &lt;/b&gt;control, and then we have the individual&amp;nbsp;&lt;b&gt;Option Button &lt;/b&gt;controls which are contained within the Option Group.&amp;nbsp; So to re-create the Option Button Group in the exercise below, we will need to use 1 Option Group control, and 3 Option Buttons, four separate controls acting together as one.&amp;nbsp; It is the Option Group control that contains the &lt;b&gt;Control Source &lt;/b&gt;property for the group as a whole, whilst the Option Buttons each have their own individual &lt;b&gt;Option Value &lt;/b&gt;properties.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;How to Create an Option Button Group&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Open the form in DESIGN VIEW.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Select the &lt;b&gt;OPTION GROUP&lt;/b&gt; control from the&amp;nbsp; DESIGN RIBBON&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ6k-E2yVcFwH60aV8AwWUiEWnIpenEX2DtDQPpec3fLd8kLaPDrarsmIdPw34YVRz2uGx7nlk8N4QkPq65pDIycnu21OkZj21rwpHWia_32NNBwnMKBF599DVZlNEThzVoyYXn8H4lZA/s41/option+group+icon.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;35&quot; data-original-width=&quot;41&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ6k-E2yVcFwH60aV8AwWUiEWnIpenEX2DtDQPpec3fLd8kLaPDrarsmIdPw34YVRz2uGx7nlk8N4QkPq65pDIycnu21OkZj21rwpHWia_32NNBwnMKBF599DVZlNEThzVoyYXn8H4lZA/s16000/option+group+icon.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;and drag it down onto the form design grid.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Whilst the OPTION GROUP control is still selected in the design grid, open or go to the PROPERTIES window, select the DATA tab, and then select &lt;b&gt;team &lt;/b&gt;from the &lt;b&gt;CONTROL SOURCE &lt;/b&gt;drop-down list (NB this assumes you have already set the CONTROL SOURCE of the form itself to the underlying table).&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijkzt_s1LFdVju9IPYoKjUGb1lOl1LfxJsbiKymyph707zup2o9IDNC_wLfIO80RqeTPxnb_3bKv12l1jdrxsqqzrxmWii0FtxUDBBCJCObr4l2VCnxoy1ebBV0rJpQmehke4dnblGFA0/s702/option+group+with+property+sheet.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;482&quot; data-original-width=&quot;702&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijkzt_s1LFdVju9IPYoKjUGb1lOl1LfxJsbiKymyph707zup2o9IDNC_wLfIO80RqeTPxnb_3bKv12l1jdrxsqqzrxmWii0FtxUDBBCJCObr4l2VCnxoy1ebBV0rJpQmehke4dnblGFA0/s320/option+group+with+property+sheet.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Form design grid with the &lt;b&gt;option group&amp;nbsp;&lt;/b&gt;control&amp;nbsp;&lt;br /&gt;added (highlighted orange).&amp;nbsp; The property sheet is also visible &lt;br /&gt;for the control with &lt;i&gt;team &lt;/i&gt;entered as the &lt;b&gt;control source&lt;/b&gt;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Next, select the OPTION BUTTON control from the DESIGN RIBBON, and drag it down onto the OPTION GROUP which you added to the design grid in step 2.&amp;nbsp; You should notice the OPTION GROUP turn black once the OPTION BUTTON is over the control and ready to drop.&amp;nbsp; This indicates that the button will be added to the group.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Whilst the OPTION BUTTON is still selected, open and/or go to the PROPERTY WINDOW, select the DATA TAB, and check the OPTION VALUE property.&amp;nbsp; It should say &quot;1&quot;.&amp;nbsp; This is the value that will be bound to the &lt;i&gt;team &lt;/i&gt;field if the button is selected by the user at runtime.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Repeat steps 4 and 5 for the remaining two CONTROL BUTTONS checking the OPTION VALUE properties say &quot;2&quot; and &quot;3&quot; respectively.&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzWPoNAAZyEeMvZTbaM5NFe4pkB0NP0uEvw24GTMwW6hYYAO0HoacW6g_DtbmUO97T4J4awCV44XPF3gN0e8-F4GqDVDweUdQ-2bmaJcy9Swmnu6xUo3iMcyRr1BVkDZMecrnahCv80q8/s656/option+button+with+property+sheet.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;382&quot; data-original-width=&quot;656&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzWPoNAAZyEeMvZTbaM5NFe4pkB0NP0uEvw24GTMwW6hYYAO0HoacW6g_DtbmUO97T4J4awCV44XPF3gN0e8-F4GqDVDweUdQ-2bmaJcy9Swmnu6xUo3iMcyRr1BVkDZMecrnahCv80q8/s320/option+button+with+property+sheet.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Design grid showing three &lt;b&gt;option buttons &lt;/b&gt;added to the &lt;br /&gt;&lt;b&gt;option group &lt;/b&gt;control.&amp;nbsp; The property sheet for the third control button &lt;br /&gt;(showing the &lt;b&gt;option value &lt;/b&gt;property) is&amp;nbsp;also visible.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;The form should now be ready to open in FORM VIEW.&amp;nbsp; The screenshot below shows the finished form with the underlying table.&amp;nbsp; I have added some data to demonstrate how information contained in the &lt;b&gt;Option Button Group&lt;/b&gt; is stored in the database.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ3ZSsUCs-qB7dF96RWQoC8WEkL-8d6NZTHEHgae6TIF0u5I3ZLgYWZItnaBXh3dind55-G4exKYtbBsS43tM6B2Qb1gaGrFK_fmnI3-TA8Yixlkr2tgDns6tz0of94J9_afSHnAgjzVA/s958/form+with+option+button+group.jpg&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;494&quot; data-original-width=&quot;958&quot; height=&quot;330&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ3ZSsUCs-qB7dF96RWQoC8WEkL-8d6NZTHEHgae6TIF0u5I3ZLgYWZItnaBXh3dind55-G4exKYtbBsS43tM6B2Qb1gaGrFK_fmnI3-TA8Yixlkr2tgDns6tz0of94J9_afSHnAgjzVA/w640-h330/form+with+option+button+group.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Form with &lt;b&gt;option button group&lt;/b&gt;.&amp;nbsp; Select an option button on the form results in the &lt;b&gt;option value &lt;/b&gt;property being stored in the underlying database table.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;Note how &lt;i&gt;team 3&lt;/i&gt; is selected for the &lt;i&gt;Sarah Arden &lt;/i&gt;record (ID 7) in the &lt;b&gt;option button group&lt;/b&gt;.&amp;nbsp; As you may remember, the &lt;b&gt;option value&lt;/b&gt; property was set to &quot;3&quot; for the last button.&amp;nbsp; This is the value that has been stored in the underlying database table.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;This post has shown how we create an &lt;b&gt;option button group &lt;/b&gt;using a combination of an &lt;b&gt;option group &lt;/b&gt;control and three &lt;b&gt;option buttons&lt;/b&gt;.&amp;nbsp; I have demonstrated how the control source for the group as a whole is bound to a field in the forms underlying database table, and how each &lt;b&gt;option button &lt;/b&gt;has a unique &lt;b&gt;option value &lt;/b&gt;property which is the value stored if the user selects a given button at runtime.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;In a future post, I intend to show how option button groups can be used to control the behaviour of a form at runtime, rather than being bound to a field in an underlying database table.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;To do this I will demonstrate how we can &lt;a href=&quot;https://ms-access-tips.blogspot.com/2021/06/programming-access-option-groups.html&quot; target=&quot;_blank&quot;&gt;reference the option button group with VISUAL BASIC code, and respond to its click events&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/277959715368250136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2021/06/how-to-use-option-buttons.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/277959715368250136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/277959715368250136'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2021/06/how-to-use-option-buttons.html' title='How to Use Option Buttons (aka Radio Buttons or Option Groups)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg33Xs40Q5o3wD_2LArT3jA8l_um7mXi85k7PCfyWgFG2pzTCsdai4fBNrhkOkou9Chmk120oGZUutnbnM1SWPd6TuVxXdoqCEMpWt8dZpIEfNnA31NXV9_YMOV05E5OYIo06Uk-sgMzqw/s72-c/Option+Group.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4633669074431921111</id><published>2019-12-20T07:19:00.004-08:00</published><updated>2021-06-20T06:13:38.095-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="class module"/><category scheme="http://www.blogger.com/atom/ns#" term="custom&#xa; object"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Creating Custom Objects with Class Modules</title><content type='html'>&lt;div&gt;
Suppose we wanted to work with a set of related variables with VBA code.&amp;nbsp; Let&#39;s say these variables relate to a &lt;i&gt;person&lt;/i&gt;.&amp;nbsp; The information we want to store and process may include the person&#39;s &lt;i&gt;name&lt;/i&gt;, &lt;i&gt;age&lt;/i&gt; and &lt;i&gt;gender&lt;/i&gt;.&amp;nbsp;&amp;nbsp; The best way to do this would be to create our own custom &lt;i&gt;person object&lt;/i&gt;; with the above-mentioned variables as the object&#39;s &lt;i&gt;properties&lt;/i&gt;, and any code to process or work with these properties, as the object&#39;s &lt;i&gt;methods&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
The advantage of creating a custom object is that a lot of related information, and the means to process it, is contained within a referenced entity that is easily accessed and used from different parts of the program.&lt;br /&gt;
&lt;br /&gt;
There are two steps to creating a custom object. The first is to create a blueprint or design for the object which defines what information the object holds and the processing to be done on that information. To do this we create what is known as a &lt;b&gt;Class Module&lt;/b&gt;. The second step is to create the actual object based on the class module - this is known as &lt;i&gt;instantiation&lt;/i&gt;. Once the class module is in place, we can create as many instances, or objects based on the module, as we need. Hence, we may reuse the code we write in the class module over and over again.&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Let&#39;s go through the steps to create a class module:&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Creating a Class Module&lt;/h3&gt;
&lt;ol&gt;&lt;span style=&quot;background-color: white;&quot;&gt;
&lt;li&gt;Open the database in which the class module is to be created.&lt;/li&gt;
&lt;li&gt;Click the CLASS MODULE icon in the MACROS &amp;amp; CODE group of the CREATE ribbon.&amp;nbsp; This opens the VBA editor ready to enter code in our new class module.&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMP9ZxzuTMUbjNDDbPEqHZo8KwWEm-VMorZl9mEJw_s9xpR8iC7PlQMY7vLg8tXWKCrfyWhCiX5RkdJm7SH1fp5FUrfgga6wlFBiLFHf7DsiAaaK2BA-JBFudBnbD1fWqIHkFLazaxm2w/s1600/class+module+icon.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;141&quot; data-original-width=&quot;195&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMP9ZxzuTMUbjNDDbPEqHZo8KwWEm-VMorZl9mEJw_s9xpR8iC7PlQMY7vLg8tXWKCrfyWhCiX5RkdJm7SH1fp5FUrfgga6wlFBiLFHf7DsiAaaK2BA-JBFudBnbD1fWqIHkFLazaxm2w/s1600/class+module+icon.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Click SAVE CLASS MODULES in the FILE menu of the VBA editor.&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Give the new class module the name &quot;&lt;b&gt;clsPerson&lt;/b&gt;&quot; when the SAVE AS dialog window opens.&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibfgdP8G76tf9Kc12n08qSgkOoc78DvAsQ8_kRC2LiPDqvaiuYpuk3b7Ut-IXMYEL-TEfb02FHs8hRr3Pr51U2MmyCY0qhKZRiu_NBMjQTch0NKafJz9xtsdS4YQy7H1YmvVvu0VHv5oo/s1600/save.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;128&quot; data-original-width=&quot;280&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibfgdP8G76tf9Kc12n08qSgkOoc78DvAsQ8_kRC2LiPDqvaiuYpuk3b7Ut-IXMYEL-TEfb02FHs8hRr3Pr51U2MmyCY0qhKZRiu_NBMjQTch0NKafJz9xtsdS4YQy7H1YmvVvu0VHv5oo/s1600/save.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Save As dialog window&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;/span&gt;&lt;/ol&gt;
&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
Although we haven&#39;t started to enter code, the new clsPerson Module shows up in the VBA Project in the CLASS MODULES node of the VBA Project Explorer, and in the MODULES section of the main Access Navigation Pane.&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt; &lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieuIepQ8RwZscurA3hsPDm2xmqa0PHWO2kpB9mit2IXfi3BLuSwmZcl4AICX12gTUwgaUf4G0wetRtHJPSJND-9NdTtx0WZLg7sSU19Nv4nHCXEk0uVZrkfUjKRXX-eZ4Vfc8RimqF18k/s1600/VBA+project+explorer.jpg&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; clear: right; color: #0066cc; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 1em; margin-left: auto; margin-right: auto; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;239&quot; data-original-width=&quot;259&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieuIepQ8RwZscurA3hsPDm2xmqa0PHWO2kpB9mit2IXfi3BLuSwmZcl4AICX12gTUwgaUf4G0wetRtHJPSJND-9NdTtx0WZLg7sSU19Nv4nHCXEk0uVZrkfUjKRXX-eZ4Vfc8RimqF18k/s1600/VBA+project+explorer.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;VBA Project Explorer&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieuIepQ8RwZscurA3hsPDm2xmqa0PHWO2kpB9mit2IXfi3BLuSwmZcl4AICX12gTUwgaUf4G0wetRtHJPSJND-9NdTtx0WZLg7sSU19Nv4nHCXEk0uVZrkfUjKRXX-eZ4Vfc8RimqF18k/s1600/VBA+project+explorer.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt; &lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgboUTqVGNQ-3cUtrsNBT9mfUwU4KNFkn0lotkHSXHstRG9ayI5RJP0fKjhoPPrOL3iHh6lEpNt8g3EXWUyrdscdigVHuKoZdZv_SKkA9UYxQYxRchvc4Tb4A1oijFoQCr5rq5FTF0hyphenhyphenO4/s1600/Access+Navigation+Pane.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;211&quot; data-original-width=&quot;338&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgboUTqVGNQ-3cUtrsNBT9mfUwU4KNFkn0lotkHSXHstRG9ayI5RJP0fKjhoPPrOL3iHh6lEpNt8g3EXWUyrdscdigVHuKoZdZv_SKkA9UYxQYxRchvc4Tb4A1oijFoQCr5rq5FTF0hyphenhyphenO4/s1600/Access+Navigation+Pane.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Access Navigation Pane&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
Code to Create an Instance of the Class Module&lt;/h3&gt;
We will add code to our class module in the following section. Before doing so, however, let&#39;s look at how the class module is &lt;i&gt;instantiated&lt;/i&gt; - ie how the blueprint becomes an actual object. &lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Objects are instantiated in code outside of the class module itself, where the object is to be used - this may be in the code belonging to an Access form or report, or perhaps in a conventional module. &lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
There are two things we need to do. Firstly we define a variable through which the object can be referenced. We do this as follows:&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #073763; font-family: Verdana, sans-serif;&quot;&gt;Dim objPerson As clsPerson&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Here &lt;b&gt;objPerson&lt;/b&gt; is the name of the new object, and &lt;b&gt;clsPerson&lt;/b&gt; defines the object&#39;s type - ie the Class Module on which it is based.&lt;br /&gt;&lt;br /&gt;
Secondly, we instantiate the object with the &lt;b&gt;New&lt;/b&gt; keyword; and link the object to the variable that we created above with the &lt;b&gt;Set&lt;/b&gt; keyword. This is done as follows:&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Set objPerson = New clsPerson&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;However, before we can create an instance of the class we must first add our code to the class module. Let&#39;s start by writing the code to create the class module properties.&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #0b0599; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
Setting and Getting Class Module Property Values&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The person object we are creating has three properties - &lt;i&gt;name&lt;/i&gt;, &lt;i&gt;age&lt;/i&gt; and &lt;i&gt;gender&lt;/i&gt;.&amp;nbsp; Class properties are basically variables with CLASS MODULE level scope.&amp;nbsp; As such, they are declared pretty much the same way as variables in the declarations section of the CLASS MODULE, except we use the PRIVATE keyword instead of DIM.&amp;nbsp; As such, this is the code we need to write:&lt;br /&gt;
&lt;span style=&quot;color: #0b0599; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Private strName As String&lt;br /&gt;Private intAge As Integer&lt;br /&gt;Private strGender As String&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: blue;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: blue;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&lt;/span&gt; By restricting scope to CLASS MODULE level (as opposed to GLOBAL), the data stored in each variable cannot be accessed &lt;i&gt;directly&lt;/i&gt; from &lt;i&gt;outside&lt;/i&gt; the class module. This means we must set up a special sort of interface within the class module so we may &lt;i&gt;get&lt;/i&gt; and &lt;i&gt;set&lt;/i&gt; our object property values after the object has been instantiated.&amp;nbsp; We do this through &lt;b&gt;PROPERTY LET&lt;/b&gt; and &lt;b&gt;PROPERTY GET&lt;/b&gt;.&amp;nbsp; These are located in the main section of the class module code with it&#39;s SUB&#39;s and FUNCTIONS. Here are the blocks of code to &lt;i&gt;set&lt;/i&gt; and &lt;i&gt;get&lt;/i&gt; the NAME property stored in the &lt;i&gt;strName&lt;/i&gt; class module variable.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Property Let Name(strNameIn As String)&lt;br /&gt;&amp;nbsp;&amp;nbsp; strName = strNameIn&lt;br /&gt;End Property&lt;br /&gt;&lt;br /&gt;Property Get Name() As String&lt;br /&gt;&amp;nbsp;&amp;nbsp; Name = strName&lt;br /&gt;End Property&lt;/span&gt;&lt;span style=&quot;background-color: #073763;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #073763;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
Let&#39;s examine how these work.&amp;nbsp; Imagine we have created an instance of the &lt;b&gt;clsPerson&lt;/b&gt; class and called it &lt;b&gt;objPerson&lt;/b&gt;.&amp;nbsp; To set the &lt;b&gt;Name&lt;/b&gt; property of the object to, let&#39;s say, &quot;Sarah&quot;,&amp;nbsp; we would use the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;objPerson.Name = &quot;Sarah&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;color: #073763;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Doing this invokes &lt;b&gt;PROPERTY LET NAME&lt;/b&gt; in the &lt;b&gt;clsPerson&lt;/b&gt; class module code (see code snippet above).&amp;nbsp; The string value &quot;Sarah&quot; is received as the &lt;b&gt;strNameIn&lt;/b&gt; argument, and is then assigned to the &lt;b&gt;strName&lt;/b&gt; class module variable that we set up in the declarations section above.&amp;nbsp; As such,&amp;nbsp; PROPERTY LET has set the value of a &lt;i&gt;private&lt;/i&gt; class module variable from a location external to the class module itself.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Then to retrieve the value of the objects &lt;b&gt;Name&lt;/b&gt; property from outside the class module, we just need to reference the object name (eg &lt;b&gt;objPerson&lt;/b&gt;) and property (eg &lt;b&gt;Name&lt;/b&gt;) in the same way.&amp;nbsp; For example, to retrieve the property value and store it in a variable called &lt;i&gt;strGetName&lt;/i&gt; we would use the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #073763;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;strGetName = objPerson.Name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #073763;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
Doing this invokes PROPERTY GET NAME in the&lt;b&gt; clsPerson&lt;/b&gt; class module (see code snippet above).&amp;nbsp; PROPERTY GET returns a returns the value of the property by assigning a value to NAME.&amp;nbsp; As such, &quot;&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Name = strName&lt;/span&gt;&quot; assigns the value stored in the &lt;i&gt;strName&lt;/i&gt; class module variable to the objects &lt;b&gt;Name &lt;/b&gt;property and returns this value whenever the object&#39;s &lt;b&gt;Name&lt;/b&gt; property is referenced outside of the class module.&amp;nbsp; It works in a similar way to calling a VBA FUNCTION.&lt;br /&gt;
&lt;br /&gt;
The&lt;b&gt; Age&lt;/b&gt; and&lt;b&gt; Gender&lt;/b&gt; properties in the clsPerson class are set and retrieved in the same way.&amp;nbsp; The screenshot below shows all the class module code to set and get the clsPerson properties:&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1eYu9FG-b8eL7GajVyi8gBeyeRsJcE3B76s8Nht_IMjkTM6mZJa7nA9SoRucCyeYaoVRPOjeXFQ6oQno4-mJcPC945uE5JxZVyNgl79M-u8l5tJEcH37MndVvKseayl-ifmp86rxMQZk/s1600/class+module+code.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;516&quot; data-original-width=&quot;435&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1eYu9FG-b8eL7GajVyi8gBeyeRsJcE3B76s8Nht_IMjkTM6mZJa7nA9SoRucCyeYaoVRPOjeXFQ6oQno4-mJcPC945uE5JxZVyNgl79M-u8l5tJEcH37MndVvKseayl-ifmp86rxMQZk/s1600/class+module+code.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Class module code for &lt;b&gt;clsPerson&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Adding SUB&#39;s and FUNCTION&#39;s to the Class Module&lt;/h3&gt;
Class modules and objects are not just about storing and retrieving property values.&amp;nbsp; As written above, we can also process and work with those property values in all kinds of ways.&amp;nbsp; To do this, we add SUBs and FUNCTIONs to the class module.&amp;nbsp; These are referred to as class&lt;i&gt; methods&lt;/i&gt;, and providing they have been created using the PUBLIC keyword (as opposed to PRIVATE), they can be called from outside the class module after the object has been instantiated.&lt;br /&gt;
&lt;br /&gt;
We are going to create a simple method to categorize a person based on the information stored in the object properties.&amp;nbsp; When the method is called after instantiation, it will return one of eight categories which describe the person stored in our object.&amp;nbsp; These are:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Male under 18&lt;/li&gt;
&lt;li&gt;Female under 18&lt;/li&gt;
&lt;li&gt;Male 18 to 30&lt;/li&gt;
&lt;li&gt;Female 18 to 30&lt;/li&gt;
&lt;li&gt;Male 31 to 64&lt;/li&gt;
&lt;li&gt;Female 31 to 64&lt;/li&gt;
&lt;li&gt;Male 65 and over&lt;/li&gt;
&lt;li&gt;Female 65 and over&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
To do this we shall write a&amp;nbsp; PUBLIC FUNCTION called &lt;i&gt;categorizePerson&lt;/i&gt;. Here is the code we shall use:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Public Function categorizePerson()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;On Error GoTo myError&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim strAgeCat As String &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If intAge &amp;lt; 18 Then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strAgeCat = &quot;under 18&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf intAge &amp;gt; 18 And intAge &amp;lt;= 30 Then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strAgeCat = &quot;18 to 30&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf intAge &amp;gt; 30 And intAge &amp;lt;= 65 Then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strAgeCat = &quot;31 to 64&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf intAge &amp;gt;= 65 Then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strAgeCat = &quot;65 and over&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; categorizePerson = strGender &amp;amp; &quot; &quot; &amp;amp; strAgeCat &amp;nbsp; &lt;br /&gt;leave:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Function &amp;nbsp; &lt;br /&gt;myError:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox Error$&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Resume leave &amp;nbsp; &lt;br /&gt;End Function&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As we can see, the method uses IF .. THEN .. ELSEIF statements to select an age category based on the value of the age property stored in the intAge class module variable. The person&#39;s gender is then added to the description (thereby doubling the number of potential categories) and returned to the calling code.&lt;/div&gt;
&lt;div&gt;
The code to invoke the method after the object has been instantiated is as follows:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;objPerson.categorizePerson()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Testing the Custom Module&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In order to demonstrate how all this works in practice, I have created an unbound Access form to test our clsPerson class.&amp;nbsp; The form allows us to enter the three property values used by clsPerson, and create a new instance of the class containing these values when the SET PERSON PROPERTIES control button is clicked.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1MYDo9xKIsDDukc8XDP4N-huJSG7RB1EXKGDrRwfX6bHdYEu6n7EJRLwAoqJVeqdpLqSFW2oENZtXJS_9p3JQgBr8fDoljBnm3OD5K5pQ2-G_Ce-JP1_c1ccXKfCo9x-6BRimh3ye924/s1600/test+form.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;517&quot; data-original-width=&quot;567&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1MYDo9xKIsDDukc8XDP4N-huJSG7RB1EXKGDrRwfX6bHdYEu6n7EJRLwAoqJVeqdpLqSFW2oENZtXJS_9p3JQgBr8fDoljBnm3OD5K5pQ2-G_Ce-JP1_c1ccXKfCo9x-6BRimh3ye924/s1600/test+form.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
After clicking &lt;b&gt;SET PERSON PROPERTIES&lt;/b&gt; the &lt;b&gt;btnSet_Click&lt;/b&gt; event (shown in the screenshot below) is invoked. It&#39;s code creates a new object instance called &lt;b&gt;objPerson&lt;/b&gt; using the SET and NEW keywords. The values contained in the unbound textboxes are then referenced and set as the respective Name, Age and Gender properties for the object. Note how the &lt;b&gt;objPerson&lt;/b&gt; variable is declared in the declarations section of the form module so it will persist as long as the form is still open or its value is reset to &lt;b&gt;NOTHING&lt;/b&gt; when the &lt;b&gt;DELETE PERSON&lt;/b&gt; button is clicked thereby invoking the &lt;b&gt;btnDeleteObj_Click&lt;/b&gt; event.&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: #0b0599;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeWyXb9K67ob0ZggW4_mA5gLbJuCXmsharhX-uilWkwFqtbAfBLpUaOK1yNHMr5PCaO9Z8sNAgxFqC9N4u61ADoCS0v-LLXyGfhWABzWsyFnUZAIJf2jaJGeWmzeLu2z7ckObuzZI6FQ4/s1600/test+object+form.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;697&quot; data-original-width=&quot;507&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeWyXb9K67ob0ZggW4_mA5gLbJuCXmsharhX-uilWkwFqtbAfBLpUaOK1yNHMr5PCaO9Z8sNAgxFqC9N4u61ADoCS0v-LLXyGfhWABzWsyFnUZAIJf2jaJGeWmzeLu2z7ckObuzZI6FQ4/s1600/test+object+form.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq4eBDenl8DPSfHUxqv8t1jzuLbat-vtv2V9-eQPeKA0XaLgTtEGLNBGO1LPmF34twcLJlh6WukhOQM9IY0dR6ZPgSM8yyA7ZK3td8t40c4vamrCAqCfIdxPYyIOVyMHwuOulCfQRToyE/s1600/test+object+form+2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;333&quot; data-original-width=&quot;324&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq4eBDenl8DPSfHUxqv8t1jzuLbat-vtv2V9-eQPeKA0XaLgTtEGLNBGO1LPmF34twcLJlh6WukhOQM9IY0dR6ZPgSM8yyA7ZK3td8t40c4vamrCAqCfIdxPYyIOVyMHwuOulCfQRToyE/s1600/test+object+form+2.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Once the object has been created, the &lt;b&gt;btnSet&lt;/b&gt; button is disabled through the code logic in the &lt;b&gt;setControls&lt;/b&gt; sub (see screenshot above). This also enables the other three buttons which let us retrieve the property values, categorize the person, or delete the object.&lt;br /&gt;
&lt;br /&gt;
Clicking the &lt;b&gt;GET PERSON PERSON PROPERTIES &lt;/b&gt;button invokes the&lt;b&gt; btnGet_Click&lt;/b&gt; event where the property values are retrieved, added to a string variable, and displayed in the &lt;b&gt;OUTPUT&lt;/b&gt; textbox (see screenshot below).&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: #073763; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXoPbhlUyG_1N5yPQ-vZXkU7Uio0HSH6Lvm7aOBYs_psrU976HXNaxtzPFDb9KsMDHEsv3eFFRUlMNF0ZydciJSWSD03akEzu6d8MiMO334Sf66unpfthzUoz49I0yA84zEsowA-tRg-k/s1600/get+properties.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;507&quot; data-original-width=&quot;558&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXoPbhlUyG_1N5yPQ-vZXkU7Uio0HSH6Lvm7aOBYs_psrU976HXNaxtzPFDb9KsMDHEsv3eFFRUlMNF0ZydciJSWSD03akEzu6d8MiMO334Sf66unpfthzUoz49I0yA84zEsowA-tRg-k/s1600/get+properties.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #073763;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #0b0599; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Finally, clicking the &lt;b&gt;CATEGORIZE PERSON&lt;/b&gt; button invokes code in the &lt;b&gt;btnCat_Click&lt;/b&gt; event and the category is displayed in the OUTPUT textbox (see below)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8i-kQ3dVsKbz-qJZnbJ67s-fHg_hLF1ls5SfLxAB-4MD718f3ln1ze3GN1QnwVtwAWz8uO_Ju0hwXcGndjZo3CI0NWdrV1ET4zhK1F-DxiIh48gbxWf7dOjIoWfDW6Gywu38DMXH2gM/s1600/categorize.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;185&quot; data-original-width=&quot;286&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8i-kQ3dVsKbz-qJZnbJ67s-fHg_hLF1ls5SfLxAB-4MD718f3ln1ze3GN1QnwVtwAWz8uO_Ju0hwXcGndjZo3CI0NWdrV1ET4zhK1F-DxiIh48gbxWf7dOjIoWfDW6Gywu38DMXH2gM/s1600/categorize.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
As such, we can see how the properties and methods in clsPerson (ie &lt;b&gt;PROPERTY LET&lt;/b&gt;, &lt;b&gt;PROPERTY GET&lt;/b&gt;, and &lt;b&gt;CATEGORIZE PERSON&lt;/b&gt;) are invoked with statements such as &lt;b&gt;objPerson.categorisePerson&lt;/b&gt; after the object has been instantiated in the &lt;b&gt;TEST CUSTOM PERSON OBJECT&lt;/b&gt; form.&amp;nbsp; I hope this gives you a good example of how VBA class modules and custom objects work in practice.&lt;/div&gt;
&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/4633669074431921111/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/12/creating-custom-objects-with-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4633669074431921111'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4633669074431921111'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/12/creating-custom-objects-with-class.html' title='Creating Custom Objects with Class Modules'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMP9ZxzuTMUbjNDDbPEqHZo8KwWEm-VMorZl9mEJw_s9xpR8iC7PlQMY7vLg8tXWKCrfyWhCiX5RkdJm7SH1fp5FUrfgga6wlFBiLFHf7DsiAaaK2BA-JBFudBnbD1fWqIHkFLazaxm2w/s72-c/class+module+icon.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2017151586167772815</id><published>2019-05-17T04:19:00.000-07:00</published><updated>2019-05-20T02:56:19.505-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="external data"/><category scheme="http://www.blogger.com/atom/ns#" term="MS Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="tables"/><title type='text'>Linking Access to an Excel Worksheet</title><content type='html'>Excel is great for number crunching, and can even be used as a basic database to store information.&amp;nbsp; However, when it comes to displaying and presenting information, the MS Access database has some big advantages over it&#39;s peer in the Office 365 suite of software. The reason for this is that Access has a number of tools and features specifically designed to make data easier to read and understand - the &lt;i&gt;&lt;a href=&quot;http://www.dealing-with-data.net/create-access-report.html&quot; target=&quot;_blank&quot;&gt;Reports&lt;/a&gt;&lt;/i&gt; facility being just one.&lt;br /&gt;
&lt;br /&gt;
The good news is that Access has the ability to connect to, and work with, Excel data in two different ways.&amp;nbsp; Firstly, Access can &lt;i&gt;import&lt;/i&gt; data from an Excel worksheet into an Access table.&amp;nbsp; This method lets us work with a &quot;snapshot&quot; of data from Excel as it was at the time the data was extracted (there is more information about importing from Excel in my post on &lt;a href=&quot;http://ms-access-tips.blogspot.com/2011/06/importing-and-exporting-data-between.html&quot; target=&quot;_blank&quot;&gt;&quot;Importing and Exporting Data between Access and Excel&quot;&lt;/a&gt;).&amp;nbsp; The second method is to set up a &quot;live&quot; &lt;i&gt;link&lt;/i&gt; between the Excel worksheet and the Access table. This has the advantage of giving us direct access to current data in the spreadsheet; so any updates, additions or deletions will show up in Access (after data is refreshed/reloaded) as soon as the data is saved in Excel. However, please do note that this connection is read-only; new data cannot be saved back into the Excel spreadsheet without specifically doing an additional &lt;i&gt;export&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Today we are going to learn how to set up this &quot;live&quot; link. To do so, I have set up a sample Excel worksheet with fictitious personnel records.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Linking to Excel&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ol start=&quot;1&quot; type=&quot;1&quot;&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12.0pt;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;Create a new Access Database, or open an existing one.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12.0pt;&quot;&gt;Select the EXTERNAL DATA ribbon.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 12.0pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Click the NEW DATA SOURCE icon in the IMPORT AND LINK group.&lt;/span&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGIP2z-F8CDWMHgVsLu9TtrhAOnanjYNQt8Mx2PHyNiebgWnou7X4WCfR-D5h-_7fFN4LYFRTFfmFULkzRNGkF8pEkytMm_JqYWAUyl5WoD3tMal6-eiLE1fwvXRh2TNrrAxUNFvJW84Y/s1600/External_Data.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;img alt=&quot;External Data Ribbon&quot; border=&quot;0&quot; data-original-height=&quot;485&quot; data-original-width=&quot;652&quot; height=&quot;475&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGIP2z-F8CDWMHgVsLu9TtrhAOnanjYNQt8Mx2PHyNiebgWnou7X4WCfR-D5h-_7fFN4LYFRTFfmFULkzRNGkF8pEkytMm_JqYWAUyl5WoD3tMal6-eiLE1fwvXRh2TNrrAxUNFvJW84Y/s640/External_Data.jpg&quot; title=&quot;External Data Ribbon&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; Adding a&lt;b&gt; New Data Source&lt;/b&gt; from the &lt;b&gt;External Data&lt;/b&gt; ribbon.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 12.0pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Select FROM FILE from the drop-down menu, and then EXCEL from the sub-menu.&amp;nbsp; This opens the GET EXTERNAL DATA - EXCEL SPREADSHEET dialog form.&lt;span style=&quot;background-color: white; color: black; display: inline; float: none; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKws8qnyhC0dHe87OeQX1qkkkW18RVOIqeIczz__K4K4quAipClNYQhJ5JV10vCP-URNGUMtNgETAZyC-BGa4VzvBvez87Ot6TeX57UfbQhZpGSubtJS0oIkJZ25-tECkCUp6Lv-S3xcQ/s1600/select-source.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Get External Data - Excel Spreadsheet dialog form&quot; border=&quot;0&quot; data-original-height=&quot;552&quot; data-original-width=&quot;741&quot; height=&quot;475&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKws8qnyhC0dHe87OeQX1qkkkW18RVOIqeIczz__K4K4quAipClNYQhJ5JV10vCP-URNGUMtNgETAZyC-BGa4VzvBvez87Ot6TeX57UfbQhZpGSubtJS0oIkJZ25-tECkCUp6Lv-S3xcQ/s640/select-source.jpg&quot; title=&quot;Get External Data - Excel Spreadsheet dialog form&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; The&lt;b&gt; Get External Data - Excel Spreadsheet&lt;/b&gt; dialog form.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/span&gt; &lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12.0pt;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;Click the BROWSE button and select the Excel spreadsheet you want to link to.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12.0pt;&quot;&gt;Click the LINK TO A DATA SOURCE BY CREATING A LINKED TABLE radio button, and then click OK. &amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-size: 12.0pt;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;The next page of the wizard opens where you should see a sample of the worksheet you are linking to.&amp;nbsp; If your worksheet had column headings, ensure the FIRST ROW CONTAINS COLUMN HEADINGS box is ticked, and click NEXT. (Please note that if your spreadsheet has more than one worksheet or named range, you will see an additional wizard page asking you to select the specific worksheet or range before the page in the screenshot below).&lt;/span&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv6H9XWrliQQbHh64QFaJTSFFi6Odu0wyN66F07X1xEBZAhSzai08cR27UJvSUCLHz8ebHBuAaaBvOZUGARVCYurlI0CgkkidwLtSsgHwZXeZ_RIEi2N_iDrgeVq-1qAc1Qf56yWj1PbE/s1600/link-spreadsheet-wizard.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;img alt=&quot;MS Access - Link Spreadsheet Wizard&quot; border=&quot;0&quot; data-original-height=&quot;542&quot; data-original-width=&quot;740&quot; height=&quot;468&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgv6H9XWrliQQbHh64QFaJTSFFi6Odu0wyN66F07X1xEBZAhSzai08cR27UJvSUCLHz8ebHBuAaaBvOZUGARVCYurlI0CgkkidwLtSsgHwZXeZ_RIEi2N_iDrgeVq-1qAc1Qf56yWj1PbE/s640/link-spreadsheet-wizard.jpg&quot; title=&quot;MS Access - Link Spreadsheet Wizard&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: First page of the &lt;b&gt;Link Spreadsheet Wizard&lt;/b&gt;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;color: black; font-size: 12pt; font-style: normal; font-weight: 400; line-height: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot; , serif; font-size: 12.0pt;&quot;&gt;Enter the name you are going to call the linked Access table in the last page of the wizard, and click FINISH.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div&gt;
Once you have done this, you will see the new linked table appear in the left-hand Access navigation pane under TABLES.&amp;nbsp; Note how the linked table icon is a blue arrow pointing to the Excel logo, thereby indicating the table is linked to an Excel spreadsheet.&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRGmHY8cX83kQJGobsItHzq08RNwfC0b3sg9u5gm-PJwHXXOGwKfm-8UBUMJGiZd_SmoCMuUCAjPBRTaqBr86fSMXLlZfGExc5ZBeyEVdGf73ebcONPy-CO9FrUGuAexlQB-fnc0mNOtg/s1600/tbl_personnel.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;MS Access table linked to Excel&quot; border=&quot;0&quot; data-original-height=&quot;319&quot; data-original-width=&quot;973&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRGmHY8cX83kQJGobsItHzq08RNwfC0b3sg9u5gm-PJwHXXOGwKfm-8UBUMJGiZd_SmoCMuUCAjPBRTaqBr86fSMXLlZfGExc5ZBeyEVdGf73ebcONPy-CO9FrUGuAexlQB-fnc0mNOtg/s1600/tbl_personnel.jpg&quot; title=&quot;MS Access table linked to Excel&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: The table linked to Excel.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
Now the link has been established to the Excel worksheet, we are free to base &lt;a href=&quot;http://www.dealing-with-data.net/create-access-form.html&quot; target=&quot;_blank&quot;&gt;forms&lt;/a&gt;, &lt;a href=&quot;http://www.dealing-with-data.net/create-access-report.html&quot; target=&quot;_blank&quot;&gt;reports&lt;/a&gt; and &lt;a href=&quot;http://www.dealing-with-data.net/create-access-query.html&quot; target=&quot;_blank&quot;&gt;queries&lt;/a&gt; on the linked table as if it is native to Access itself.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/2017151586167772815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/05/linking-access-to-excel-worksheet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2017151586167772815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2017151586167772815'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/05/linking-access-to-excel-worksheet.html' title='Linking Access to an Excel Worksheet'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGIP2z-F8CDWMHgVsLu9TtrhAOnanjYNQt8Mx2PHyNiebgWnou7X4WCfR-D5h-_7fFN4LYFRTFfmFULkzRNGkF8pEkytMm_JqYWAUyl5WoD3tMal6-eiLE1fwvXRh2TNrrAxUNFvJW84Y/s72-c/External_Data.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-7308332217016022369</id><published>2019-04-05T02:30:00.002-07:00</published><updated>2019-04-05T02:34:10.296-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="calculated control"/><category scheme="http://www.blogger.com/atom/ns#" term="Controls"/><category scheme="http://www.blogger.com/atom/ns#" term="custom function"/><category scheme="http://www.blogger.com/atom/ns#" term="expressions"/><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="module"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Using Custom Functions in Calculated Controls</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Back in May 2012, I wrote a blog article on &lt;a href=&quot;https://ms-access-tips.blogspot.com/2012/05/writing-custom-functions-for-access-vba.html&quot; target=&quot;_blank&quot;&gt;Writing Custom Functions for Access VBA&lt;/a&gt;.&amp;nbsp; Custom functions work the same way as MS Access built-in functions such as &lt;i&gt;DateAdd&lt;/i&gt;, &lt;i&gt;DatePart&lt;/i&gt; and &lt;i&gt;DSum&lt;/i&gt;, but are instead created ourselves as database developers.&amp;nbsp; We do this by creating a public function with the VBA programming language and save it inside a global module within the database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The blog I wrote in 2012 explained how these custom functions can be accessed from sub procedures associated with forms and reports elsewhere in the database.&amp;nbsp; Today, however, I am going to explain how custom functions can be utilised in &lt;i&gt;calculated form controls&lt;/i&gt;, without needing to invoke them with VBA itself.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s begin by looking at the custom function we are going to use.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Custom Function to get Week Commencing&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I have created a custom function called &lt;i&gt;getWeekCommencing&lt;/i&gt; to calculate the week commencing date of a given week, in a given year.&amp;nbsp; For example, the week commencing date of the &lt;b&gt;14th&lt;/b&gt; week of &lt;b&gt;2019&lt;/b&gt; is &lt;b&gt;1st&lt;/b&gt; &lt;b&gt;April 2019&lt;/b&gt; (if we count Monday as the first day of the week). As such the function takes two arguments -&lt;b&gt; week number &lt;/b&gt;and &lt;b&gt;year&lt;/b&gt;.&amp;nbsp; The full syntax for using the function is as follows:&lt;/div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;/span&gt;getWeekCommencing(weekNumber, Year)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The code I used to create this function is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Public Function getWeekCommencing(intWeekNo, intYear)&lt;br /&gt;On Error GoTo myError&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim intJan1 As Integer&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim varStartDate As Variant &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; intJan1 = Weekday(DateSerial(intYear, 1, 1), vbMonday)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; varStartDate = DateAdd(&quot;d&quot;, -(intJan1 - 1), DateSerial(intYear, 1, 1))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; getWeekCommencing = DateAdd(&quot;ww&quot;, intWeekNo - 1, varStartDate) &amp;nbsp; &lt;br /&gt;leave:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Function&lt;br /&gt;myError:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox Error$&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Resume leave &amp;nbsp; &lt;br /&gt;End Function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt; &lt;span style=&quot;color: #000025; font-family: inherit;&quot;&gt;If you are unfamiliar with VBA you can still copy this code into your database and use it within a calculated control. There are instructions for doing this below:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000025;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Instructions for adding the function to your database&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&amp;nbsp;Copy the code above onto your clipboard.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Open the database you are going to add the function to.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Select the CREATE ribbon.&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNN1FooTapbQW6ecRSmmZv-i4-SkTkRPZjEbQH5SDu9FsvoAIcnhXXEse-4cY2yQ5rceu_TRGitah4r67RgvKIuEJN8TXf5rpLL9R5KUnryyCNcFiclWW0HV8V5-TSMeIXstx48qLrL5o/s1600/new+module.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNN1FooTapbQW6ecRSmmZv-i4-SkTkRPZjEbQH5SDu9FsvoAIcnhXXEse-4cY2yQ5rceu_TRGitah4r67RgvKIuEJN8TXf5rpLL9R5KUnryyCNcFiclWW0HV8V5-TSMeIXstx48qLrL5o/s1600/new+module.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;314&quot; data-original-width=&quot;959&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNN1FooTapbQW6ecRSmmZv-i4-SkTkRPZjEbQH5SDu9FsvoAIcnhXXEse-4cY2yQ5rceu_TRGitah4r67RgvKIuEJN8TXf5rpLL9R5KUnryyCNcFiclWW0HV8V5-TSMeIXstx48qLrL5o/s640/new+module.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; The&lt;b&gt; MODULE&lt;/b&gt; icon is located on the right-hand side of the&lt;b&gt; CREATE&lt;/b&gt; ribbon.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;Click the MODULE icon from the MACROS AND CODE group.&amp;nbsp; This opens the VBA editor and creates a new module ready for the code to be added:&lt;/li&gt;
&lt;li&gt;Paste the code into the VBA editor as in the screenshot below:&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvvXyCorRTO2tm0fiY5fSbI8Nhn4lFJ1O3CruQskQchX13BdUfUKM9LXCUkzLHyOmLCd3ANn8Sg2XZw8NHHsouwaQaqrUGdIHlK6sV7iP5L8Z4zHNBF6xgo1U7NrwosMDabpSQLE7rdoI/s1600/vba+function.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;476&quot; data-original-width=&quot;1130&quot; height=&quot;268&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvvXyCorRTO2tm0fiY5fSbI8Nhn4lFJ1O3CruQskQchX13BdUfUKM9LXCUkzLHyOmLCd3ANn8Sg2XZw8NHHsouwaQaqrUGdIHlK6sV7iP5L8Z4zHNBF6xgo1U7NrwosMDabpSQLE7rdoI/s640/vba+function.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
&lt;b&gt;Above: The VBA Editor:&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
You may notice that I have changed the default name of the Module (see the PROJECT EXPLORER in the&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
left-hand side bar) from Module 3 to &quot;&lt;b&gt;myFunctions&lt;/b&gt;&quot;.&amp;nbsp; You can do the same by highlighting the module name in the&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
project explorer and hitting the F4 button to bring up the PROPERTIES window. You may then change the name property&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;to one of your choice.&amp;nbsp; However, this is not essential.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div&gt;
The custom function is now ready to use in a calculated form control.&amp;nbsp;&lt;/div&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Setting up the Test Data for this Exercise&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Before we create the form to test the function, we first need to set up a simple database table containing test data. The table needs just two fields: &lt;b&gt;WeekOfYear&lt;/b&gt; and &lt;b&gt;Year&lt;/b&gt;, both of which are of the NUMBER data type.&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEgILUmqfb68K5DV3a3th-gEN01dv5zmGkGvjJF7UqzxZWNaWNgtOSYHHhAe07495LaxNPR5p8JwOXqLNTvPkKqjsTCp5lJA2q4xJjdwcUsVJlH12tOj1BBesXP3t7jySmdQQPO0OZBNQ/s1600/test+table.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;103&quot; data-original-width=&quot;385&quot; height=&quot;85&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEgILUmqfb68K5DV3a3th-gEN01dv5zmGkGvjJF7UqzxZWNaWNgtOSYHHhAe07495LaxNPR5p8JwOXqLNTvPkKqjsTCp5lJA2q4xJjdwcUsVJlH12tOj1BBesXP3t7jySmdQQPO0OZBNQ/s320/test+table.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; tblWeeks in Design View&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDRzxMn76nh_DQ8VitbUQ6tQmOyWxH06oDlcs6CHoJerRDr1s5YtdQPz-8OZ8mVQy0W7IOLIe0SV1Kz-q8gPLR-o_xxv-EMGZ3J-jsVG9IfEyC9Gw_RoEDSWmhXpJJz1s58gITM-XMQMA/s1600/tblWeeks.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;309&quot; data-original-width=&quot;235&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDRzxMn76nh_DQ8VitbUQ6tQmOyWxH06oDlcs6CHoJerRDr1s5YtdQPz-8OZ8mVQy0W7IOLIe0SV1Kz-q8gPLR-o_xxv-EMGZ3J-jsVG9IfEyC9Gw_RoEDSWmhXpJJz1s58gITM-XMQMA/s1600/tblWeeks.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above: &lt;/b&gt;tblWeeks in Form View with test data entered.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
Once the table is set up, we can add our test data as I have done in the screenshot above. Although there are&amp;nbsp; 52 week in the year, the first week may not start on a Monday, so the data entered in &lt;b&gt;WeekOfYear&lt;/b&gt; field can be anything between 1 and 53 (so the possibility of a partial first week is offset by Week 53).&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The Calculated Control&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
Now we have added the &lt;b&gt;getWeekCommencing&lt;/b&gt; function along with test data to our database, we can create the form containing the calculated control.&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsXsXqKvCqrYA4TRikmOlKEu6Ydr3xfw0aCH6_mhHr6XXm-Qutw-Q5IAOBc9Ttzaiv3ChVFMFAWSWTD2XO6bOGoMaj9jNrm99jiZ-2eafjVtf2Oo6VAAPyhlDo9TW6SNDxiF_t5VJ46WI/s1600/WeekCommmencingCalculator.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;276&quot; data-original-width=&quot;405&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsXsXqKvCqrYA4TRikmOlKEu6Ydr3xfw0aCH6_mhHr6XXm-Qutw-Q5IAOBc9Ttzaiv3ChVFMFAWSWTD2XO6bOGoMaj9jNrm99jiZ-2eafjVtf2Oo6VAAPyhlDo9TW6SNDxiF_t5VJ46WI/s1600/WeekCommmencingCalculator.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: The Week Commencing Calculator form in Design View.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
To do this we need to create a form bound to the &lt;b&gt;tblWeeks&lt;/b&gt; table.&amp;nbsp; We then need to add three text boxes:&amp;nbsp; the first text box (&lt;b&gt;txtWeekOfYear&lt;/b&gt;) is bound to the &lt;b&gt;WeekOfYear&lt;/b&gt; field in &lt;b&gt;tblWeeks&lt;/b&gt;, and the second (&lt;b&gt;txtYear&lt;/b&gt;) is bound to the &lt;b&gt;Year&lt;/b&gt; field.&amp;nbsp; The third text&amp;nbsp;box (&lt;b&gt;txtWeekCommencing&lt;/b&gt;) is unbound.&amp;nbsp; This is where we are going to add our calculated control which returns the &lt;i&gt;week commencing date (&lt;/i&gt;based on the data displayed in the &lt;b&gt;WeekOfYear&lt;/b&gt; and &lt;b&gt;Year&lt;/b&gt; textboxes).&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Here are the instructions for creating the calculated control:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Create the third text box that we are going to use for the calculated control as in the screenshot above.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Display the PROPERTY SHEET if it is not already visibile.&amp;nbsp; The PROPERTY SHEET icon is located in the TOOLS group of the DESIGN ribbon.&lt;/li&gt;
&lt;li&gt;Select the new text box by clicking on it.&lt;/li&gt;
&lt;li&gt;Click the &lt;b&gt;OTHER&lt;/b&gt; tab of the PROPERTY SHEET, and change the &lt;b&gt;NAME&lt;/b&gt; property to &lt;b&gt;txtWeekCommencing&lt;/b&gt;. (I also suggest you change the names of the first textbox to &lt;b&gt;txtWeekOfYear&lt;/b&gt; and the second to &lt;b&gt;txtYear&lt;/b&gt; by selecting them and changing the &lt;b&gt;NAME&lt;/b&gt; properties).&lt;/li&gt;
&lt;li&gt;Click the &lt;b&gt;DATA&lt;/b&gt; tab on the PROPERTY SHEET (having first selected &lt;b style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;txtWeekCommencing&lt;/b&gt;&lt;span style=&quot;background-color: white; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;)&lt;/span&gt;.&amp;nbsp; We are now going to enter an expression which uses our &lt;b&gt;getWeekCommencing&lt;/b&gt; custom function. &amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Enter the expression below directly into the CONTROL SOURCE property:&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;=getWeekCommencing([txtWeekNumber],[txtYear])&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #000013; font-family: inherit;&quot;&gt;The &lt;b&gt;txtWeekNumber&lt;/b&gt; parameter references the value in the &lt;b&gt;txtWeekNumber&lt;/b&gt; textbox, and the &lt;b&gt;txtYear&lt;/b&gt; parameter does the same for the &lt;b&gt;txtYear&lt;/b&gt; text box. &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #000013; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqAhH-C9BqVB8gzk0CMYJnbhPxlNFEa-orDJDuTEjvxPI96fCEA_tJuWu67oMQ8pnJ74euc5IAUPvzFDp9HMnJiLOAb_gqyngb7gqKjgnRuZdOHYd3LrpMPLDwG3X5u3QRy2nOIgbn4Yk/s1600/control+source+property.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;316&quot; data-original-width=&quot;877&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqAhH-C9BqVB8gzk0CMYJnbhPxlNFEa-orDJDuTEjvxPI96fCEA_tJuWu67oMQ8pnJ74euc5IAUPvzFDp9HMnJiLOAb_gqyngb7gqKjgnRuZdOHYd3LrpMPLDwG3X5u3QRy2nOIgbn4Yk/s1600/control+source+property.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
In this exercise, the expression was entered directly into the CONTROL SOURCE&lt;/div&gt;
&lt;div&gt;
property.&amp;nbsp; Alternatively, we could have clicked the elipse button at the end of the CONTROL SOURCE&lt;br /&gt;
property row to open the &lt;b&gt;EXPRESSION BUILDER&lt;/b&gt;.&amp;nbsp; Using the Expresison Builder is, however, something&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
I would need to cover another day, in another post!&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
And that&#39;s it! All you need to do now is save the form and open it in FORM VIEW.&amp;nbsp; Use the form&#39;s navigation buttons to view each record in the &lt;b&gt;tblWeeks&lt;/b&gt; table.&amp;nbsp; The calculated control uses the &lt;i&gt;getWeekCommencing&lt;/i&gt; custom function to processes the week number and year data for the current &lt;b&gt;tblWeeks&lt;/b&gt; record, and displays the appropriate date.&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj91vrTcleiGCUeeUE_xTtEz0SSLc-jojAsNt2TSoyni_CgEyZxmDrjccKn_o5Ksz86fYfrQsT6PoYoT_gnHD1xRFk2xWI0Pox_k6F4hZi2MlX2KRCjddexBd0sLD-ZbWhN_yQmL-eB42k/s1600/form+view.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;210&quot; data-original-width=&quot;352&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj91vrTcleiGCUeeUE_xTtEz0SSLc-jojAsNt2TSoyni_CgEyZxmDrjccKn_o5Ksz86fYfrQsT6PoYoT_gnHD1xRFk2xWI0Pox_k6F4hZi2MlX2KRCjddexBd0sLD-ZbWhN_yQmL-eB42k/s1600/form+view.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
NB - Just to clarify, the format for the week commencing date in this screenshot is for the UK (ie dd/mm/yyyy).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
The same date using the US format would be 01/07/2019 (mm/dd/yyyy). However, your computer should be set up&lt;br /&gt;
to display the date format appropriate for your location automatically.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/7308332217016022369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/04/custom-functions-in-calculated-controls.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/7308332217016022369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/7308332217016022369'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/04/custom-functions-in-calculated-controls.html' title='Using Custom Functions in Calculated Controls'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNN1FooTapbQW6ecRSmmZv-i4-SkTkRPZjEbQH5SDu9FsvoAIcnhXXEse-4cY2yQ5rceu_TRGitah4r67RgvKIuEJN8TXf5rpLL9R5KUnryyCNcFiclWW0HV8V5-TSMeIXstx48qLrL5o/s72-c/new+module.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-5976442578474388390</id><published>2019-03-02T14:14:00.000-08:00</published><updated>2019-03-02T14:14:38.746-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="calculated control"/><category scheme="http://www.blogger.com/atom/ns#" term="DateDiff"/><category scheme="http://www.blogger.com/atom/ns#" term="FormatDateTime"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><title type='text'>Converting Minutes to Hours:Minutes in MS Access</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
There may be occasions when we need to convert the difference between a&lt;i&gt; &lt;b&gt;start time&lt;/b&gt;&lt;/i&gt; and an &lt;i&gt;&lt;b&gt;end time&lt;/b&gt;&lt;/i&gt;, and display the result in &lt;b&gt;&lt;i&gt;hours and minutes&lt;/i&gt;&lt;/b&gt;.&amp;nbsp; For example, suppose we set up an Access table field to record the time a person starts work (the &lt;b&gt;session_start&lt;/b&gt; field) and another to record when s/he finishes (the &lt;b&gt;session_end&lt;/b&gt;) field.&amp;nbsp; Rather than set up a third field to store the &lt;b&gt;total time worked&lt;/b&gt;, we can instead calculate this value automatically using a &lt;b&gt;calculated control&lt;/b&gt; in an Access &lt;i&gt;form&lt;/i&gt;, or a&lt;b&gt; calculated field&lt;/b&gt; in an Access &lt;i&gt;query&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6Ub8V9FMscGt6p6xwPhQAd_mY-Qw-pckOJAEpkKgXuoxqV_SlKiyENIyh6-3w08LhpuAdwh4hrt-xllGedwtUbc_pgXrmrOxf2A0kH9sZMPW5zczIVxzScVAUIQIlu3XQIwne1biSz4/s1600/calculated+control+textbox.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;b&gt;&lt;img alt=&quot;Calculated Control&quot; border=&quot;0&quot; data-original-height=&quot;113&quot; data-original-width=&quot;245&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6Ub8V9FMscGt6p6xwPhQAd_mY-Qw-pckOJAEpkKgXuoxqV_SlKiyENIyh6-3w08LhpuAdwh4hrt-xllGedwtUbc_pgXrmrOxf2A0kH9sZMPW5zczIVxzScVAUIQIlu3XQIwne1biSz4/s1600/calculated+control+textbox.jpg&quot; title=&quot;Calculated Control&quot; /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: the bottom text box (&lt;b&gt;txtHoursWorked&lt;/b&gt;) is a calculated control.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;The&lt;b&gt; CONTROL SOURCE&lt;/b&gt; is an expression based on the values contained in &lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;the top two text boxes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;(bound to the&lt;b&gt; session_start&lt;/b&gt; and&lt;b&gt; session_end&lt;/b&gt; fields in the undelying table).&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, to do this we must use two expressions to calculate the time difference, and then display the time difference in the &lt;b&gt;hrs:mm&lt;/b&gt; format.&amp;nbsp; So if we enter&lt;u&gt; 20:40&lt;/u&gt; as the&lt;b&gt; session_start,&lt;/b&gt; and &lt;u&gt;22:06&lt;/u&gt; for &lt;b&gt;session_end&lt;/b&gt;, we need an expression to calculate the total minutes worked (which in this case is &lt;u&gt;86&lt;/u&gt; minutes), and then convert the total &lt;i&gt;minutes&lt;/i&gt; to&lt;i&gt; hours/minutes &lt;/i&gt;format (which would be&lt;u&gt; 01:26&lt;/u&gt;).&amp;nbsp; To achieve this we use the&lt;b&gt; DateDiff&lt;/b&gt; and&lt;b&gt; FormatDateTime&lt;/b&gt; functions.&amp;nbsp; Lets take a look at each function individually before combing them to produce the required result.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The syntax for the &lt;b&gt;DateDiff&lt;/b&gt; function is as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Times New Roman;&quot;&gt;&lt;/span&gt;DateDiff(&quot;interval&quot;, time_1, time_2)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The function works by calculating the time difference between&lt;b&gt; &lt;/b&gt;the &lt;b&gt;time_1&lt;/b&gt; and&lt;b&gt; time_2 &lt;/b&gt;parameters, and returns the result in accordance with the&lt;b&gt; interval&lt;/b&gt; parameter.&amp;nbsp; In our case, we want need the result returned as &lt;b&gt;minutes&lt;/b&gt;, so enter&lt;b&gt; &quot;n&quot;&lt;/b&gt; as interval. &amp;nbsp; &lt;b&gt;Time_1&lt;/b&gt; and&lt;b&gt; Time_2&lt;/b&gt; correspond to the &lt;b&gt;start time&lt;/b&gt; and &lt;b&gt;end time&lt;/b&gt;.&amp;nbsp; To get these values for the expression, we can we put a reference to the values contained in the text boxes for &quot;&lt;i&gt;Start time&lt;/i&gt;&quot; and &quot;&lt;i&gt;End time&lt;/i&gt;&quot;.&amp;nbsp; In our example these text boxes are called&lt;i&gt; &lt;b&gt;txtStartTime&lt;/b&gt;&lt;/i&gt; and &lt;i&gt;&lt;b&gt;txtEndTime&lt;/b&gt;.&lt;/i&gt;&amp;nbsp; This what our &lt;b&gt;DateDiff&lt;/b&gt; function looks once we add the parameter values:&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;DateDiff(&quot;n&quot;, txtStartTime, txtEndTime)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
The value returned in our example is &lt;u&gt;&lt;b&gt;86&lt;/b&gt;&lt;/u&gt; minutes.&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The second function that we are going to use is &lt;b&gt;FormatDateTime &lt;/b&gt;which converts the value returned by the &lt;b&gt;DateDiff&lt;/b&gt; function into hours and minutes.&amp;nbsp; The syntax we need to use in the &lt;b&gt;FormatDateTime&lt;/b&gt; is as follows:&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;FormatDateTime( (minutes/(24*60) , named_format)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This first parameter is a division of the &lt;i&gt;number of minutes&lt;/i&gt; (returned in the &lt;b&gt;DiffFunction&lt;/b&gt;) by the &lt;i&gt;total number of minutes in a day -&amp;nbsp;&lt;/i&gt; which in our example is &lt;b&gt;86/(24*60)&lt;/b&gt; - and returns the result in accordance with the value contained in the &lt;b&gt;named_format&lt;/b&gt; parameter.&amp;nbsp; The latter is a numeric value indicating the required time format - which in our example is &lt;b&gt;vbShortTime&lt;/b&gt; ie &lt;b&gt;hours:minutes&lt;/b&gt;.&amp;nbsp; The numeric value we enter for the &lt;b&gt;vbShortTime&lt;/b&gt; format is&lt;b&gt;&lt;u&gt; 4&lt;/u&gt;&lt;/b&gt;.&amp;nbsp; This is what our &lt;b&gt;FormatDateTime&lt;/b&gt; function looks like once we add the parameter values:&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;FormatDateTime((86/(24*60) , 4)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
The value returned from this expression is&lt;b&gt;&lt;u&gt; 01:26&lt;/u&gt;&lt;/b&gt; - ie 1 hour and 26 minutes.&lt;br /&gt;
&lt;u&gt;&lt;/u&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;u&gt;&lt;/u&gt;&lt;b&gt;&lt;/b&gt;&lt;u&gt;&lt;/u&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When we come to enter the actual expression used as the control source for the &lt;b&gt;TOTAL (HRS:MINS)&lt;/b&gt; text box (referred to as &lt;b&gt;txtHoursWorked &lt;/b&gt;in the screenshot below), we need to combine these two functions by nesting the &lt;b&gt;DateDiff&lt;/b&gt; function inside the&lt;i&gt; first parameter&lt;/i&gt; of the &lt;b&gt;FormatDateTime&lt;/b&gt; function. This is done as follows:&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: large;&quot;&gt;FormatDateTime((DateDiff(&quot;n&quot;, txtStartTime, txtEndTime/(24*60) , 4)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Finally, we just need to enter this expression into the &lt;b&gt;CONTROL SOURCE&lt;/b&gt; property of the &lt;br /&gt;txtHoursWorked text box (see screen shot below):&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDhJZbq6mtGwa63hx_nrg4r4wrETd3LTUOH5gTK5rSQNqmUpUSiVhOh7zxnaTrddatvm22d3wbmpxKJl1Zttj97Yf0waYBxHYP-WCBBFZwzX2gMsm4IWQwz5DQ8LmIZyfNQ3WecyhRUPY/s1600/control+source.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;306&quot; data-original-width=&quot;841&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDhJZbq6mtGwa63hx_nrg4r4wrETd3LTUOH5gTK5rSQNqmUpUSiVhOh7zxnaTrddatvm22d3wbmpxKJl1Zttj97Yf0waYBxHYP-WCBBFZwzX2gMsm4IWQwz5DQ8LmIZyfNQ3WecyhRUPY/s1600/control+source.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;The &lt;b&gt;txtHoursWorked&lt;/b&gt; text box is highlighted on the left, and the expression used as the &lt;b&gt;CONTROL SOURCE&lt;/b&gt; property value is highlighted on the right.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/5976442578474388390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/03/converting-minutes-to-hoursminutes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/5976442578474388390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/5976442578474388390'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/03/converting-minutes-to-hoursminutes.html' title='Converting Minutes to Hours:Minutes in MS Access'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6Ub8V9FMscGt6p6xwPhQAd_mY-Qw-pckOJAEpkKgXuoxqV_SlKiyENIyh6-3w08LhpuAdwh4hrt-xllGedwtUbc_pgXrmrOxf2A0kH9sZMPW5zczIVxzScVAUIQIlu3XQIwne1biSz4/s72-c/calculated+control+textbox.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-7775887145324973065</id><published>2019-02-15T14:49:00.000-08:00</published><updated>2019-02-15T14:49:39.682-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="one to many relationship"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Creating a Custom Save Button for an MS Access Form.</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
When we use an MS Access form to create a new record, or update one that already exists, the process of saving that data is normally taken care of automatically &quot;behind the scenes.&quot;&amp;nbsp; All we need to do is move to or create a new record, close the form, or close the database, and Access saves the original record for us.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuZi9mLLvZCT43vC6X87HZq3-7VqRneZFP8D1ss85a07Jns76USUdMpIEnJpCkkhuRNbm82pquXNC0BTR-Jk67GpE9wt0MoPK5b42NamtAd2yE_oe9YB-2sAyHIXcjkfedC-TeYjOKed0/s1600/navigation+control.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;31&quot; data-original-width=&quot;198&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuZi9mLLvZCT43vC6X87HZq3-7VqRneZFP8D1ss85a07Jns76USUdMpIEnJpCkkhuRNbm82pquXNC0BTR-Jk67GpE9wt0MoPK5b42NamtAd2yE_oe9YB-2sAyHIXcjkfedC-TeYjOKed0/s1600/navigation+control.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
&lt;b&gt;Record Navigation Buttons:&lt;/b&gt; when a record is added or changed, moving to a new or different record&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
via the navigation buttons, will save the origin form record automatically.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, there are times when it may necessary to &lt;i&gt;save a record manually&lt;/i&gt;.&amp;nbsp; Suppose, for example, we have two tables joined together in a &lt;a href=&quot;http://ms-access-tips.blogspot.com/2011/03/one-to-many-relationship.html&quot; target=&quot;_blank&quot;&gt;one to many relationship&lt;/a&gt;. We create a new record on a form bound to a table on the one side of the relationship, and then click a button to open a new form bound to a table on the&lt;i&gt; many&lt;/i&gt; side of the relationship.&amp;nbsp; The newly opened form is then used to create a sub-record for the parent record on the original form.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQy00PvjFeGUzfjA_g1QLUN2dyALC40cFevHK9R-YnEWLYg5ZntoOKlhmSOu1U_xl6XFgPydUuN5LKCWr9pacc-MiKedbd0Rz3ufx9cnljtlK_QMtJRluM6y42eQTQwTecHYcLJngirJ4/s1600/table+relationships.PNG&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: #0066cc; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-left: 1em; margin-right: 1em; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;340&quot; data-original-width=&quot;420&quot; height=&quot;259&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQy00PvjFeGUzfjA_g1QLUN2dyALC40cFevHK9R-YnEWLYg5ZntoOKlhmSOu1U_xl6XFgPydUuN5LKCWr9pacc-MiKedbd0Rz3ufx9cnljtlK_QMtJRluM6y42eQTQwTecHYcLJngirJ4/s320/table+relationships.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuO47XanI3yKQirpcHB3foYhMMK4qEaTGGQR6_MoxxOQYTi4XNRJ8Z5cSQj2g7aJ2n4vxzLsA8pK-ct1-Q9VYq7AVO-f-dzdMlvjRlkpIGQ_dfdwNFkrcAHa7M73em2gzOoKDN26dNENI/s1600/related+forms+2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;685&quot; data-original-width=&quot;1138&quot; height=&quot;385&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuO47XanI3yKQirpcHB3foYhMMK4qEaTGGQR6_MoxxOQYTi4XNRJ8Z5cSQj2g7aJ2n4vxzLsA8pK-ct1-Q9VYq7AVO-f-dzdMlvjRlkpIGQ_dfdwNFkrcAHa7M73em2gzOoKDN26dNENI/s640/related+forms+2.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Parent and sub-forms:&lt;/b&gt; In this screenshot, the parent form &quot;&lt;b&gt;Work Session&lt;/b&gt;&quot; is bound to the &lt;b&gt;tbl_work_session&lt;/b&gt; table, and the &quot;&lt;b&gt;Entry Log&lt;/b&gt;&quot; form is bound to the&lt;b&gt; tbl_entry_log&lt;/b&gt; table.&amp;nbsp; There is a one to many relationship between the two tables, with &lt;b&gt;tbl_work_session&lt;/b&gt; being on the one side of the relationship.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The problem in this scenario is that when we come to close the form for the sub-record (thereby saving the data to the underlying table on the&lt;i&gt; many&lt;/i&gt; side of the relationship), the parent record on the original form has not, at this stage, been inserted into the underlying table on the &lt;i&gt;one&lt;/i&gt; side of the relationship.&amp;nbsp; That is to say, Access has not got around to autosaving the parent record since the &lt;u&gt;parent form&lt;/u&gt; has not moved to any other record, or been closed etc - all we have done is click a command button to open a new form.&amp;nbsp; As such we get an error message saying &quot;&lt;i&gt;You cannot add or change a record because a related record is required in [the parent] table&lt;/i&gt;&quot;; this is because the rules of&lt;i&gt; referential integrity&lt;/i&gt; have been broken (ie the sub-record in the &lt;i&gt;many&lt;/i&gt; table requires a parent record in the &lt;i&gt;one&lt;/i&gt; table).&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, it is simple to overcome this issue. We just need to save the parent record manually before trying to close the sub-record form.&amp;nbsp; A quick and easy way to do this is to click the pencil symbol on the top left of the parent-form, or the &lt;b&gt;SAVE&lt;/b&gt; icon in the &lt;b&gt;RECORDS&lt;/b&gt; group of the &lt;b&gt;HOME&lt;/b&gt; ribbon. This will save the parent record, thereby allowing it&#39;s sub-record to be saved afterwards.&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4pOf-dphBt9zbhVGndHy0Z1sTHi9DAmdTSczS57FN8UlAkzBMURAd52C44P0QCk8L7IMmvv0EsjdsNpPhRNYzTuT55gU8PejKptNMlc0z3n52YUC8dajNITVDN4A-334BSeQ3cKaDPM/s1600/pencil+symbol.PNG&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; clear: left; color: #0066cc; float: left; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 16px; margin-right: 16px; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4pOf-dphBt9zbhVGndHy0Z1sTHi9DAmdTSczS57FN8UlAkzBMURAd52C44P0QCk8L7IMmvv0EsjdsNpPhRNYzTuT55gU8PejKptNMlc0z3n52YUC8dajNITVDN4A-334BSeQ3cKaDPM/s1600/pencil+symbol.PNG&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; clear: left; color: #0066cc; float: left; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 16px; margin-right: 16px; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;194&quot; data-original-width=&quot;235&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4pOf-dphBt9zbhVGndHy0Z1sTHi9DAmdTSczS57FN8UlAkzBMURAd52C44P0QCk8L7IMmvv0EsjdsNpPhRNYzTuT55gU8PejKptNMlc0z3n52YUC8dajNITVDN4A-334BSeQ3cKaDPM/s1600/pencil+symbol.PNG&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz1a993LSgkuOr554GijaeZGpH7CS5sGUsCFjkA0j-7VvyNwBYKOZ_zonLH8iMSv171S8sl7zZ41UtIAnz5kPqijWCnFSCqfhi7t0605ZFRLXBCbScXQFXgv6U3fnvLIVeG-JBj8gWbBQ/s1600/save+icon.PNG&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: #0066cc; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-left: auto; margin-right: auto; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;88&quot; data-original-width=&quot;102&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiz1a993LSgkuOr554GijaeZGpH7CS5sGUsCFjkA0j-7VvyNwBYKOZ_zonLH8iMSv171S8sl7zZ41UtIAnz5kPqijWCnFSCqfhi7t0605ZFRLXBCbScXQFXgv6U3fnvLIVeG-JBj8gWbBQ/s200/save+icon.PNG&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4pOf-dphBt9zbhVGndHy0Z1sTHi9DAmdTSczS57FN8UlAkzBMURAd52C44P0QCk8L7IMmvv0EsjdsNpPhRNYzTuT55gU8PejKptNMlc0z3n52YUC8dajNITVDN4A-334BSeQ3cKaDPM/s1600/pencil+symbol.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR4pOf-dphBt9zbhVGndHy0Z1sTHi9DAmdTSczS57FN8UlAkzBMURAd52C44P0QCk8L7IMmvv0EsjdsNpPhRNYzTuT55gU8PejKptNMlc0z3n52YUC8dajNITVDN4A-334BSeQ3cKaDPM/s1600/pencil+symbol.PNG&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; clear: left; color: #0066cc; float: left; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 16px; margin-right: 16px; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&amp;nbsp;The &lt;b&gt;pencil&lt;/b&gt; symbol (above left) can be used to save the current record manually.&amp;nbsp; Alternatively, the&lt;b&gt; SAVE&lt;/b&gt; icon in the&amp;nbsp;&lt;b&gt;RECORDS&lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt; group&lt;/span&gt; of the &lt;b&gt;HOME &lt;/b&gt;ribbon (above right) can also be used.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, this is not particularly useful from the perspective of user-friendliness. That is to say, a user may not realise or understand that this action is necessary.&amp;nbsp; A better way of doing it would be to save the parent record automatically when the user clicks the command button to open the sub record form. As such, we need to alter the &lt;i&gt;open form button&lt;/i&gt; (referred to as &quot;CREATE NEW ENTRY&quot; in our example above) so it also becomes a &lt;i&gt;custom save button&lt;/i&gt;.&amp;nbsp; To do this, we just add the following line of VBA code to the buttons &lt;b&gt;ON CLICK &lt;/b&gt;event:&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Application.RunCommand acCmdSaveRecord&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;See the screenshot below for the full code:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhXdRRN6BaEdDjp1Bep1y-HzghGug12TE7ibDbQLph10fgZWcpGZZYaeWWcdlpE3Da7zVO6PoWK_ecaaW0meMfVReyRBIwFeBQmSzvjYOq48soEsD12Ov09QMD56Svo-ebyY6GVEpjXUw/s1600/vba.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;264&quot; data-original-width=&quot;638&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhXdRRN6BaEdDjp1Bep1y-HzghGug12TE7ibDbQLph10fgZWcpGZZYaeWWcdlpE3Da7zVO6PoWK_ecaaW0meMfVReyRBIwFeBQmSzvjYOq48soEsD12Ov09QMD56Svo-ebyY6GVEpjXUw/s1600/vba.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;VBA&lt;/b&gt; code to save the parent record &lt;i&gt;before&lt;/i&gt; opening the sub-record form.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Creating a Custom Save Button from Scratch - A Tutorial&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here is a step by step tutorial for creating a&lt;i&gt; custom save button&lt;/i&gt; from scratch on &lt;i&gt;Access for Office 365&lt;/i&gt;:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Open the form in DESIGN VIEW. &lt;/li&gt;
&lt;li&gt;Go to the CONTROLS group of the CREATE ribbon. &lt;/li&gt;
&lt;li&gt;Click the MORE button (&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb4d72EB7yhqbopjmniMrS5GNO-yF9Zkd7Hn5N6BKz51sfWC6o-d9_JTXTHegp6zTb0MsDQeajeezOljnK7OrYe2D76WoeAQPJtznXk_fOneZtUN8ZgwYOAOO9IkYcW4UjGVE0FRnTT54/s1600/more.PNG&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb4d72EB7yhqbopjmniMrS5GNO-yF9Zkd7Hn5N6BKz51sfWC6o-d9_JTXTHegp6zTb0MsDQeajeezOljnK7OrYe2D76WoeAQPJtznXk_fOneZtUN8ZgwYOAOO9IkYcW4UjGVE0FRnTT54/s1600/more.PNG&quot; /&gt;&lt;/a&gt;) to the lower right of the control icons, and de-select the USE CONTROL WIZARDS icon when the additional options appear.&amp;nbsp;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjliD3i155hUNCn4YWZ3rAq01ZA4tMlVueapd-ZSpV5ja7eHxxN5EfLOw4V9qb4j7OcI89R6XVMz1dCEpC0SulkoeOTE5rKNNb2LFgmUlAQtrg1pG46czKWkNJizGg-vtBMsPrBR7btGiA/s1600/control+wizards.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;91&quot; data-original-width=&quot;172&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjliD3i155hUNCn4YWZ3rAq01ZA4tMlVueapd-ZSpV5ja7eHxxN5EfLOw4V9qb4j7OcI89R6XVMz1dCEpC0SulkoeOTE5rKNNb2LFgmUlAQtrg1pG46czKWkNJizGg-vtBMsPrBR7btGiA/s1600/control+wizards.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: additonal&amp;nbsp; options below control icons.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;Click the BUTTON control icon (&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVHGvASMWoJqc73UWy78iNJ8pxNc8nmHazDOHuVucuUrZxoAwchY5wtm4Awjqx4q5JUnxWLL36-zRqnBAbBbNQfQHBZuATL87qLNODjyCJgqkuDAyw_1HYgxeYsVy9LAWnrNazowUgh2w/s1600/button+icon.PNG&quot; imageanchor=&quot;1&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: #0066cc; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-left: 16px; margin-right: 16px; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;34&quot; data-original-width=&quot;48&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVHGvASMWoJqc73UWy78iNJ8pxNc8nmHazDOHuVucuUrZxoAwchY5wtm4Awjqx4q5JUnxWLL36-zRqnBAbBbNQfQHBZuATL87qLNODjyCJgqkuDAyw_1HYgxeYsVy9LAWnrNazowUgh2w/s1600/button+icon.PNG&quot; style=&quot;cursor: move;&quot; /&gt;&lt;/a&gt;) from the CONTROLS ribbon. The cursor will now change to a &lt;i&gt;button&lt;/i&gt; icon when it enters the design grid.&lt;/li&gt;
&lt;li&gt;Position the cursor at the desired location on the design grid, and click the left hand mouse button.&amp;nbsp; This will create the new button at the selected location.&lt;/li&gt;
&lt;li&gt;Select the new &lt;b&gt;BUTTON&lt;/b&gt; contol by left clicking it, and open the &lt;b&gt;PROPERTIES&lt;/b&gt; sheet from the &lt;b&gt;TOOLS&lt;/b&gt; group of the &lt;b&gt;DESIGN&lt;/b&gt; ribbon (if it is not already open).&lt;/li&gt;
&lt;li&gt;Click the &lt;b&gt;EVENTS&lt;/b&gt; tab on the properties sheet, and left click the &lt;b&gt;ON CLICK&lt;/b&gt; row of the events tab.&lt;/li&gt;
&lt;li&gt;Click the &lt;b&gt;ELIPSE&lt;/b&gt; button (three horizontal dots) which appears on the right hand side of the row.&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWs-j_CJ3eZfgTDjZBlwjsb5cD9koXcjaQOgTVa7FvsVWdnXh2TpEXFcBTzDkcFlpCn-je9CrJm-Oxyr2iWyMHC50n7mXQYXRIbuxulo3QgXVwQ9e36VFUUFrx5Q10OgsudCX0x42Y7AE/s1600/on+click+property.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;79&quot; data-original-width=&quot;358&quot; height=&quot;70&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWs-j_CJ3eZfgTDjZBlwjsb5cD9koXcjaQOgTVa7FvsVWdnXh2TpEXFcBTzDkcFlpCn-je9CrJm-Oxyr2iWyMHC50n7mXQYXRIbuxulo3QgXVwQ9e36VFUUFrx5Q10OgsudCX0x42Y7AE/s320/on+click+property.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; the &lt;b&gt;ON CLICK&lt;/b&gt; event row on the PROPERTIES sheet.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;/b&gt;Select&lt;b&gt; CODE BUILDER&lt;/b&gt; from the &lt;b&gt;CHOOSE BUILDER&lt;/b&gt; dialog form which opens.&amp;nbsp; This opens the VBA editor.&lt;/li&gt;
&lt;li&gt;Enter the following code in the CLICK sub procedure for the control button.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPC-rUyPTdZjLL8HMtZc3H-VkG-MYmvYWDVLmVDIO9CZzZtwtV83PAGc6gKj2SEEY5IbYT1Yv9v90m5azhhm7fS_CmT0AIVScLT3_k7UoJgukvBPg4JH-zJTTLn5VygEZdCRO8-yFbQ7g/s1600/save+record+command.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;109&quot; data-original-width=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPC-rUyPTdZjLL8HMtZc3H-VkG-MYmvYWDVLmVDIO9CZzZtwtV83PAGc6gKj2SEEY5IbYT1Yv9v90m5azhhm7fS_CmT0AIVScLT3_k7UoJgukvBPg4JH-zJTTLn5VygEZdCRO8-yFbQ7g/s1600/save+record+command.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: The &lt;b&gt;CLICK&lt;/b&gt; sub procedure for the new control button shown in the &lt;b&gt;VBA&lt;/b&gt; editor.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now when the user clicks the new button at runtime, any data s/he entered will be saved to the corresponding record in the forms underlying table.&lt;/div&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: right; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZJCfCcFcHP8a0EmOYsWSDY08yibQkx7paXrYQOeZ2c73Kva7GKCIeApWqIH9sAzdOX34R1B68TcCDi-cSVLekkE1J7lEo7p4pTl2B07rQInKY_eGUNrdEe-LaJXXGfoi-MHtBcEdsWLw/s1600/control+wizards.PNG&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; clear: left; color: #0066cc; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 16px; margin-left: auto; margin-right: auto; orphans: 2; text-align: center; text-decoration: underline; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/7775887145324973065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/02/creating-custom-save-button.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/7775887145324973065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/7775887145324973065'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/02/creating-custom-save-button.html' title='Creating a Custom Save Button for an MS Access Form.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuZi9mLLvZCT43vC6X87HZq3-7VqRneZFP8D1ss85a07Jns76USUdMpIEnJpCkkhuRNbm82pquXNC0BTR-Jk67GpE9wt0MoPK5b42NamtAd2yE_oe9YB-2sAyHIXcjkfedC-TeYjOKed0/s72-c/navigation+control.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-6783191277758936306</id><published>2019-01-25T14:28:00.001-08:00</published><updated>2019-01-25T14:28:25.862-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="If Then Else"/><category scheme="http://www.blogger.com/atom/ns#" term="Loops"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Passing Multiple Values via the OpenArgs Parameter of DoCmd.OpenForm</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;The &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;b&gt;DoCmd.OpenForm&lt;/b&gt; command is a useful tool for the &lt;i&gt;Access for Office 365&lt;/i&gt; database developer wanting to control the manner in which a form opens during runtime.&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;I have written about it previously in my post on how to &quot;&lt;a href=&quot;http://ms-access-tips.blogspot.com/2012/02/control-form-opening-datamode-openargs.html&quot; target=&quot;_blank&quot;&gt;&lt;span id=&quot;goog_912767475&quot;&gt;&lt;/span&gt;Control Form Opening&lt;span id=&quot;goog_912767476&quot;&gt;&lt;/span&gt;&lt;/a&gt;&quot;.&amp;nbsp; However, in today&#39;s post, we are going to focus on a specific area of this command&#39;s use - that is, how we can pass multiple values via its &lt;/span&gt;&lt;b style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;OpenArgs&lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt; property.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;&lt;u&gt;&lt;/u&gt;&lt;sub&gt;&lt;/sub&gt;&lt;sup&gt;&lt;/sup&gt;&lt;strike&gt;&lt;/strike&gt;&lt;/div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnZTVOMl-c3keUZouxfX5zsydt3LzR6iIYsSZshGI1jFy4xVwzgaM-C9UzqrNmYkvaIZHUNB8kL3AfVeFlIym14or4jmSMZecUBScGHWHqB8zOhTpd3wFFblGGMEB1_aKuB1_vM-EHjok/s1600/open-args1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;77&quot; data-original-width=&quot;805&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnZTVOMl-c3keUZouxfX5zsydt3LzR6iIYsSZshGI1jFy4xVwzgaM-C9UzqrNmYkvaIZHUNB8kL3AfVeFlIym14or4jmSMZecUBScGHWHqB8zOhTpd3wFFblGGMEB1_aKuB1_vM-EHjok/s1600/open-args1.PNG&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The &lt;b&gt;OpenArgs&lt;/b&gt; parameter of &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; gives us the means to pass a single string value to the &lt;b&gt;OpenArgs&lt;/b&gt; property of new form being opened.&amp;nbsp; After the form has opened, this value can then be read and used by any code able to reference the new forms &lt;b&gt;OpenArgs&lt;/b&gt; property. As things stand, the limitation of this is that we can only pass one string value as the command executes.&amp;nbsp; So let&#39;s see how we can get around this, and pass any number of strings values in one go.&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To demonstrate how this works, I have created an&amp;nbsp;&lt;i&gt;Access for Office 365 &lt;/i&gt;form containing three text boxes and a submit button.&amp;nbsp; When the user populates the text boxes and clicks &lt;b&gt;SUBMIT &lt;/b&gt;during runtime, the values contained in each of the three text boxes are passed over to a new form by means of the &lt;b&gt;OpenArgs&lt;/b&gt; parameter of the &lt;b&gt;DoCmd&lt;/b&gt;.&lt;b&gt;OpenForm&lt;/b&gt; command.&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB6wxtsYz1HPfk_eMvGs_PstCk1zDqEc6AiJU5KL-WL9tfQwjLT5YOGXNvgTyNhHBsCb8otiI5fxIKTunS_NsYkdTqdaTMgC-DLF4wYb8ivb1iFhzBp3EkJpGSNaPSpjmObjC8ONB1uGI/s1600/Send+OpenArgs.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;423&quot; data-original-width=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB6wxtsYz1HPfk_eMvGs_PstCk1zDqEc6AiJU5KL-WL9tfQwjLT5YOGXNvgTyNhHBsCb8otiI5fxIKTunS_NsYkdTqdaTMgC-DLF4wYb8ivb1iFhzBp3EkJpGSNaPSpjmObjC8ONB1uGI/s1600/Send+OpenArgs.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; Form to pass multiple values via the &lt;b&gt;OpenArgs&lt;/b&gt; parameter of &lt;b&gt;DoCmd.OpenForm&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;You can download the full &lt;a href=&quot;http://www.dealing-with-data.net/exercises/OpenArgsPost.accdb&quot;&gt;OpenArgsPost.accdb&lt;/a&gt; database used in the this exercise from here.&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
(NB I have tested the download process using the &lt;b&gt;Chrome&lt;/b&gt; browser which works OK.&amp;nbsp; The download process may fail using other browsers such as&lt;b&gt; Microsoft Edge&lt;/b&gt;. If you experience issues please try using a different browser).&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt; &lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Part One: Passing the Values&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;/span&gt;Let&#39;s look at what happens behind the scenes when the&lt;b&gt; SUBMIT&lt;/b&gt; button is clicked.&amp;nbsp; First of all, clicking &lt;b&gt;SUBMIT &lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;(referred to as &lt;/span&gt;&lt;b style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;btnSubmit &lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;in DESIGN VIEW)&lt;/span&gt; results in the control button&#39;s &lt;b&gt;ON CLICK&lt;/b&gt; event firing.&amp;nbsp; This, in turn, starts the following VBA event procedure (see screenshot below):&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2Xhi21XkfXx16sF3xwDd39EbxgwT1RFWhApwBWO12qhTcbdNccF3k5PN01i9uvJ8Bw12vQtJohiQ5yIwiEg4_rHAcCnlS0RHwSRBHgL4uDWhGk2GxeHrJF0prTewnAPQjIJ1rQT3ob9U/s1600/submit-button-code.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;401&quot; data-original-width=&quot;540&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2Xhi21XkfXx16sF3xwDd39EbxgwT1RFWhApwBWO12qhTcbdNccF3k5PN01i9uvJ8Bw12vQtJohiQ5yIwiEg4_rHAcCnlS0RHwSRBHgL4uDWhGk2GxeHrJF0prTewnAPQjIJ1rQT3ob9U/s1600/submit-button-code.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: The VBA event procedure for &lt;b&gt;btnSubmit&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
The code begins by declaring a string variable called &lt;b&gt;strOpenArgs&lt;/b&gt;:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/span&gt; &lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Dim strOpenArgs AS String&lt;/span&gt; &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The next two lines of code reference the value entered by the user in the first text box.&amp;nbsp; The value is stored in the &lt;b&gt;strOpenArgs&lt;/b&gt; string:&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;txtValue1.SetFocus&lt;br /&gt;strOpenArgs = txtValue1.Text&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The next two lines of code after that reference the value of the second text box, and append it to the &lt;b&gt;strOpenArgs&lt;/b&gt; string &lt;u&gt;preceded by a semi-colon&lt;/u&gt; (the significance of the semi-colon will be explained in&lt;b&gt; part 3&lt;/b&gt; of this post):&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;txtValue2.SetFocus&lt;br /&gt;strOpenArgs = strOpenArgs + &quot;;&quot; + txtValue2.Text&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
This is then repeated for the third text box:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;txtValue3.SetFocus&lt;br /&gt;strOpenArgs = strOpenArgs + &quot;;&quot; + txtValue3.Text&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
So at this point in the program flow, the value of &lt;b&gt;strOpenArgs&lt;/b&gt; is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&quot;one;two;three&quot;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is the final value of the &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; &lt;i&gt;OpenArgs&lt;/i&gt; parameter which will be passed to the new form in the following line of code:&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;DoCmd.OpenForm &quot;frmReceiveOpenArgs&quot;, , , , , , strOpenArgs&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Part Two: Retrieving the Values&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt; Let&#39;s take a look at the new form which opens after the &lt;b&gt;SUBMIT&lt;/b&gt; button has been clicked, and the event procedure explained above has finished executing:&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjle-rp8p1FiMQi8bxXlSYErXPOMUoMDvPgHsxl62iGy7O2nU705mZgqh0uUwN5HFnA-cB9yQqsP-IAgKkD4n70n35AeGhgwAsoEv25MvkiGq8MNV2E_bdIdub7EtUKZ-HVxv7Vl9zHaz8/s1600/retrieval+form.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;358&quot; data-original-width=&quot;487&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjle-rp8p1FiMQi8bxXlSYErXPOMUoMDvPgHsxl62iGy7O2nU705mZgqh0uUwN5HFnA-cB9yQqsP-IAgKkD4n70n35AeGhgwAsoEv25MvkiGq8MNV2E_bdIdub7EtUKZ-HVxv7Vl9zHaz8/s1600/retrieval+form.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;: the new form which opens in response to clicking the &lt;/span&gt;&lt;b style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; font-family: Times New Roman; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; padding-top: 0px; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;SUBMIT&lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt; button.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As you can see in the screenshot above, the new form consists of three empty text boxes (for displaying retrieved values) and a &lt;b&gt;RETRIEVE &lt;/b&gt;button.&amp;nbsp; When the user clicks &lt;b&gt;RETRIEVE &lt;/b&gt;the text boxes will be populated with the values submitted from the first form.&amp;nbsp; In our case, &lt;i&gt;Retrieved Value 1&lt;/i&gt; will display the value &quot;&lt;b&gt;one&lt;/b&gt;&quot;, &lt;i&gt;Retrieved Value 2 &lt;/i&gt;will display the value &quot;&lt;b&gt;two&lt;/b&gt;&quot;, and &lt;i&gt;Retrieved Value 3 &lt;/i&gt;will display the value &quot;&lt;b&gt;three&lt;/b&gt;&quot;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s look at what happens behind the scenes after the &lt;b&gt;RETRIEVE&lt;/b&gt; button is clicked.&amp;nbsp; Like the first form, clicking the command button, which in this form is called &lt;b&gt;btnRetrieve&lt;/b&gt;, results in it&#39;s ON CLICK event firing.&amp;nbsp; This starts the following VBA event procedure (see screenshot below):&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHgxDeLbANqrmXXVYTRlUwdn2mUc1dQJpEwQvL2IJO6cOcaQgxDecms1FhqSwIJkckOlGwu7SDvggVd5Hn6n59Nc9trwIh3f002cbnU2dfgm0IVdSxAp0EFftqE0h6nOBPzw3mkw3SE8Y/s1600/retrieve+event+procedure.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;443&quot; data-original-width=&quot;510&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHgxDeLbANqrmXXVYTRlUwdn2mUc1dQJpEwQvL2IJO6cOcaQgxDecms1FhqSwIJkckOlGwu7SDvggVd5Hn6n59Nc9trwIh3f002cbnU2dfgm0IVdSxAp0EFftqE0h6nOBPzw3mkw3SE8Y/s1600/retrieve+event+procedure.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt; The VBA event procedure for &lt;/span&gt;&lt;b style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; font-family: Times New Roman; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 700; letter-spacing: normal; orphans: 2; padding-top: 0px; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;btnRetrieve&lt;/b&gt;&lt;span style=&quot;background-color: transparent; color: black; display: inline; float: none; font-family: &amp;quot;times new roman&amp;quot;; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; text-align: center; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The code begins by declaring a string variable called &lt;b&gt;strOpenArgs &lt;/b&gt;before referencing the forms &lt;b&gt;OpenArgs&lt;/b&gt; property and storing its value in the string.&amp;nbsp; (Just to recap, the value of the &lt;b&gt;OpenArgs&lt;/b&gt; property (ie &quot;&lt;b&gt;one;two;three&lt;/b&gt;&quot;) was determined by the &lt;b&gt;OpenArgs&lt;/b&gt; parameter of the&amp;nbsp; &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; command invoked when the user clicked the &lt;b&gt;SUBMIT&lt;/b&gt; button on the previous form):&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;dim strOpenArgs As String&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;strOpenArgs = Me.OpenArgs&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt; The next couple of lines of code are very important. A string array called &lt;b&gt;strValues&lt;/b&gt; is declared and has its elements populated with data returned from a function called &lt;b&gt;getOpenArgsArray&lt;/b&gt;.&amp;nbsp; This function is located in a separate module called &lt;b&gt;Utilities&lt;/b&gt; which is &lt;a href=&quot;http://ms-access-tips.blogspot.com/2012/06/vba-project-anatomy-and-scope.html&quot; target=&quot;_blank&quot;&gt;global in scope&lt;/a&gt;.&amp;nbsp; This is where the core of the processing is done for this exercise:&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Dim strValues() As String&lt;br /&gt;strValues = getOpenArgsArray(strOpenArgs)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The purpose of the &lt;b&gt;getOpenArgsArray&lt;/b&gt; is to split the value of its parameter, &lt;b&gt;strOpenArgs &lt;/b&gt;(which in our case is &quot;&lt;b&gt;one;two;three&lt;/b&gt;&quot;), into three separate strings, with each array element containing an individual string.&amp;nbsp; So for us, the &lt;b&gt;strValues&lt;/b&gt; array is populated with the following values:&lt;/div&gt;
&lt;br /&gt;
&lt;table style=&quot;border: 1px solid black;&quot;&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;th style=&quot;border: 1px solid black;&quot;&gt;Array Element&lt;/th&gt;&lt;th style=&quot;border: 1px solid black;&quot;&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border: 1px solid black;&quot;&gt;strValues(0)&lt;/td&gt;&lt;td style=&quot;border: 1px solid black;&quot;&gt;&quot;one&quot;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border: 1px solid black;&quot;&gt;strValues(1)&lt;/td&gt;&lt;td style=&quot;border: 1px solid black;&quot;&gt;&quot;two&quot;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border: 1px solid black;&quot;&gt;strValues(2)&lt;/td&gt;&lt;td style=&quot;border: 1px solid black;&quot;&gt;&quot;three&quot;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
These values are assigned to each of the three text boxes in the next six lines of code:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Me!txtRetValue1.SetFocus&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Me!txtRetValue1.Text = strValues(0)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Me!txtRetValue2.SetFocus&lt;br /&gt;Me!txtRetValue2.Text = strValues(1)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Me!txtRetValue3.SetFocus&lt;br /&gt;Me!txtRetValue3.Text = strValues(2)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The end result can be seen in the screenshot below:&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYiqdhCqTR9X2K339BBPwgGtrnaJRsOE_HYh49MqK402unklPtl4azN06qWBiuyRMJNfwP0SyAQ0Enpow0FwKff5kA1z-cWKakj1L4AYPc3L9EV7gjRKS6oqlkqqgO5TxunhtDhii2kDc/s1600/end+result.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;356&quot; data-original-width=&quot;487&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYiqdhCqTR9X2K339BBPwgGtrnaJRsOE_HYh49MqK402unklPtl4azN06qWBiuyRMJNfwP0SyAQ0Enpow0FwKff5kA1z-cWKakj1L4AYPc3L9EV7gjRKS6oqlkqqgO5TxunhtDhii2kDc/s1600/end+result.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: the end result after the user clicks &lt;b&gt;RETRIEVE&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In this way, we have used the &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; &lt;i&gt;OpenArgs&lt;/i&gt; parameter to pass multiple values to a new form, thereby overcoming the limitation of only being able to pass a single string within the statement.&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;hr /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;Part Three: The &lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;i&gt;getOpenArgsArray&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt; Function&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, this post would not be complete without an explanation of the &lt;b&gt;getOpenArgsArray&lt;/b&gt; function, as this is where the core of the processing was done for this exercise.&amp;nbsp; Let&#39;s take a look at the code used in the &lt;b&gt;getOpenArgsArray &lt;/b&gt;function:&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4pLBAMFiKMsPH9lXjxVTbXQVdxBZPEFpXQ9EljrssUM3wcXPN7n3VSZS9evb6SP6qP0jz16Fj3lo5Y5SzlTzRk7S-wtNGXhaS94ZN7vbqgqCVW7uOg_D3Fn03rHVYf9Kd7U9ob41D9KU/s1600/getOpenArgsArray+Code.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;645&quot; data-original-width=&quot;592&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4pLBAMFiKMsPH9lXjxVTbXQVdxBZPEFpXQ9EljrssUM3wcXPN7n3VSZS9evb6SP6qP0jz16Fj3lo5Y5SzlTzRk7S-wtNGXhaS94ZN7vbqgqCVW7uOg_D3Fn03rHVYf9Kd7U9ob41D9KU/s1600/getOpenArgsArray+Code.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above:&lt;/b&gt; code for the &lt;b&gt;getOpenArgsArray&lt;/b&gt; function.&lt;br /&gt;
&lt;b&gt;NB:&lt;/b&gt; in this screenshot the &lt;b&gt;strArgs&lt;/b&gt; array is declared with 7 elements.&lt;br /&gt;
This is because the function is global in scope and other event procedures using&lt;br /&gt;
&amp;nbsp;the function may need addtional elements.&amp;nbsp; This means that the &lt;b&gt;OpenArgs&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;parameter of &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; can pass up to 7 values with this current setup. &lt;br /&gt;
If more elements are needed, the array can be declared with an adjusted number as necessary.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As mentioned in section 2 above, the purpose of the &lt;b&gt;getOpenArgsArray&lt;/b&gt; function is to split the value of the &lt;b&gt;strOpenArgs&lt;/b&gt; parameter passed to the function, into individual sections, and to save each section as a separate array element. So in our case, the function receives a string containing the value &quot;&lt;b&gt;one;two;three&lt;/b&gt;&quot;, and returns an array with three elements ie&amp;nbsp;&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px; color: black; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;th style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Array Element &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;/th&gt;&lt;th style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;nbsp;Value &amp;nbsp;&lt;/div&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Element 1&amp;nbsp;&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;nbsp;&quot;one&quot;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; display: inline !important; float: none; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;Element 2&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;nbsp;&quot;two&quot;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
Element 3&lt;/div&gt;
&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgb(0, 0, 0); border-bottom-style: solid; border-bottom-width: 1px; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-left-color: rgb(0, 0, 0); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(0, 0, 0); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(0, 0, 0); border-top-style: solid; border-top-width: 1px;&quot;&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;
&amp;nbsp;&quot;three&quot;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is acheived by iterating through the &lt;b&gt;strOpenArgs&lt;/b&gt; string in a FOR NEXT loop and appending each individual character to a temporary string called &lt;b&gt;strBuildString&lt;/b&gt;.&amp;nbsp; Then when the current character of &lt;b&gt;strOpenArgs&lt;/b&gt; in the loop is one of the semi-colons, the value of &lt;b&gt;strBuildString&lt;/b&gt; is saved to a new array element.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets break this down further.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The following three lines of code are concerned with iterating through each&amp;nbsp; character contained in the &lt;b&gt;strOpenArgs &lt;/b&gt;string.&amp;nbsp; Each character is temporarily stored in a string variable called&lt;b&gt; strChr&lt;/b&gt;:&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;For i = 1 To Len(strOpenArgs)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; Dim strChr As String&lt;br /&gt;&amp;nbsp; &amp;nbsp; strChr = Mid(strOpenArgs, i, 1)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The value of &lt;b&gt;strChr&lt;/b&gt; is then checked to see whether or not it is a semi-colon.&amp;nbsp; If it is NOT a semi-colon, the character is appended to the &lt;b&gt;strBuildString&lt;/b&gt; variable :&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; If Not strChr = &quot;;&quot; Then&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;strBuildString = strBuildString + strChr&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;If, on the other hand, the character&lt;i&gt; IS&lt;/i&gt; a semi-colon, the current value of &lt;b&gt;strBuildString&lt;/b&gt; is saved as a&amp;nbsp; new array element in &lt;b&gt;strArgs()&lt;/b&gt;.&amp;nbsp; The &lt;b&gt;strBuildString&lt;/b&gt; variable is then cleared ready to build the value of the next array element:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;i&gt;&lt;/i&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Else &amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; strArgs(argCounter) = strBuildString&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; strBuildString = &quot;&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The element number of the array is kept track of in an integer variable called &lt;b&gt;argCounter&lt;/b&gt;.&amp;nbsp; This is incremented by one after the &lt;b&gt;strBuildString&lt;/b&gt; variable is cleared:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; argCounter = argCounter + 1&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Next i&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;After the last iteration of &lt;b&gt;strOpenArgs&lt;/b&gt; has completed, the final array element is saved, and the return value of the &lt;b&gt;getOpenArgsArray&lt;/b&gt; function is set to the value of the &lt;b&gt;strArgs()&lt;/b&gt; array:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;strArgs(argCounter) = strBuildString&lt;br /&gt;getOpenArgsArray = strArgs&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Exit Function&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/6783191277758936306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/01/passing-multiple-values-via-openargs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6783191277758936306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6783191277758936306'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/01/passing-multiple-values-via-openargs.html' title='Passing Multiple Values via the OpenArgs Parameter of DoCmd.OpenForm'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnZTVOMl-c3keUZouxfX5zsydt3LzR6iIYsSZshGI1jFy4xVwzgaM-C9UzqrNmYkvaIZHUNB8kL3AfVeFlIym14or4jmSMZecUBScGHWHqB8zOhTpd3wFFblGGMEB1_aKuB1_vM-EHjok/s72-c/open-args1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4681244980991832307</id><published>2019-01-04T04:04:00.002-08:00</published><updated>2019-01-04T16:43:14.855-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Controls"/><category scheme="http://www.blogger.com/atom/ns#" term="design"/><category scheme="http://www.blogger.com/atom/ns#" term="formatting"/><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="properties"/><category scheme="http://www.blogger.com/atom/ns#" term="text box"/><title type='text'>Changing &quot;Entry Key Behaviour&quot; to Allow New Lines within a Textbox</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
In my previous blog post, I wrote about &lt;a href=&quot;http://ms-access-tips.blogspot.com/2018/12/adding-rich-text-formatting-to-access.html&quot; target=&quot;_blank&quot;&gt;Adding Rich Text Formatting to MS Access Data&lt;/a&gt;.&amp;nbsp; However, there was one related topic which I didn&#39;t cover - ie how to change the entry key behaviour to &lt;i&gt;allow new lines within a text box&lt;/i&gt;.&amp;nbsp; This is done by changing the&lt;b&gt; ENTRY KEY BEHAVIOR&lt;/b&gt; property of the text box in question.&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;-webkit-text-stroke-width: 0px; background-color: transparent; color: black; float: right; font-family: Times New Roman; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; margin-bottom: 8px; orphans: 2; padding: 6px; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;&quot;&gt;&lt;tbody style=&quot;margin-bottom: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;tr style=&quot;margin-bottom: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhEvnW6PM_Jt6yYlyh3KRF-cx0tkgKWrp6YtNf3E9y_zyQ5RP4Ge1p3YHCkJCFKXL101u9aoHmNQSfLGtVdrEBjg1lnAuzt4878uWkyELpjp6OQC1W59o9FAyPsFm_tDX6zGkhj5_NiJ4/s1600/entry+key+behavior+property.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; margin-bottom: 16px; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;416&quot; data-original-width=&quot;367&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhEvnW6PM_Jt6yYlyh3KRF-cx0tkgKWrp6YtNf3E9y_zyQ5RP4Ge1p3YHCkJCFKXL101u9aoHmNQSfLGtVdrEBjg1lnAuzt4878uWkyELpjp6OQC1W59o9FAyPsFm_tDX6zGkhj5_NiJ4/s320/entry+key+behavior+property.PNG&quot; width=&quot;280&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;margin-bottom: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px; padding-top: 4px; text-align: center;&quot;&gt;&lt;div style=&quot;font-size: 12.8px; padding-top: 0px;&quot;&gt;
The&lt;b style=&quot;font-size: 12.8px; padding-top: 0px;&quot;&gt; ENTRY KEY BEHAVIOR&lt;/b&gt; property set to&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;font-size: 12.8px; padding-top: 0px;&quot;&gt;
&lt;b style=&quot;font-size: 12.8px; padding-top: 0px;&quot;&gt;NEW LINE IN FIELD &lt;/b&gt;for the &lt;i style=&quot;font-size: 12.8px; padding-top: 0px;&quot;&gt;txtDescription&lt;/i&gt; text box.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Let&#39;s imagine we have a text box on a form in which we are going enter a large amount of text data separated by paragraphs. We have set the field in the underlying table to accept LONG TEXT data, and perhaps also enabled rich text formatting.&amp;nbsp; The first thing we do is resize the text box in FORM DESIGN view by selecting the text box and dragging the lower right corner so it is large enough to display a good area of text without having to constantly scroll down.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If we left the&lt;b&gt; ENTRY KEY BEHAVIOR&lt;/b&gt; property at its default setting, it would not be possible for a user to create a new paragraph within the text box whenever they hit the &lt;b&gt;ENTER&lt;/b&gt; key.&amp;nbsp; What we need to do, therefore, is change the property value from&lt;b&gt; DEFAULT&lt;/b&gt; to&lt;b&gt; NEW LINE IN FIELD&lt;/b&gt;. This is how:&lt;/div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Open the form in DESIGN VIEW.&lt;/li&gt;
&lt;li&gt;Select the text box control to be modified by clicking it.&lt;/li&gt;
&lt;li&gt;Open the&lt;b&gt; PROPERTY SHEET&lt;/b&gt; by clicking the icon in the&lt;b&gt; TOOLS&lt;/b&gt; group of the &lt;b&gt;DESIGN&lt;/b&gt; ribbon (if it&#39;s not already open).&lt;/li&gt;
&lt;li&gt;Click the&lt;b&gt; OTHER&lt;/b&gt; tab on the property sheet.&lt;/li&gt;
&lt;li&gt;Locate the&lt;b&gt; ENTRY KEY BEHAVIOR&lt;/b&gt; property and change the value to&lt;b&gt; NEW LINE IN FIELD&lt;/b&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
Once the property has been changed, the user can enter text in the text box and use the &lt;b&gt;ENTER&lt;/b&gt; key to create a new paragraph without the focus shifting to the next control in the tab order.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPhMCR3CdknwwCNPRakfpWVHcLl6y-E2oECMyIQVVLGh4qfxFm8__lT0vxLfk3hop7FaTVcGFCcG0wnTq_NWuDQ9OsFPthb2B0s9V_c37DdyZMkMd5SJylibZOsj2btE-8o1ChZpEfXhM/s1600/Entry+Key+Behavior.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;396&quot; data-original-width=&quot;795&quot; height=&quot;316&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPhMCR3CdknwwCNPRakfpWVHcLl6y-E2oECMyIQVVLGh4qfxFm8__lT0vxLfk3hop7FaTVcGFCcG0wnTq_NWuDQ9OsFPthb2B0s9V_c37DdyZMkMd5SJylibZOsj2btE-8o1ChZpEfXhM/s640/Entry+Key+Behavior.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div&gt;
Above: Example of a text box with the &lt;b&gt;ENTRY KEY BEHAVIOR&lt;/b&gt; property modified to&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &lt;b&gt;NEW LINE IN FIELD&lt;/b&gt;.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;b&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/4681244980991832307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2019/01/changing-entry-key-behaviour-to-allow.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4681244980991832307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4681244980991832307'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2019/01/changing-entry-key-behaviour-to-allow.html' title='Changing &quot;Entry Key Behaviour&quot; to Allow New Lines within a Textbox'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhEvnW6PM_Jt6yYlyh3KRF-cx0tkgKWrp6YtNf3E9y_zyQ5RP4Ge1p3YHCkJCFKXL101u9aoHmNQSfLGtVdrEBjg1lnAuzt4878uWkyELpjp6OQC1W59o9FAyPsFm_tDX6zGkhj5_NiJ4/s72-c/entry+key+behavior+property.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2235746659271554751</id><published>2018-12-27T14:52:00.001-08:00</published><updated>2018-12-27T14:52:47.176-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="rich text formatting"/><category scheme="http://www.blogger.com/atom/ns#" term="tables"/><category scheme="http://www.blogger.com/atom/ns#" term="text box"/><title type='text'>Adding rich text formatting to Access data</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When we store information in an &lt;i&gt;Access for Office 365&lt;/i&gt; database, text formatting (eg setting text as bold or italic, and changing font size etc) isn&#39;t normally a consideration. For example, if we have a field storing a title, it is very unlikely that we would need to &lt;i&gt;save &lt;/i&gt;the titles&#39; font size.&amp;nbsp; This is something we can add later to a text box property of a form or report where the date is presented to the user.&lt;/div&gt;
&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG0vU9PAO33IDCCz1LVAQ9kopqff19s3pSuGP91Z7K7Y5b8ZdgMJZ90MeUkGMM5o8rlFf3FkVTWv_bNBEcHqE0PmwjlKWcnTGGtoCFwEAIFPsj2B4OJv6AhiF9EvQ4VjOkcY5OzLov83M/s1600/formatted+text+box.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Formatted Access 365 text box&quot; border=&quot;0&quot; data-original-height=&quot;291&quot; data-original-width=&quot;836&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG0vU9PAO33IDCCz1LVAQ9kopqff19s3pSuGP91Z7K7Y5b8ZdgMJZ90MeUkGMM5o8rlFf3FkVTWv_bNBEcHqE0PmwjlKWcnTGGtoCFwEAIFPsj2B4OJv6AhiF9EvQ4VjOkcY5OzLov83M/s400/formatted+text+box.PNG&quot; title=&quot;Formatted Access 365 text box&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: notice the text box for the task field&lt;br /&gt;
&amp;nbsp;is in a larger font with bold text.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5AohO87em41bfiUVKCOx1OU6DJ3DeGSQT1lHHDuCUGNGvo_pMjrVFuGoHE_Y8IUIEfOtFnrfALwxjW8w5fZbXJ6yQqi6B8XxaZOd9yjzpsXTKf5jRwV96dtIsqVfcymE14qDHh1yKMrA/s1600/text+box+formatting+propertiesPNG.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; display: inline !important; margin-bottom: 1em; margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;img alt=&quot;Access 365 text box properties&quot; border=&quot;0&quot; data-original-height=&quot;128&quot; data-original-width=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5AohO87em41bfiUVKCOx1OU6DJ3DeGSQT1lHHDuCUGNGvo_pMjrVFuGoHE_Y8IUIEfOtFnrfALwxjW8w5fZbXJ6yQqi6B8XxaZOd9yjzpsXTKf5jRwV96dtIsqVfcymE14qDHh1yKMrA/s1600/text+box+formatting+propertiesPNG.PNG&quot; title=&quot;Access 365 text box properties&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: the &lt;b&gt;property sheet &lt;/b&gt;where&lt;br /&gt;
&amp;nbsp;the db designer sets formatting&lt;br /&gt;
&amp;nbsp;properties of the text box.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, there are certain instances when we &lt;i&gt;do &lt;/i&gt;want to save formatting information relating to the data stored in a particular field of a table. This may be the case when a field contains a large amount of textual data, and we want the &lt;i&gt;user entering the data &lt;/i&gt;to decide which text &lt;i&gt;within&lt;/i&gt; the field is formatted in a particular way; &lt;i&gt;not &lt;/i&gt;the database designer who can only apply formatting to &lt;i&gt;all&lt;/i&gt; text displayed in any given text box control.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;
So how do we add &lt;i&gt;rich text formatting&lt;/i&gt; to an &lt;i&gt;Access for Office 365&lt;/i&gt; database field?&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Rich text formatting is achieved through the addition of html markup tags to the text they relate to.&amp;nbsp; These are the same tags used by web pages for formatting content.&amp;nbsp; However, we don&#39;t need any knowledge of HTML markup, because &lt;i&gt;Access for Office 365&lt;/i&gt; does it for us.&amp;nbsp; All we need to do is change the &lt;b&gt;TEXT FORMAT&lt;/b&gt; property of the field within the database table.&amp;nbsp; NB this can only be done on a table field set to the&amp;nbsp;&lt;b&gt;LONG TEXT &lt;/b&gt;datatype.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here are the instructions for setting up a&lt;b&gt; LONG TEXT &lt;/b&gt;field for&amp;nbsp;&lt;b&gt;rich text formatting&lt;/b&gt;:&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Open (or create) the table containing the field to be set to rich text in DESIGN VIEW.&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
Change the data type for the field to &lt;b&gt;LONG TEXT&lt;/b&gt; in the TABLE DESIGN GRID.&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwSmFPj59tprgfzKDVQtJwZI4udHctWLuRpZWLY53Emke7qV6I81HMhOaWgq7wuo6S6YZxZnaglKSXC1Kys-UjRyoEJeKaMG6warnjww4WnfeoIpPvR1gGPwJpt-J2kJN6nXu_8xqGoZc/s1600/set+table+data+type.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;373&quot; data-original-width=&quot;406&quot; height=&quot;292&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwSmFPj59tprgfzKDVQtJwZI4udHctWLuRpZWLY53Emke7qV6I81HMhOaWgq7wuo6S6YZxZnaglKSXC1Kys-UjRyoEJeKaMG6warnjww4WnfeoIpPvR1gGPwJpt-J2kJN6nXu_8xqGoZc/s320/set+table+data+type.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Above&lt;/b&gt;: the &lt;b&gt;entry &lt;/b&gt;field being set to&lt;b&gt; LONG TEXT&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
Change the &lt;b&gt;TEXT FORMAT &lt;/b&gt;property to &lt;b&gt;RICH TEXT &lt;/b&gt;in the field property grid.&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5NqLNXtK1kbuVnOlRMju6U8OLeMeuACEsMhxxfypYphasMhgh0i0TEXwFMdSBx-hQta6k58Z6fdIoYx3JX1kxtwELL9vViubvaZcFWk4AxVRz7wJIpvDL51bLrHNuTgyk477WqOlTm5M/s1600/text+format+table+property.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;251&quot; data-original-width=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5NqLNXtK1kbuVnOlRMju6U8OLeMeuACEsMhxxfypYphasMhgh0i0TEXwFMdSBx-hQta6k58Z6fdIoYx3JX1kxtwELL9vViubvaZcFWk4AxVRz7wJIpvDL51bLrHNuTgyk477WqOlTm5M/s1600/text+format+table+property.PNG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Above: changing the &lt;b&gt;TEXT FORMAT&lt;/b&gt; property to&lt;b&gt; RICH TEXT&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We can now change from TABLE DESIGN VIEW to DATASHEET VIEW and add rich text formatting to data stored in the field we have just modified.&amp;nbsp; Do this by highlighting some text within the field and selecting the desired formatting from the context menu that opens automatically. Alternatively, you can also use the TEXT FORMATTING&amp;nbsp; group of icons from the HOME ribbon.&lt;/div&gt;
&lt;ol&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggqvI3Oa8YIDXvupmUSqY5pjS9_diXoo_TJPKpMjHvd6N30qZnGM6Bj8vduEKtKnPoO1g-mFd8NGTmuYlBbILhQ5glxfvXpMyp1Z-0PKSDw1J340Tr_CllHEdYI2d6A_Sw9aeSgz1Yp1k/s1600/formatted+field+in+datasheet+view.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;337&quot; data-original-width=&quot;765&quot; height=&quot;280&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggqvI3Oa8YIDXvupmUSqY5pjS9_diXoo_TJPKpMjHvd6N30qZnGM6Bj8vduEKtKnPoO1g-mFd8NGTmuYlBbILhQ5glxfvXpMyp1Z-0PKSDw1J340Tr_CllHEdYI2d6A_Sw9aeSgz1Yp1k/s640/formatted+field+in+datasheet+view.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px;&quot;&gt;&lt;b style=&quot;font-size: 12.8px;&quot;&gt;Above&lt;/b&gt;&lt;span style=&quot;font-size: 12.8px;&quot;&gt;: an example of&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-size: 12.8px;&quot;&gt;rich text formatting&lt;/b&gt;&lt;span style=&quot;font-size: 12.8px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 12.8px;&quot;&gt;within an&lt;/span&gt;&lt;span style=&quot;font-size: 12.8px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-size: 12.8px;&quot;&gt;Access for Office 365&lt;/i&gt;&lt;span style=&quot;font-size: 12.8px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: 12.8px;&quot;&gt;table field.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: 12.8px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Displaying formatted data on &lt;i&gt;Access for Office 365&lt;/i&gt; &lt;i&gt;forms &lt;/i&gt;and &lt;i&gt;reports&lt;/i&gt;.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now that we have set up the table for&lt;i&gt; rich text formatting&lt;/i&gt;, there is one other thing we need to do if we want to display our formatted data in a text box control on a form or report. This involves changing the text box&#39;s&amp;nbsp;&lt;b&gt;TEXT FORMAT &lt;/b&gt;property to&lt;b&gt; RICH TEXT&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;ol&gt;
&lt;li&gt;Open the form containing the text box we want to change in &lt;b&gt;DESIGN VIEW&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Select the text box control by clicking it in the design grid.&lt;/li&gt;
&lt;li&gt;Open the properties sheet by clicking the &lt;b&gt;PROPERTIES SHEET &lt;/b&gt;icon from the&amp;nbsp;&lt;b&gt;DESIGN &lt;/b&gt;ribbon.&lt;/li&gt;
&lt;li&gt;Click on the &lt;strong&gt;DATA&amp;nbsp;&lt;/strong&gt;Tab on the properties sheet, and change the &lt;strong&gt;TEXT FORMAT&amp;nbsp;&lt;/strong&gt;property to &lt;strong&gt;Rich Text.&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Z2QENACNWpkQLXcIJ8W0pw74MAWjwYJFe62oXq6xDityhdPfklDp4GfJkLTX9rb76Byr4awtnimDhTVMuDzhkmZBEQioHXgFm_QrhrYrUNvaumTmXaOL-wvqeIQZ0FFpR3mFrG1KvR0/s1600/text+format+property+of+text+box+control.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;719&quot; data-original-width=&quot;1056&quot; height=&quot;433&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Z2QENACNWpkQLXcIJ8W0pw74MAWjwYJFe62oXq6xDityhdPfklDp4GfJkLTX9rb76Byr4awtnimDhTVMuDzhkmZBEQioHXgFm_QrhrYrUNvaumTmXaOL-wvqeIQZ0FFpR3mFrG1KvR0/s640/text+format+property+of+text+box+control.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When we now re-open the form in &lt;b&gt;FORM VIEW&lt;/b&gt;, &lt;i&gt;rich text formatting&lt;/i&gt; is applied to any text the user had previously set before it was saved in the forms underlying table.&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;-webkit-text-stroke-width: 0px; clear: both; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 0px; orphans: 2; text-align: center; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;font-family: &amp;quot;times new roman&amp;quot;; letter-spacing: normal; margin-bottom: 0.5em; margin-left: auto; margin-right: auto; padding: 6px; text-align: center; text-indent: 0px; text-transform: none; word-spacing: 0px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5x9eOpN5z3VALa1ObbwSFIZLpzS9oFzlCV1Rn5mwu_u8AppsNKVLpBhb8bg2O2PjLLopOCFc8_MF8W-7S8sY_oTPSfBm7mSWAvLsO2l5agGoQ71yWKd25UuvQgkD8FG2C1bDI_09iV8A/s1600/rich+text+formatting.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Access 365 Rich Text Formatting Example&quot; border=&quot;0&quot; data-original-height=&quot;562&quot; data-original-width=&quot;832&quot; height=&quot;432&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5x9eOpN5z3VALa1ObbwSFIZLpzS9oFzlCV1Rn5mwu_u8AppsNKVLpBhb8bg2O2PjLLopOCFc8_MF8W-7S8sY_oTPSfBm7mSWAvLsO2l5agGoQ71yWKd25UuvQgkD8FG2C1bDI_09iV8A/s640/rich+text+formatting.PNG&quot; title=&quot;Access 365 Rich Text Formatting Example&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px; padding-top: 4px; text-align: center;&quot;&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;b&gt;Above&lt;/b&gt;: an example of&amp;nbsp;&lt;b&gt;rich text formatting&lt;/b&gt;&amp;nbsp;within an&amp;nbsp;&lt;i&gt;Access for Office 365&lt;/i&gt;&amp;nbsp;text box control.&amp;nbsp;&lt;br /&gt;
&lt;span style=&quot;font-size: 12.8px;&quot;&gt;Had we left the TEXT FORMAT property as PLAIN TEXT, any data displayed in the text box would&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 12.8px;&quot;&gt;not have been formatted; any text that should have been, would have appeared in plain text between html markup tags.&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/2235746659271554751/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2018/12/adding-rich-text-formatting-to-access.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2235746659271554751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2235746659271554751'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2018/12/adding-rich-text-formatting-to-access.html' title='Adding rich text formatting to Access data'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG0vU9PAO33IDCCz1LVAQ9kopqff19s3pSuGP91Z7K7Y5b8ZdgMJZ90MeUkGMM5o8rlFf3FkVTWv_bNBEcHqE0PmwjlKWcnTGGtoCFwEAIFPsj2B4OJv6AhiF9EvQ4VjOkcY5OzLov83M/s72-c/formatted+text+box.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-8419266973460410311</id><published>2012-06-08T05:45:00.000-07:00</published><updated>2012-06-08T05:46:36.652-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mail Merge"/><category scheme="http://www.blogger.com/atom/ns#" term="MS Access"/><category scheme="http://www.blogger.com/atom/ns#" term="MS Word"/><title type='text'>Using MS Access Data in a Mail Merge</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Suppose you have an Access Database containing the names and addresses of your customers. &amp;nbsp;Every now and again you may want or need to send a standard letter to each customer who has opted in to such mailings. &amp;nbsp;However, you are aware that these letters are going to look so much better, and work so much more effectively, if they are personalised to each particular recipient. &amp;nbsp;A basic example of this is to print the name and address of the customer at the top of the letter, and to include the customers title and surname in the greeting line. &amp;nbsp; We can go much further than this, of course, and include information about the customers account and even their previous orders (if appropriate).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There are two ways of doing this. We could create an access report which is fine and good. After all, the data is stored in Access, so why not create a the letter by means of such a report? &amp;nbsp;It is certainly possible to do so. &amp;nbsp;However, there may well be an advantage in merging your customer data stored in an Access table or query into an MS Word word-processing document. &amp;nbsp;It is arguably much easier to sit down and compose a well presented standard letter using MS Word (than it is to create the same document in an Access report). &amp;nbsp;It might be said that Word is a better tool for this particular job.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Mail Merge&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The process whereby data from a table is integrated into a word processing document is known as a &lt;i&gt;mail merge&lt;/i&gt;. &amp;nbsp;The following exercise explains how to use information from the Access table in Figure 1 below. &lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZXCEKDQGuWnMuuaQ0X6J5WGnfIBFymXX2ncV7bVAWTqb30Ay_auC7HQBAgW-udo9gT8Rt0eJ7yS0mBDDKI6PHSNUd9fsRKhhcPSioH1zf6ppBTi_ESeAsIhYGVBKzkL-PubhzbPUWtBc/s1600/fields.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZXCEKDQGuWnMuuaQ0X6J5WGnfIBFymXX2ncV7bVAWTqb30Ay_auC7HQBAgW-udo9gT8Rt0eJ7yS0mBDDKI6PHSNUd9fsRKhhcPSioH1zf6ppBTi_ESeAsIhYGVBKzkL-PubhzbPUWtBc/s1600/fields.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1:&lt;/b&gt; The schema of the Access table we shall be using.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Connecting to Access Data&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This first stage in the process involves connecting MS Word to the database where the customer data &amp;nbsp;is stored.&amp;nbsp;We are going to be working on blank document here, but normally you would begin by composing your standard letter. &amp;nbsp;The object of this exercise is to show how a Word document gains access to data in an MS Access table or query (rather than how to compose a well presented Word document per se).&lt;/div&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Open MS Word. &amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the SELECT RECIPIENTS icon. &amp;nbsp;This is located in the START MAIL MERGE group of the MAILINGS ribbon. Clicking the icon reveals a drop down menu. &amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Select USE EXISTING LIST from the drop down menu.&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
Browse to the location of your Access Database (in the window that has opened) and &amp;nbsp;double click the it&#39;s file name. &amp;nbsp;This opens the SELECT TABLE dialog form in which you see all the tables and queries from your database.&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc1fL4KPk_jzpye-yUvtFGiMkHRairrqY-oDb6wIUSULTjWiw0gafVEjFl67JBUKKcem2NRJph_FBOhDK66-iLosjCQppBp5-JmJaDQr5LmMN88bQUuKqOtwXQ2klZjgYgnFQKpqTU7Xw/s1600/select-table.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc1fL4KPk_jzpye-yUvtFGiMkHRairrqY-oDb6wIUSULTjWiw0gafVEjFl67JBUKKcem2NRJph_FBOhDK66-iLosjCQppBp5-JmJaDQr5LmMN88bQUuKqOtwXQ2klZjgYgnFQKpqTU7Xw/s1600/select-table.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Figure 2: The &lt;b&gt;SELECT TABLE&lt;/b&gt;&amp;nbsp;dialog form.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Double click the name of the table or query containing the customer names and addresses. &amp;nbsp;We are interested in the tblCustomer. The dialog form then closes. &amp;nbsp;You are now ready to select which fields to use in your document.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Accessing Table or Query Fields&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We have now connected to the Access Database and the table in which the customer data is stored. &amp;nbsp;The next stage in the process is to insert fields from that table into the actual Word Document itself. &amp;nbsp;We are going to use fields to enter the customer&#39;s address at the top of the letter, and to produce a greeting line. &amp;nbsp;If we wanted, we could also go further and insert data from the table with the main text of the letter.&lt;/div&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the location on the document where the field is to be inserted.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the lower half of the INSERT MERGE FIELD split button icon. &amp;nbsp;This is located in the WRITE AND INSERT FIELDS group of the MAILINGS ribbon. &amp;nbsp;A drop down list of fields appears (see figure 3 below). 

&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlMXUtJD1jEmdvrxFzjvmVX8qSY5VheLxKuhHVBcd5MnQhpCwTqaa9zJP2OmYd_FeCqVJ3N3blC9RPJevPc9ewb29L0gI5lkvA4e79Shdh9E7i2Z30fxZDGoJMiDqTT-rufFD9XyT7Qtk/s1600/select-fields.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlMXUtJD1jEmdvrxFzjvmVX8qSY5VheLxKuhHVBcd5MnQhpCwTqaa9zJP2OmYd_FeCqVJ3N3blC9RPJevPc9ewb29L0gI5lkvA4e79Shdh9E7i2Z30fxZDGoJMiDqTT-rufFD9XyT7Qtk/s1600/select-fields.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 3:&lt;/b&gt; Insert&amp;nbsp;&lt;b&gt;Mail Merge Fields&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Select the customers &lt;b&gt;title &lt;/b&gt;field from the list. A &lt;b&gt;title &lt;/b&gt;field place holder now appears on the document.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Repeat step 2, this time selecting the surname field. &amp;nbsp;Make sure you leave a space between the two place holders.&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Go to a new line and then repeat step 2 again, this time selecting the first address field. &amp;nbsp;Repeat this step for each of the address fields, each field on a separate line.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Go down two &amp;nbsp;lines below the address fields to enter the greeting line. &amp;nbsp;Type a greeting such as &quot;Dear &quot;, leave a space, and then insert a &lt;b&gt;title &lt;/b&gt;field, followed by another space, and then the &lt;b&gt;surname &lt;/b&gt;field&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Your document should now look like this:&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimxguy4EreuP8luW4Ab6dpHqxWzOfYLrsuEsfwFNy4RpqNf27sn64T723OQOQa1zaF-l9MKBhLMyuXmHsDWsQ_AG-O4glefcALhMEgb3DYJjTiQ4G-06PSVN1quXlmC0Uyx7QYCqVPd2c/s1600/merge-fields.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimxguy4EreuP8luW4Ab6dpHqxWzOfYLrsuEsfwFNy4RpqNf27sn64T723OQOQa1zaF-l9MKBhLMyuXmHsDWsQ_AG-O4glefcALhMEgb3DYJjTiQ4G-06PSVN1quXlmC0Uyx7QYCqVPd2c/s1600/merge-fields.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 4:&lt;/b&gt; The &lt;b&gt;Mail Merge Field&lt;/b&gt; Placeholders.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Merging Access Data&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Once you have added the mail merge fields to your document, you are nearly ready to run the mail merge. Before we do, however, it is a good idea to preview what the documents are going to look like after the data is merged. Do this by clicking the PREVIEW RESULTS icon on the MAILING RIBBON. Each record from the database is then merged onto a separate document. You can scroll through each of these &quot;document records&quot; using the navigation buttons in the PREVIEW RESULTS group. This is how our document looks when previewed:&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLUu32ZNsR2vdfeirQRbA8Jn3IelH0BHtIXGHQSX7pSleD6wK4B18Zy_qDN6_v4iECekheIpoYLlDfZW__nTiT7pMfB534W13pbqiRQTqdnJe5hcLtggN4Uq2j-6C5QhkDmOA9_fdTA2Y/s1600/merged.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLUu32ZNsR2vdfeirQRbA8Jn3IelH0BHtIXGHQSX7pSleD6wK4B18Zy_qDN6_v4iECekheIpoYLlDfZW__nTiT7pMfB534W13pbqiRQTqdnJe5hcLtggN4Uq2j-6C5QhkDmOA9_fdTA2Y/s1600/merged.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 5 (above): &lt;/b&gt;Preview for the first record of merged data.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqIN7JG7hdJLG0SQEukjy__DWKZ37Xsyu7LU1MxykUHiTIB2iWcKoWJv_3avBr4S3hvwp-lIMwXgYLzxme6nyTBwf8t3CCLLPh35F1CDebT2hh3Ej5nNxch93cFGv1DY-KAchp21EY7VE/s1600/finish-and-merge.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqIN7JG7hdJLG0SQEukjy__DWKZ37Xsyu7LU1MxykUHiTIB2iWcKoWJv_3avBr4S3hvwp-lIMwXgYLzxme6nyTBwf8t3CCLLPh35F1CDebT2hh3Ej5nNxch93cFGv1DY-KAchp21EY7VE/s1600/finish-and-merge.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 6:&lt;/b&gt; FINISH AND MERGE.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We can now run the mail merge. Do this by clicking the FINISH AND MERGE button (see figure 6 above). You are then given the option to PRINT DOCUMENTS or EDIT INDIVIDUAL DOCUMENTS. Doing the latter opens a new instance of Word containing the merged documents. You are then free to make any adjustments that you see fit, and print out when ready.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/8419266973460410311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/06/using-ms-access-data-in-mail-merge.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/8419266973460410311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/8419266973460410311'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/06/using-ms-access-data-in-mail-merge.html' title='Using MS Access Data in a Mail Merge'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZXCEKDQGuWnMuuaQ0X6J5WGnfIBFymXX2ncV7bVAWTqb30Ay_auC7HQBAgW-udo9gT8Rt0eJ7yS0mBDDKI6PHSNUd9fsRKhhcPSioH1zf6ppBTi_ESeAsIhYGVBKzkL-PubhzbPUWtBc/s72-c/fields.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-3396254250816817193</id><published>2012-06-02T11:39:00.000-07:00</published><updated>2012-06-02T11:39:35.973-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="argument"/><category scheme="http://www.blogger.com/atom/ns#" term="class module"/><category scheme="http://www.blogger.com/atom/ns#" term="class object"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><category scheme="http://www.blogger.com/atom/ns#" term="module"/><category scheme="http://www.blogger.com/atom/ns#" term="parameter"/><category scheme="http://www.blogger.com/atom/ns#" term="project"/><category scheme="http://www.blogger.com/atom/ns#" term="scope"/><category scheme="http://www.blogger.com/atom/ns#" term="sub procedures"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>VBA Project Anatomy and Scope</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Last week I explained how to create an Access &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2012/05/writing-custom-functions-for-access-vba.html&quot; target=&quot;_blank&quot;&gt;VBA Custom Function&lt;/a&gt; in a &lt;i&gt;global module&lt;/i&gt;.&amp;nbsp; This was something of a departure from what I covered in previous blog posts.&amp;nbsp; All of the programming I had covered previously has been associated with a given form or report - what we refer to as a&amp;nbsp; &lt;b&gt;&lt;i&gt;Class Object&lt;/i&gt;&lt;/b&gt;.&amp;nbsp; In this post we are going to take a step back and look at the general structure of a VBA &lt;i&gt;&lt;b&gt;Project&lt;/b&gt;&lt;/i&gt; as a whole, &amp;nbsp;and in so doing we will examine the concept and workings of &lt;i&gt;&lt;b&gt;Scope&lt;/b&gt;&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;VBA Projects&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I have mentioned in the past that Access and VBA are two separate, albeit closely related, pieces of development software.&amp;nbsp; When we create an access database, a VBA project linked to that particular database is created for us automatically.&amp;nbsp; It is within this project that we create and store all the code relating to our database.&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: right; margin-left: 1em; text-align: right;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDYjmwkx6CZ3A0n6HprcZRaUVcUnavc72ucP83c-2Q3chveoiBxnTHffvBiRjAmeTV5chEXfVg3eRbjSyxgaU7Y0em_baLrTyg6XlVvj0KZiKGcitH1uk_chXZWA6OVS4lIJWzgkO1f64/s1600/project-explorer.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDYjmwkx6CZ3A0n6HprcZRaUVcUnavc72ucP83c-2Q3chveoiBxnTHffvBiRjAmeTV5chEXfVg3eRbjSyxgaU7Y0em_baLrTyg6XlVvj0KZiKGcitH1uk_chXZWA6OVS4lIJWzgkO1f64/s1600/project-explorer.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1:&lt;/b&gt; The VBA &lt;b&gt;Project Explorer&lt;/b&gt;&lt;br /&gt;
showing folders for &lt;i&gt;Class Objects&lt;/i&gt;, &lt;i&gt;Modules &lt;/i&gt;and&lt;br /&gt;
&lt;i&gt;Class Modules&lt;/i&gt;.&lt;/td&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The VBA project consists of three main elements: these are &lt;i&gt;class objects&lt;/i&gt;, &lt;i&gt;modules &lt;/i&gt;and &lt;i&gt;class modules&lt;/i&gt;. These can be viewed in tree diagram format via the VBA Project Explorer (see &lt;b&gt;Figure 1&lt;/b&gt; right).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Class Objects&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;Class Objects&lt;/i&gt; contain code relating to elements in a&amp;nbsp;&amp;nbsp;form or report.&amp;nbsp; We covered these in some detail in the &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/11/learning-access-vba-beginners-guide.html&quot; target=&quot;_blank&quot;&gt;Learning Access VBA&lt;/a&gt; series of posts. As you may remember, code from class modules is generally triggered when a form or report event is triggered (for example, the &lt;b&gt;OnCurrent&lt;/b&gt; Event is triggered when the user moves into a record displayed on a form).&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Modules&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Modules, on the other hand are not associated with any particular form or report, but do contain variables, sub procedures and functions that can communicate with them in various ways.&amp;nbsp; They are a convenient place to keep code which can be read, written to, or called from the class objects.&amp;nbsp; Moreover, when declared &lt;b&gt;Public&lt;/b&gt;, any given variable, sub procedure or function within a Module can be accessed from many different class objects (and sub procedures within class objects) elsewhere in the project.&amp;nbsp; As such, modules help us &lt;i&gt;organise &lt;/i&gt;and &lt;i&gt;manage &lt;/i&gt;our code, thereby making our VBA project more logical and efficient.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets elaborate on this further.&amp;nbsp; Suppose we have a sub procedure called &lt;b&gt;deleteRecord&lt;/b&gt; stored in a module.&amp;nbsp; It purpose is to delete a particular record from a particular table when called. &amp;nbsp;The advantage of locating this code in a module is so different forms in the database can also make use of this same code.&amp;nbsp; So rather than&amp;nbsp; re-write the same section of code in each form, we write it once in a module, and &lt;i&gt;call &lt;/i&gt;it whenever one of the forms needs to use it.&amp;nbsp; As such, we not only write less code, and save time in so doing, but we can easily maintain and modify that code since it is located in one module. That is to say, if we want to change how the &amp;nbsp;&lt;b&gt;deleteRecord &lt;/b&gt;command button behaves in all the sharing forms, we only need update our code in one central place.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;Class Modules&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So far we have said little about &lt;i&gt;Class Modules&lt;/i&gt;, the third main element of a VBA Project.&amp;nbsp; These are actually worthy of a complete series of blog posts in their own right (something which I may well do in the future). For now, however, let&#39;s just say they offer the programmer a way of creating their own custom objects made up of properties, methods and events.&amp;nbsp; Like conventional modules, class modules also help the programmer organise and manage code, but in a way that is potentially more complex and powerful.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Scope&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
With the partitioning of class objects, modules and class modules, VBA Projects have the potential to become very large and complicated. &amp;nbsp;On the one hand these different project &#39;zones&#39; need to be self contained so something happening in one class module does not interfere with something happening in another elsewhere; yet on the other, they also need to exchange information and communicate. &amp;nbsp;This is where the concept of &lt;i&gt;&lt;b&gt;Scope &lt;/b&gt;&lt;/i&gt;comes in.&lt;br /&gt;
&lt;br /&gt;
The concept of scope relates to the way in which different zones of a VBA Project partition the processing of data that occurs within and between each of those sections. We are going to illustrate how this works in relation to &lt;i&gt;variables &lt;/i&gt;and &lt;i&gt;sub procedure/function calls&lt;/i&gt;. Lets start with how variables behave within a form&#39;s object class.&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVHWsXBxurUTW2cBe_7QTQtsW3m7bQBNjDkNkQhyo_sG-QMRvH9GkP6N8MjtTo0_A7ksdaYAEN0tbEo0WpyD1Xf3Eyb11j64M3RAFXrCPNYyX92ediTkCnqwDSdn5Nw6TXFBuvt2RqziA/s1600/class-object.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVHWsXBxurUTW2cBe_7QTQtsW3m7bQBNjDkNkQhyo_sG-QMRvH9GkP6N8MjtTo0_A7ksdaYAEN0tbEo0WpyD1Xf3Eyb11j64M3RAFXrCPNYyX92ediTkCnqwDSdn5Nw6TXFBuvt2RqziA/s1600/class-object.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 2:&lt;/b&gt; &amp;nbsp;A basic &lt;b&gt;Class Object&lt;/b&gt; to illustrate &lt;b&gt;Scope &lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;b&gt;Variables and Scope&lt;/b&gt;&lt;br /&gt;
The screenshot in figure 2 shows a class object containing two sub procedures, &lt;b&gt;Form_Load()&lt;/b&gt; and &lt;b&gt;mySub(). &amp;nbsp;&lt;/b&gt;A total of three variables are declared within the class object, two of which, -&amp;nbsp;&lt;b&gt;varB &lt;/b&gt;and &lt;b&gt;varC&lt;/b&gt;&amp;nbsp; -are contained within sub procedures. &lt;b&gt;VarA &lt;/b&gt;on the other hand is declared above both sub procedures in what is known as the &lt;b&gt;&lt;i&gt;General Declarations&lt;/i&gt;&lt;/b&gt;&lt;i style=&quot;font-weight: bold;&quot;&gt; &lt;/i&gt;section. &amp;nbsp;The difference in positioning has a direct effect on the scope of each variable. &amp;nbsp;Let&#39;s examine this in more detail.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;VarB &lt;/b&gt;is declared within the form&#39;s&amp;nbsp;&lt;b&gt;Form_Load()&lt;/b&gt; sub. &amp;nbsp;This means the &lt;i&gt;scope &lt;/i&gt;of &lt;b&gt;varB&lt;/b&gt; is &lt;i&gt;local &lt;/i&gt;to this sub, and can only be accessed by code &lt;i&gt;within &lt;/i&gt;it. &amp;nbsp;As such, we can can only read and write to this variable from within the same sub procedure in which it is declared. So, for example, if we assign a value to &lt;b&gt;varB &lt;/b&gt;within the &lt;b&gt;Form_Load()&lt;/b&gt; sub, we will not be able to read that value from code executed within &lt;b&gt;mySub &lt;/b&gt;and vice versa. &amp;nbsp;This is what is meant by a &lt;i&gt;local &lt;/i&gt;variable.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;VarA &lt;/b&gt;on the other hand is written within the &lt;b&gt;General Declarations&lt;/b&gt; section outside of any sub procedure. &amp;nbsp;The scope of any variable declared here is&amp;nbsp;&lt;b&gt;class object wide&lt;/b&gt;. &amp;nbsp;That is, it can be accessed from anywhere &lt;i&gt;within &lt;/i&gt;it&#39;s own class object. &amp;nbsp;As such, we can&amp;nbsp;assigned&amp;nbsp;a value to &lt;b&gt;varA &lt;/b&gt;in the&amp;nbsp;&lt;b&gt;Form_Load()&lt;/b&gt;&amp;nbsp;sub, and then read that same value externally from &lt;b&gt;mySub&lt;/b&gt;. &amp;nbsp;What we can&#39;t do, however, is access&amp;nbsp;the variable from outside of this particular class object. &amp;nbsp;To do this we need to declare a &lt;b&gt;Public Variable &lt;/b&gt;from a Module.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Public Variables&lt;/b&gt;&lt;br /&gt;
The scope of a public variable declared in a module is &lt;b&gt;project wide &lt;/b&gt;- that is&lt;b&gt;&amp;nbsp;&lt;/b&gt;to say, it can be accessed from any &lt;i&gt;class object&lt;/i&gt;, &lt;i&gt;module &lt;/i&gt;or &lt;i&gt;class module&lt;/i&gt; in the project. &amp;nbsp;Public variables are declared using the &lt;b&gt;Public &lt;/b&gt;Statement (as opposed to the usual &lt;b&gt;Dim &lt;/b&gt;Statement) in the module&#39;s &lt;b&gt;General Declarations&lt;/b&gt; section (see Figure 3 below for an example).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyiv-Szpw7Pkd9pGDMtkGrT6unGjQnyQqDUNC6N3sYx8xLXviWZ7Gr0IB_S8Ta8672frV95yrE8CEvpBKb-YkgM_PghyYlC0CT3k-DsMB_d_wc2w_e4WDxYoOond5RdKAqVRYFTRJLLeE/s1600/public-variable.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyiv-Szpw7Pkd9pGDMtkGrT6unGjQnyQqDUNC6N3sYx8xLXviWZ7Gr0IB_S8Ta8672frV95yrE8CEvpBKb-YkgM_PghyYlC0CT3k-DsMB_d_wc2w_e4WDxYoOond5RdKAqVRYFTRJLLeE/s1600/public-variable.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 3:&lt;/b&gt; The shows the Public Variable, &lt;b&gt;varX&lt;/b&gt;, in the &lt;b&gt;General Declarations&lt;/b&gt; section of &lt;b&gt;Module1&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
As you can see, the VBA Project in Figure 3 contains two class objects (&lt;b&gt;Form_frmReadPublicVariable&lt;/b&gt; and &lt;b&gt;Form_frmScopeTest&lt;/b&gt;) and a module (&lt;b&gt;Module1&lt;/b&gt;). &amp;nbsp;Since the variable &lt;b&gt;varX&amp;nbsp;&lt;/b&gt;has been&amp;nbsp;declared with the &lt;b&gt;Public &lt;/b&gt;statement in the &lt;b&gt;General Declarations&lt;/b&gt; section of &lt;b&gt;Module1&lt;/b&gt;, it can be accessed from &lt;i&gt;both &lt;/i&gt;class objects. &amp;nbsp;As such we can assign a value to &lt;b&gt;varX &lt;/b&gt;in the &lt;b&gt;Form_frmScopeTest &lt;/b&gt;class object, and then read that same value some time later from a sub procedure in &lt;b&gt;Form_frmReadPublicVariable&lt;/b&gt;. &amp;nbsp;However, the disadvantage of using public variables is that they make code potentially more difficult to debug, especially in large projects where the variable might be accessed from sub procedures in many different class objects, modules and class modules. &amp;nbsp;To some extent we could say that public variables undermine the code management advantages from working in a partitioned VBA project. &amp;nbsp;That said, they &lt;i&gt;can &lt;/i&gt;be a really useful programming tool if used carefully.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Scope and Persistence&lt;/b&gt;&lt;br /&gt;
Before we move on to look at sub procedure and function calls, it is important to say something about the nature of scope and persistence. &amp;nbsp;In the context of scope, persistence is how long a value assigned to a variable lasts or &lt;i&gt;persists&lt;/i&gt;. &amp;nbsp;How long, that is, before the variable value is lost and forgotten. &amp;nbsp;So, for example, if we assigned a value to a local variable declared within a sub procedure&amp;nbsp;using the&amp;nbsp;&lt;b&gt;Dim&amp;nbsp;&lt;/b&gt;Statement, that value will persist&amp;nbsp;only&amp;nbsp;as long as the sub procedure is running&lt;sup&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;(1)&lt;/span&gt;&lt;/sup&gt;. &amp;nbsp;Once the sub has finished the value assigned to the variable no longer persists. &amp;nbsp;Likewise if a variable is declared within the general declarations section of a form class object, any value assigned to the variable will only persist whilst that form is still open. &amp;nbsp;Once closed the value is lost. Of course it is public variables which have the greatest persistence. &amp;nbsp;Any value assigned to one of these will last until the database application is closed.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: #f3f3f3; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;(1) There is an exception to this rule. &amp;nbsp;We can declare the variable using the &lt;b&gt;Static &lt;/b&gt;Statement instead of &lt;b&gt;Dim&lt;/b&gt;. &amp;nbsp;Doing so enables the value to persist, but only within the sub where it has been declared. &amp;nbsp;The next time that particular sub executes, the previous variable value is remembered and can be read by code (providing that code is still within the same sub).&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Scope and Sub Procedure / Function Calls&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you read my post on &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2012/05/writing-custom-functions-for-access-vba.html&quot; target=&quot;_blank&quot;&gt;Writing Custom Functions for Access VBA&lt;/a&gt; last week, you may already be familiar with the concept of &lt;i&gt;calling &lt;/i&gt;a function. &amp;nbsp;You may recall how the &lt;b&gt;myPercentage &lt;/b&gt;function located in an external module was called from a sub procedure within a form&#39;s class object. &amp;nbsp;You may also recall how we passed three &lt;i&gt;parameters &lt;/i&gt;to that function. &amp;nbsp;The significance of being able to pass parameters in this way, is very important from the perspective of scope. &amp;nbsp;That is to say, if the call&lt;i&gt;ing&lt;/i&gt; sub procedure needs to share a local variable with the call&lt;i&gt;ed&lt;/i&gt;&amp;nbsp;function or sub, passing local data in the form of a parameter enables us to bypass the issue of scope. &amp;nbsp;As such, parameters are a way of letting various parts of the VBA project share information and communicate without compromising the real need to keep the project strictly partitioned in an organised manner.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets examine a simple example of how passing a parameter, this time in a sub procedure call, can bypass the issue of scope:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Private Sub Command9_Click()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; Dim varThis As Integer&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; varThis = 10&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; Call thatSub(varThis)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;End Sub&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Private Sub thatSub(argReceived As Integer)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; MsgBox (&quot;The argument received is: &quot; &amp;amp; argReceived)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;End Sub&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here we have two private sub procedures within the a form&#39;s class object. &amp;nbsp;When the user clicks a&amp;nbsp;command button, the &lt;b&gt;Command9_Click &lt;/b&gt;sub procedure begins to run. &amp;nbsp;It defines a local variable called &lt;b&gt;varThis &lt;/b&gt;and assigns it with the integer value &lt;b&gt;10&lt;/b&gt;. &amp;nbsp;The next line calls the &lt;b&gt;thatSub &lt;/b&gt;sub procedure, passing the local variable &lt;b&gt;varThis&lt;/b&gt; as the parameter. &amp;nbsp;This call results in the execution of &lt;b&gt;thatSub&lt;/b&gt;.&lt;b&gt;&amp;nbsp; &lt;/b&gt;Notice how the first line of &lt;b&gt;thatSub &lt;/b&gt;contains the code&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;argReceived As Integer&lt;/span&gt;&lt;/b&gt; within brackets. &amp;nbsp;This is where the passed parameter (&lt;b&gt;varThis&lt;/b&gt;) is received by the called sub procedure. &amp;nbsp;The parameter which has been passed is now referred to as an &lt;i&gt;argument&lt;/i&gt;, and it&#39;s value can be accessed from code within the receiving sub procedure. &amp;nbsp;As such, when the second line of code in &lt;b&gt;thatSub &lt;/b&gt;runs, a message is displayed ending with the value contained in &lt;b&gt;argReceived &lt;/b&gt;(see figure 4 below). &amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMVteY65Yo4VsMELBxNz6JE-V5L6puWZKbWC34crYroSyUMr0SWDtVZXW37RRYwVlwOPYQ574siROGFSRKrJCJBmiVGfj2ztop6fnlc8tmfO-JZYBQVYWKFjPIRt_6JJI6cw-beaXXo74/s1600/argument-received.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMVteY65Yo4VsMELBxNz6JE-V5L6puWZKbWC34crYroSyUMr0SWDtVZXW37RRYwVlwOPYQ574siROGFSRKrJCJBmiVGfj2ztop6fnlc8tmfO-JZYBQVYWKFjPIRt_6JJI6cw-beaXXo74/s1600/argument-received.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 4:&lt;/b&gt; The message displayed from the&lt;br /&gt;
&amp;nbsp;&lt;b&gt;MsgBox &lt;/b&gt;method in&amp;nbsp;&lt;b&gt;thatSub&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
We see, therefore, that the value contained in what is a local variable has been passed to a different sub procedure which would otherwise have been outside that variable&#39;s scope.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
In this post we have seen how the VBA project is partition into various zones, and how those zones are largely self contained in terms of data processing. &amp;nbsp;This partitioning is maintained via a set of rules collectively known as scope, the advantage of which is the management of code within the project. &amp;nbsp;Since there is a legitimate requirement for these zones to exchange information, the working of scope can be bypassed in a managed manner through the passing of parameters and receipt of arguments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/3396254250816817193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/06/vba-project-anatomy-and-scope.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/3396254250816817193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/3396254250816817193'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/06/vba-project-anatomy-and-scope.html' title='VBA Project Anatomy and Scope'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDYjmwkx6CZ3A0n6HprcZRaUVcUnavc72ucP83c-2Q3chveoiBxnTHffvBiRjAmeTV5chEXfVg3eRbjSyxgaU7Y0em_baLrTyg6XlVvj0KZiKGcitH1uk_chXZWA6OVS4lIJWzgkO1f64/s72-c/project-explorer.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-3817835739105325753</id><published>2012-05-25T07:38:00.000-07:00</published><updated>2019-04-01T12:58:57.134-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="custom function"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Writing Custom Functions for Access VBA</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
VBA Custom Functions work in a similar way to any inbuilt MS Access Function. &amp;nbsp;Both types can be called within VBA sub-procedures, and then return a value for the function&#39;s &#39;result&#39;. &amp;nbsp;Take the inbuilt &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/07/using-dlookup-function.html&quot; target=&quot;_blank&quot;&gt;DLookUp function&lt;/a&gt;, for example. &amp;nbsp;This is written as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;varResult = DLookUp (&amp;nbsp;parameter1, parameter2, parameter3&amp;nbsp;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Three things happen when we call this function:&lt;/div&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;The function is called using VBA code (passing three parameters in the process),&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;The function looks up information stored in an access table (based on the parameters passed),&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;It then returns that information, storing the result in a variable called &lt;b&gt;varResult&lt;/b&gt;. &amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
On account of &lt;i&gt;DLookUp&lt;/i&gt; being a built in function, we do not get to see what happens in stage two. &amp;nbsp;Custom Functions are different in that &lt;i&gt;we &lt;/i&gt;actually&amp;nbsp;write a block of VBA code that executes at that stage. &amp;nbsp;Once we have set this up, we can call our custom function as often as we like. &amp;nbsp;Moreover, because custom functions tend to be located in a VBA global module, and declared as &#39;Public&#39; in scope, they can be called from multiple points within our application. In this way, the creation of custom functions make our programming more organized and manageable.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDJFGUqw2wCYedeXKSIOGBc4rOA7dVGzuwbCbv3wctu3ON5IbjyJ09wXWSxnW3f2khq1DdadJqMAXz5nEK5RY2mNuOh2jH-iXv7J0S6WytwTdaa2fgC9eXuBJ1W_f29mYNyiiulWhuyMw/s1600/vba-project-explorer.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDJFGUqw2wCYedeXKSIOGBc4rOA7dVGzuwbCbv3wctu3ON5IbjyJ09wXWSxnW3f2khq1DdadJqMAXz5nEK5RY2mNuOh2jH-iXv7J0S6WytwTdaa2fgC9eXuBJ1W_f29mYNyiiulWhuyMw/s1600/vba-project-explorer.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1: &amp;nbsp;&lt;/b&gt;This screenshot of the &lt;i&gt;VBA Project Explorer&lt;/i&gt; shows&lt;br /&gt;
&amp;nbsp;a module call &lt;b&gt;modCustomFunction&lt;/b&gt;. &amp;nbsp;Providing the custom functions&amp;nbsp;contained within are &lt;br /&gt;
declared &#39;&lt;i&gt;public&lt;/i&gt;&#39; they can be called from anywhere within the project &amp;nbsp;- such as&lt;br /&gt;
the form which I have called &lt;b&gt;frmFunctionDemo&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;How to Create a Custom Function&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When we create a custom function we need to write the code that executes once it has been called from a sub procedure. As we shall see, this code is structured in a similar manner to an ordinary sub. &amp;nbsp;However, we also need to include a line of code which specifically returns a value back to the calling code. This is done by assigning a value to the name of the function (in a similar manner to assigning a value to a variable). For example:&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;Public Function myPercentage(argScore As Integer, argOutOf As Integer)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; myPercentage = (100 / argOutOf) * argScore 2&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;End Function&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This creates a function called &lt;b&gt;myPercentage&lt;/b&gt;. &amp;nbsp;The first line of code declares the function, and &lt;i&gt;receives &lt;/i&gt;two arguments from the calling code ie &lt;b&gt;argScore &lt;/b&gt;and &lt;b&gt;argOutof&lt;/b&gt;. &amp;nbsp;The second line of code in this example returns the result of the &lt;b&gt;myPercentage &lt;/b&gt;function. &amp;nbsp;There can any number of lines of code preceding the returning line. &amp;nbsp;However, I have provided a simple example which returns the result of the function in the same line of code as a percentage calculation. &amp;nbsp;This code is stored in a global module called &lt;b&gt;modCustomFunctions &lt;/b&gt;(see &lt;b&gt;Figure 1&lt;/b&gt; above).&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is the code I have used to call this function:&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;Private Sub cmdCalculate_Click()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Me!txtPercentageResult = myPercentage(Me!txtScore, Me!txtOutOf)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This code executes when a form command button (&lt;b&gt;cmdCalculate&lt;/b&gt;) is clicked by the user. &amp;nbsp;The function (&lt;b&gt;myPercentage&lt;/b&gt;) is called in the second line of code. &amp;nbsp;As you can see, the calling code for &lt;b&gt;myPercentage &lt;/b&gt;&lt;i&gt;passes &lt;/i&gt;two parameters, the values of which reference two text box controls -&amp;nbsp;&lt;b&gt;txtScore &lt;/b&gt;and &lt;b&gt;txtOutOf&lt;/b&gt;. &amp;nbsp;The function uses these parameters (which are &lt;i&gt;received &lt;/i&gt;as the arguments &lt;b&gt;argScore &lt;/b&gt;and &lt;b&gt;argOutOf&lt;/b&gt;) to calculate the percentage and return the result. &amp;nbsp;The result is then displayed in a third text box called &lt;b&gt;txtPercentageResult&lt;/b&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZz7pVrbEz8rbgjGDCzeMofYcjkJQDm2HRplfsEbPtzTBiutkqX-yMch_Z5kve_4lPfVeLF5979-SpmI-jkvh75jRgEf2e8tq3FzgHulmfNiHyfiTu99dif7gx7fq1nAseiC08iazIGQk/s1600/function-demo.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZz7pVrbEz8rbgjGDCzeMofYcjkJQDm2HRplfsEbPtzTBiutkqX-yMch_Z5kve_4lPfVeLF5979-SpmI-jkvh75jRgEf2e8tq3FzgHulmfNiHyfiTu99dif7gx7fq1nAseiC08iazIGQk/s1600/function-demo.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Figure 2: This is the form from which our function is called. &amp;nbsp;The CORRECT ANSWERS textbox is called &lt;b&gt;txtScore&lt;/b&gt;, No OF QUESTIONS is called &lt;b&gt;txtOutOf&lt;/b&gt;, and the PERCENTAGE textbox is called &lt;b&gt;txtPercentageResult&lt;/b&gt;. &amp;nbsp;The CALCULATE&lt;b&gt; &lt;/b&gt;button is called &lt;b&gt;cmdCalculate&lt;/b&gt;.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWl4s6M_nQJ20IqAn1LxVxigMwpOxMSLrww3Nbk3kLPbtafk4Vd6jVxKM_sOv0FDJGzY7AajDSuAzqi_bJq9V1JsmbzaQUdXcE4x_l7avLRnkVSrBtU8PMv1_yNLs0bf_G_rN9zsuX_80/s1600/function.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;374&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWl4s6M_nQJ20IqAn1LxVxigMwpOxMSLrww3Nbk3kLPbtafk4Vd6jVxKM_sOv0FDJGzY7AajDSuAzqi_bJq9V1JsmbzaQUdXcE4x_l7avLRnkVSrBtU8PMv1_yNLs0bf_G_rN9zsuX_80/s640/function.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 3:&lt;/b&gt; The top window shows the code calling the &lt;b&gt;myPercentage&lt;/b&gt; function. &amp;nbsp;The lower window shows the code from the &lt;b&gt;myPercentage&lt;/b&gt; function itself. &amp;nbsp;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/3817835739105325753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/writing-custom-functions-for-access-vba.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/3817835739105325753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/3817835739105325753'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/writing-custom-functions-for-access-vba.html' title='Writing Custom Functions for Access VBA'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDJFGUqw2wCYedeXKSIOGBc4rOA7dVGzuwbCbv3wctu3ON5IbjyJ09wXWSxnW3f2khq1DdadJqMAXz5nEK5RY2mNuOh2jH-iXv7J0S6WytwTdaa2fgC9eXuBJ1W_f29mYNyiiulWhuyMw/s72-c/vba-project-explorer.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-6886039944181352815</id><published>2012-05-18T06:27:00.001-07:00</published><updated>2012-05-18T06:27:10.107-07:00</updated><title type='text'>Your Feedback?</title><content type='html'>I have been writing the MS Access Tips blog around three years, and it is now being read by hundreds of people each day. I am very interested to learn more about who is reading my blog, and and what people think about it. &amp;nbsp;I would be really grateful if you could take the time to answer 6 simple question in a survey that I have set up for this purpose. &amp;nbsp;This will help me to continue writing articles that are relevant and interesting to you, the readers.&lt;br /&gt;
&lt;br /&gt;
Please click the link below to begin the survey. &amp;nbsp;Many thanks.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/p/feedback.html&quot;&gt;Survey for the MS Access Tips Blog&lt;/a&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/6886039944181352815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/your-feedback.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6886039944181352815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6886039944181352815'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/your-feedback.html' title='Your Feedback?'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-1025346968590144593</id><published>2012-05-11T08:31:00.000-07:00</published><updated>2012-05-11T08:31:13.839-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Action Query"/><category scheme="http://www.blogger.com/atom/ns#" term="make table query"/><category scheme="http://www.blogger.com/atom/ns#" term="order management system"/><category scheme="http://www.blogger.com/atom/ns#" term="query"/><title type='text'>Using the Make Table Query to Collect Archive Data</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Information stored in a database is likely to change over time. &amp;nbsp;When details change, data may be overwritten, and once this happens it is lost. &amp;nbsp;There are certain scenario&#39;s where it is important to have access to &#39;historic&#39; data, by which I mean a snapshot of information which was stored in the database at a given point sometime in the past. &amp;nbsp;Let&#39;s take an &lt;a href=&quot;http://www.dealing-with-data.co.uk/order-management-system.html&quot; target=&quot;_blank&quot;&gt;Order Management System&lt;/a&gt; for example. &amp;nbsp;Suppose you need to find a customer contact name from two years previous? &amp;nbsp;If the customer in question happened to be an organisation or business, it is possible that there was a different person in post at that time. &amp;nbsp;In this case, it would be useful to have some facility to access data from that point in time. &amp;nbsp;Whilst we can&#39;t create this sort of archive from the present backwards, &amp;nbsp;we &lt;i&gt;could &lt;/i&gt;have taken a snapshot of this data at periodic intervals previously. &amp;nbsp;One way of doing this was to have created a&amp;nbsp;&lt;b&gt;Make Table Query&lt;/b&gt; to extract relevant data from the database with a query and store the results in a new table. &amp;nbsp;These can then be saved in a separate archive database ready to be accessed if and when needed.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Taking the Order Management System scenario, there is data stored in four related tables, and only certain &amp;nbsp;fields from each table need to be archived. &amp;nbsp;We could simply make a copy of each of the four tables, but this would result in the storage of unnecessary information. &amp;nbsp;It would also be less convenient to access at a later point in time.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The related tables in question are &lt;b&gt;tblCustomer&lt;/b&gt;, &lt;b&gt;tblOrganisation&lt;/b&gt;, &lt;b&gt;tblPerson &lt;/b&gt;and &lt;b&gt;tblAddress&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs-RKERjSMRjJHziFw8CMiYFm0RyA1Hi_nX5cGkNG3HfCSqr1TSSZbJLQJhkuBpD93o4Va2pdKebIOwthB-3pzG4Lf1uk7-wrkVNWqeRdQMGJG-B-EhwMRJyPfaNoWinL9TdmKW9orxrg/s1600/make-table.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;449&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs-RKERjSMRjJHziFw8CMiYFm0RyA1Hi_nX5cGkNG3HfCSqr1TSSZbJLQJhkuBpD93o4Va2pdKebIOwthB-3pzG4Lf1uk7-wrkVNWqeRdQMGJG-B-EhwMRJyPfaNoWinL9TdmKW9orxrg/s640/make-table.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1:&lt;/b&gt; The &lt;b&gt;Make Table&lt;/b&gt; Query for an &lt;i&gt;Order Management System&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Creating a Make Table Query&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Before we create the Make Table Query, you might like to create a new blank database file. &amp;nbsp;This is so we have a separate database into which we can paste the new table from the query. &amp;nbsp;In this exercise I have called it&amp;nbsp;&lt;b&gt;HistoricData.accdb&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is the procedure to create a &lt;i&gt;Make Table&lt;/i&gt; Query:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Open the database which we are going to query (In my case this is the Order Management System).&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the QUERY DESIGN icon (located in the OTHER group of the CREATE ribbon).&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Select the tables to be used from the SHOW TABLE dialog form. I have selected&amp;nbsp;
&lt;b&gt;tblCustomer&lt;/b&gt;,&amp;nbsp;&lt;b&gt;tblOrganisation&lt;/b&gt;,&amp;nbsp;&lt;b&gt;tblPerson&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;b&gt;tblAddress&lt;/b&gt;.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Next select all the fields from the existing tables to be used in the query. &amp;nbsp;These not only form the query results, but also the structure for the new table. &amp;nbsp;I have chosen fields from all four tables so that the new table will be self sufficient.&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Amend the table relationships (or Joins) as required.&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
Click the MAKE TABLE icon (located in the QUERY TYPE group of the DESIGN ribbon). &amp;nbsp;This opens the MAKE TABLE dialog form (see Figure 2 below).&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_2NFLuwDUet7oG2z-woZRZXWzJgIKRTEE9MY_fVbW6EhmSxVS1kztXWowoFwUrAN7u04yFIHhDm0zGgkkg7MEZTKU_5G-fCHXfQBLHy_HapZjxMrFDXKip8mJ_qMjz1BFxo6Zya8nTsE/s1600/make-table-dialog-form.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_2NFLuwDUet7oG2z-woZRZXWzJgIKRTEE9MY_fVbW6EhmSxVS1kztXWowoFwUrAN7u04yFIHhDm0zGgkkg7MEZTKU_5G-fCHXfQBLHy_HapZjxMrFDXKip8mJ_qMjz1BFxo6Zya8nTsE/s1600/make-table-dialog-form.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 2:&lt;/b&gt; The &lt;b&gt;Make Table&lt;/b&gt; Dialog Form.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Enter the name of the new table that we are going to create. &amp;nbsp;I have called mine &lt;b&gt;tblCustomerTeamsMay2012&lt;/b&gt;.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the option button for ANOTHER DATABASE. This ensures the new table will be created in a different database.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Browse to the location of the external database. &amp;nbsp;I have called mine &lt;b&gt;HistoricData.accdb&lt;/b&gt;. &amp;nbsp;Double click the file to select and then click OK to close the dialog form.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Test the Query by clicking the DATASHEET VIEW icon (located in the RESULTS GROUP of the DESIGN ribbon).&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;If you are happy with the data displayed, you can run the Make Table Query by clicking the RUN icon (located in the RESULTS group of the DESIGN ribbon). &amp;nbsp;This will now create the new table in the external database.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can now open the external database and view the newly created table:&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFmfViM42Yoxg_-DyZcLyB29-6TQVp3B4KzqS3-MqB8ld4J98pvcuUwEmwl0pudJxDqcpA-T0G2BHQGLz1KgBlLwJcLwNPfKnZovG8TVqoJ9fH0kKWqmpxt0YGq_yh9W4xQ0HZ1FAuZUg/s1600/new-table.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFmfViM42Yoxg_-DyZcLyB29-6TQVp3B4KzqS3-MqB8ld4J98pvcuUwEmwl0pudJxDqcpA-T0G2BHQGLz1KgBlLwJcLwNPfKnZovG8TVqoJ9fH0kKWqmpxt0YGq_yh9W4xQ0HZ1FAuZUg/s1600/new-table.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 4: &lt;/b&gt;The newly created &lt;b&gt;tblCustomerTeamsMay2012 &lt;/b&gt;table (Design View).&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now all the database administrator has to do is run this query every month, changing the new table to the appropriate month. &amp;nbsp;Over time, we collect a &#39;warehouse&#39; of data ready to be accessed if and when needed. &amp;nbsp;Since this data is stored in a separate database, it does not impact upon the performance of the actual system from which the information was collected.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/1025346968590144593/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/using-make-table-query-to-collect.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/1025346968590144593'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/1025346968590144593'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/using-make-table-query-to-collect.html' title='Using the Make Table Query to Collect Archive Data'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs-RKERjSMRjJHziFw8CMiYFm0RyA1Hi_nX5cGkNG3HfCSqr1TSSZbJLQJhkuBpD93o4Va2pdKebIOwthB-3pzG4Lf1uk7-wrkVNWqeRdQMGJG-B-EhwMRJyPfaNoWinL9TdmKW9orxrg/s72-c/make-table.JPG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-6915515585622883598</id><published>2012-05-04T08:15:00.000-07:00</published><updated>2012-05-04T08:15:20.234-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="client/server"/><category scheme="http://www.blogger.com/atom/ns#" term="external data"/><category scheme="http://www.blogger.com/atom/ns#" term="linking"/><category scheme="http://www.blogger.com/atom/ns#" term="tables"/><title type='text'>Using the Access Database Splitter</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Last year I wrote a post on &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/06/linking-access-to-external-data-source.html&quot; target=&quot;_blank&quot;&gt;Linking to an External Data Source&lt;/a&gt;. &amp;nbsp;This is where we split an Access database &amp;nbsp;into a &lt;b&gt;Back End&lt;/b&gt; (which stores all the tables and data), and a &lt;b&gt;Front End&lt;/b&gt; (which contains all the forms, queries and reports). &amp;nbsp;There are a number of advantages to observing this practice. &amp;nbsp;To begin with, splitting a database file in this way is all but essential if it is to be deployed on a network in a multi-user environment. Another big advantage is that we can easily replace a front end file with a new updated version with minimal disruption - the actual data stored in the back end tables is not touched in this process.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you read the my post last year, you may remember that I showed you how to link a &lt;i&gt;front end&lt;/i&gt; Access file to an existing &lt;i&gt;back end&lt;/i&gt; database. &amp;nbsp;This is fine if the &lt;i&gt;back end&lt;/i&gt; database already exists, or if you decide to create the application in two separate files from the start. &amp;nbsp;However, many developers create or inherit a complete database application as one stand alone file, and then proceed to split the database. &amp;nbsp;Splitting the database can be done manually, but this is often time consuming and there is always the possibility of making errors in the process. &amp;nbsp;An easier and quicker way of doing this is by using the &lt;b&gt;Access Database Splitter&lt;/b&gt;. &amp;nbsp;This is a wizard that splits the database into a front and back end, as described above. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Splitting an Access Database&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The database that I am working with here is an&amp;nbsp;&lt;b&gt;Order Management System&lt;/b&gt; containing a number of tables. &amp;nbsp;If you want to try this on one of your own database files, it does not matter how many tables it contains - it could have a hundred or it could just have one. &amp;nbsp;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: right; margin-left: 1em; text-align: right;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTGTH5lD5T8G8KH4zxQaDfk03LPEL3aaJhTp5Om8ffb9q2MZY9ybhHMaffTluyZAZP2u9AtFoPHMF2uCfYewbnXu3NEC3mXtu3NacuyOGd9xTzlPiMAk35zruLQJu6COzWE7RjNDnq2c4/s1600/database-splitter-icon.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTGTH5lD5T8G8KH4zxQaDfk03LPEL3aaJhTp5Om8ffb9q2MZY9ybhHMaffTluyZAZP2u9AtFoPHMF2uCfYewbnXu3NEC3mXtu3NacuyOGd9xTzlPiMAk35zruLQJu6COzWE7RjNDnq2c4/s1600/database-splitter-icon.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;ol&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the ACCESS DATABASE icon (located in the MOVE DATA group of the DATABASE TOOLS ribbon). &amp;nbsp;See figure 1 on on the right. &amp;nbsp;This opens the DATABASE SPLITTER Wizard.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click the SPLIT DATABASE button at the bottom of the Wizard (see figure 2). &amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;You are now asked to select one of your folders for the new &lt;i&gt;back end &lt;/i&gt;Access file. &amp;nbsp;Browse to a location of your choice, enter a back end&amp;nbsp;file name, and then click SPLIT. &amp;nbsp;After a moment or two, you should get a message box saying &quot;&lt;i&gt;Database Successfully Split&lt;/i&gt;&quot;&lt;i&gt;.&lt;/i&gt;&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Click OK.&lt;/li&gt;
&lt;/ol&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr9OH-ygj23Ely7HFfavU7FDvbgKIvwxSNaPWq4lBv5VBMLc1yeHTgQZgc0ts4-H21imENCUf1AVSr59ZSd27g03ieL29Nap6hiC8s-LSMvWlLHesuW-Df34pVTNabCmo5zYRL8Yq8oEw/s1600/database-splitter-wizard.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr9OH-ygj23Ely7HFfavU7FDvbgKIvwxSNaPWq4lBv5VBMLc1yeHTgQZgc0ts4-H21imENCUf1AVSr59ZSd27g03ieL29Nap6hiC8s-LSMvWlLHesuW-Df34pVTNabCmo5zYRL8Yq8oEw/s1600/database-splitter-wizard.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 2:&amp;nbsp;&lt;/b&gt;The &lt;b&gt;Database Splitter Wizard&lt;/b&gt; from Stage 2.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;text-align: justify;&quot;&gt;You can now look at the navigation pane of the front end database and see the linked tables (see figure 3). &amp;nbsp;You can try adding data to one of your tables and then open the back end file to see it stored there. &amp;nbsp;You could also try copying the front end file in order to access the back end tables with different front ends. &amp;nbsp;In so doing you can see the basic principle behind how multi-user systems operate*.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjho_lFkyoY4r_3sUsAOvYbEBqdYsocl96aqW_tzO5R-QPMbc9ukvRRkxVfcaXnHV47WLD_YbN0I4i8HdeFTA5gIQVlAh44s61-VDf_Tl8vMdI-mtRUltGN3QACgnBNYnct7uA4ONporAQ/s1600/linked-tables.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjho_lFkyoY4r_3sUsAOvYbEBqdYsocl96aqW_tzO5R-QPMbc9ukvRRkxVfcaXnHV47WLD_YbN0I4i8HdeFTA5gIQVlAh44s61-VDf_Tl8vMdI-mtRUltGN3QACgnBNYnct7uA4ONporAQ/s1600/linked-tables.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 3 (above):&lt;/b&gt; This is how linked tables appear in the &lt;i&gt;Front End&lt;/i&gt; Database file.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyIasHLt9iDZLdaxp3xhjeAW7sV3X91CyA2f73VDIpgzNlOc2zq9a4NPT6lUjgepm9eGgmIMYKJUcm6jcpD8-xnln617v6yS1LwBfP9s6EktKAeZadqs1w2sf5opaa0ga-zL3lXyHVWM/s1600/windows-explorer.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhyIasHLt9iDZLdaxp3xhjeAW7sV3X91CyA2f73VDIpgzNlOc2zq9a4NPT6lUjgepm9eGgmIMYKJUcm6jcpD8-xnln617v6yS1LwBfP9s6EktKAeZadqs1w2sf5opaa0ga-zL3lXyHVWM/s1600/windows-explorer.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 4:&lt;/b&gt;&amp;nbsp; Your Database is now split into two files one for the &lt;i&gt;front end&lt;/i&gt; and one for the &lt;i&gt;back end&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;*Tip: &amp;nbsp;If you want to run more that one Access &lt;i&gt;front end &lt;/i&gt;at a time, you will need to open multiple instances of the Access &lt;i&gt;Database&lt;/i&gt;. &amp;nbsp;So rather than clicking on the access &lt;i&gt;front end&lt;/i&gt; file directly (ie from within Windows Explorer), you should open Microsoft Office Access from the windows START button or DESK TOP and then open each front end file from the GETTING STARTED WITH MICROSOFT OFFICE ACCESS screen. &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/6915515585622883598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/using-access-database-splitter.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6915515585622883598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/6915515585622883598'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/05/using-access-database-splitter.html' title='Using the Access Database Splitter'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTGTH5lD5T8G8KH4zxQaDfk03LPEL3aaJhTp5Om8ffb9q2MZY9ybhHMaffTluyZAZP2u9AtFoPHMF2uCfYewbnXu3NEC3mXtu3NacuyOGd9xTzlPiMAk35zruLQJu6COzWE7RjNDnq2c4/s72-c/database-splitter-icon.JPG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4369839711354764086</id><published>2012-04-27T05:48:00.000-07:00</published><updated>2012-04-27T05:49:38.152-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Access Options"/><category scheme="http://www.blogger.com/atom/ns#" term="forms"/><category scheme="http://www.blogger.com/atom/ns#" term="graphical user interface"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Hiding the Navigation Pane with VBA</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Once you have created an Access Database Application to be used by other people, it may well be important for you to prevent users from gaining access to any of its design features. &amp;nbsp;By this I mean, you may not want users to modify your tables, forms and queries etc in design view (inadvertently or otherwise). &amp;nbsp;There are a number of measures you need to take in order to secure your database against this possibility. &amp;nbsp;One of these involves preventing users from accessing the NAVIGATION PANE, a major doorway to all of your database objects. &amp;nbsp;Hiding the NAVIGATION PANE can be done with a couple of lines of VBA Code.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To use this code, you will need one of your database forms&#39; to open automatically as your application opens. There are instructions to do this in my post on &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/09/how-to-display-form-automatically-when.html&quot; target=&quot;_blank&quot;&gt;How to Display a Form Automatically&lt;/a&gt;.&amp;nbsp;Once this is in place you can insert the following code into that form&#39;s ON LOAD event.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #20124d;&quot;&gt;&lt;b&gt; &lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;DoCmd.SelectObject acTable, &quot;tblCustomer&quot;, True&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; DoCmd.RunCommand acCmdWindowHide&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The purpose of the first line of code is to select &lt;i&gt;any &lt;/i&gt;object in the navigation pane. &amp;nbsp;We have selected one of the database &lt;i&gt;tables &lt;/i&gt;called &lt;b&gt;tblCustomer&lt;/b&gt;, and then set the INNAVIGATIONPANE parameter to &lt;b&gt;true&lt;/b&gt;. &amp;nbsp;Once &amp;nbsp;a database object &lt;i&gt;from the navigation pane &lt;/i&gt;has been selected, we can then use the &lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;b&gt;DoCmd.RunCommand&lt;/b&gt;&lt;/span&gt; with the &lt;b&gt;&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;acCmdWindowHide&lt;/span&gt;&lt;/b&gt; parameter in the following line of code. &amp;nbsp;This has the effect of hiding whichever window happens to contain the selected object.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The user can quite easily get the Navigation Pane back by pressing the &lt;b&gt;F11&lt;/b&gt; Access Special Key (assuming &amp;nbsp;that he or she knows about it), but this facility can be disabled. &amp;nbsp;To do this you will need to deselect the USER ACCESS SPECIAL KEYS check box in the CURRENT DATABASE section of ACCESS OPTIONS, (via the OFFICE button).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Hiding the Navigation Pane alone is &lt;u&gt;not&lt;/u&gt; sufficient to secure a database, but it is one important part of doing so.&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/4369839711354764086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/04/hiding-navigation-pane-with-vba.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4369839711354764086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4369839711354764086'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/04/hiding-navigation-pane-with-vba.html' title='Hiding the Navigation Pane with VBA'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-5507708377044575532</id><published>2012-03-30T02:59:00.000-07:00</published><updated>2012-03-30T02:59:29.383-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DateAdd"/><category scheme="http://www.blogger.com/atom/ns#" term="functions"/><title type='text'>Calculating a Future Date with the DateAdd Function</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
If you read my blog last week you may have seen the sample Lending Library Database that I created to demonstrate a working example of the &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2012/03/dao-recordset-in-action-example-lending.html&quot; target=&quot;_blank&quot;&gt;DAO Recordset&lt;/a&gt;. &amp;nbsp;You may have noticed that I used a function called &lt;b&gt;DateAdd&lt;/b&gt; to calculate the future date that a library book is due for return. &amp;nbsp;As you may remember, this date was automatically entered as the value for the &lt;b&gt;DueDate &lt;/b&gt;field in the &lt;b&gt;tblLoan &lt;/b&gt;junction table via VBA code.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I thought it would be interesting to take a closer look at how the&amp;nbsp;&lt;b&gt;DateAdd &lt;/b&gt;function works. However, please &amp;nbsp;do bear in mind that the DateAdd funciton can also be used in Queries and &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/07/calculated-controls.html&quot; target=&quot;_blank&quot;&gt;Calculated Form Controls&lt;/a&gt; (not just in VBA code). &amp;nbsp;This is how the syntax for &lt;b&gt;DateAdd &lt;/b&gt;is constructed:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;DateAdd(&quot;interval&quot;, number, date)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-aPmcaWmHm7L4GLN4OVUhNoHTQ5qA5-bdATzuxe0J0-MMHcYqV_iZMlwIZzna9AzFti6uHIwXCP8mYeTKixI_YC_ojV4ROhXMCGDnDeQjnZtaG6-7QaBLh6b2EKHX0mJMh347NuvwQjw/s1600/calculated-query-field.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-aPmcaWmHm7L4GLN4OVUhNoHTQ5qA5-bdATzuxe0J0-MMHcYqV_iZMlwIZzna9AzFti6uHIwXCP8mYeTKixI_YC_ojV4ROhXMCGDnDeQjnZtaG6-7QaBLh6b2EKHX0mJMh347NuvwQjw/s1600/calculated-query-field.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1 (above):&lt;/b&gt; This shows the &lt;b&gt;DateAdd&lt;/b&gt; function used&lt;br /&gt;as a &lt;i&gt;Calculated Field&lt;/i&gt; in a Query. &amp;nbsp;You can see an example of a Calculated Field&lt;br /&gt;in my post on the related&amp;nbsp;&lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/08/calculating-date-difference-using.html&quot; target=&quot;_blank&quot;&gt;DateDiff Function&lt;/a&gt;.&amp;nbsp;(NB &lt;b&gt;DateDiff &lt;/b&gt;calculates and returns the &lt;i&gt;difference&amp;nbsp;&lt;/i&gt;between&amp;nbsp;&lt;br /&gt;two dates,&amp;nbsp;whereas &lt;b&gt;DateAdd &lt;/b&gt;calculates and returns a &lt;i&gt;new date&lt;/i&gt; based on the value of the &lt;b&gt;number &lt;/b&gt;parameter passed).&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9Ws7r2kTzpEE2Li-z3AGQesDrW6L6Rjh4ri3zBzxvGK-4J068t0MipbWAkOBaRNLBVz28oMc-WB11u7iXDbmhzxdA5YYW_kAX021TfiretQ_oHcMOeiJQzBWK0J-ma-PAL_2BQwz06CU/s1600/calculated-form-field.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9Ws7r2kTzpEE2Li-z3AGQesDrW6L6Rjh4ri3zBzxvGK-4J068t0MipbWAkOBaRNLBVz28oMc-WB11u7iXDbmhzxdA5YYW_kAX021TfiretQ_oHcMOeiJQzBWK0J-ma-PAL_2BQwz06CU/s1600/calculated-form-field.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Figure 2: This shows the&amp;nbsp;&lt;b&gt;DateAdd&amp;nbsp;&lt;/b&gt;function used as a&amp;nbsp;&lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/07/calculated-controls.html&quot; target=&quot;_blank&quot;&gt;Calculated Control&lt;/a&gt;&amp;nbsp;in a form. &amp;nbsp;It can be entered&lt;br /&gt;into the CONTROL SOURCE&amp;nbsp;property or directly into the text box on the &amp;nbsp;Form Design Grid.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;DateAdd Parameters&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As you can see, the &lt;b&gt;DateAdd &lt;/b&gt;function has three parameters - &lt;i&gt;&lt;b&gt;interval&lt;/b&gt;&lt;/i&gt;, &lt;b&gt;&lt;i&gt;number&lt;/i&gt; &lt;/b&gt;and &lt;i&gt;&lt;b&gt;date&lt;/b&gt;&lt;/i&gt;. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Interval&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The &lt;b&gt;interval &lt;/b&gt;parameter determines whether we are adding intervals of days, weeks, or months etc. &amp;nbsp;The parameter is entered as a string value; &lt;i&gt;days &lt;/i&gt;are entered as &lt;b&gt;&quot;d&quot;&lt;/b&gt;, &lt;i&gt;weeks &lt;/i&gt;as &lt;b&gt;&quot;ww&quot;&lt;/b&gt; and &lt;i&gt;months &lt;/i&gt;as &lt;b&gt;&quot;m&quot;&lt;/b&gt;. &amp;nbsp;There are 10 possible parameter values to choose from, ranging from &lt;i&gt;years &lt;/i&gt;&lt;b&gt;&quot;yyyy&quot;&lt;/b&gt; right down to &lt;i&gt;hours &lt;/i&gt;&lt;b&gt;&quot;h&quot;&lt;/b&gt;, &lt;i&gt;minuets &lt;/i&gt;&lt;b&gt;&quot;n&quot;&lt;/b&gt;, and &lt;i&gt;seconds&lt;/i&gt; &lt;b&gt;&quot;s&quot;&lt;/b&gt;. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Number&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The &lt;b&gt;number &lt;/b&gt;parameter is the number of intervals to be added. &amp;nbsp;So if we want to calculate a date 30 days in the future, we would set the interval to &lt;b&gt;&quot;d&quot;&lt;/b&gt; and the number to &lt;b&gt;30&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Date&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The &lt;b&gt;date &lt;/b&gt;parameter is the base date we are applying the &lt;b&gt;DateAdd &lt;/b&gt;function to. &amp;nbsp;As such, if we want to calculate a date 30 days from 1/4/2012, we would simply enter &lt;b&gt;1/4/2012&lt;/b&gt; as the date parameter value. If you want to calculate a date from today (whatever date that may be on the day you are reading this) you can enter the &lt;b&gt;Date()&lt;/b&gt; function as the actual parameter value. &amp;nbsp;This will return the current date when the database is being run.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Calculating a Library Book Due Date&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is the syntax I used in the last weeks lending library database to calculate a &lt;b&gt;DueDate &lt;/b&gt;30 days from when a book is issued:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #20124d; font-size: large;&quot;&gt;DateAdd (&quot;d&quot;, 30, Date())&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsCmNB-AUQkq3GZZxrmhtpp5H0KAQTLaqO6DYBbZjjsuuo-msJakeJicUztXTFPxL9Mr2cLVANaPAwfPhnhRmPNaYSohia_fzf_cafjLJtBhCdCK6Juxm7PnAz7OYhAPbTIA3hEYv3jOI/s1600/DateAdd-VBA.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsCmNB-AUQkq3GZZxrmhtpp5H0KAQTLaqO6DYBbZjjsuuo-msJakeJicUztXTFPxL9Mr2cLVANaPAwfPhnhRmPNaYSohia_fzf_cafjLJtBhCdCK6Juxm7PnAz7OYhAPbTIA3hEYv3jOI/s1600/DateAdd-VBA.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;b&gt;Figure 3:&amp;nbsp;&lt;/b&gt;This shows the &lt;b&gt;DateAdd&lt;/b&gt; function used in the fourth line of this VBA code snippet.&lt;br /&gt;The &lt;b&gt;rstLoan &lt;/b&gt;object is a DAO Recordset, and &lt;b&gt;DueDate &lt;/b&gt;is the field name in the &lt;b&gt;tblLoans &lt;/b&gt;Table.&lt;br /&gt;You can see the rest of the code in last weeks blog post on the &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2012/03/dao-recordset-in-action-example-lending.html&quot; target=&quot;_blank&quot;&gt;DAO Recordset&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
As you can see, the interval used is &lt;i&gt;days&lt;/i&gt;, the number parameter is &lt;i&gt;30&lt;/i&gt;, and I have used the &lt;b&gt;Date()&lt;/b&gt; function to return the current date for the date parameter.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/5507708377044575532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/03/calculating-future-date-with-dateadd.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/5507708377044575532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/5507708377044575532'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/03/calculating-future-date-with-dateadd.html' title='Calculating a Future Date with the DateAdd Function'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-aPmcaWmHm7L4GLN4OVUhNoHTQ5qA5-bdATzuxe0J0-MMHcYqV_iZMlwIZzna9AzFti6uHIwXCP8mYeTKixI_YC_ojV4ROhXMCGDnDeQjnZtaG6-7QaBLh6b2EKHX0mJMh347NuvwQjw/s72-c/calculated-query-field.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2765750544485099795</id><published>2012-03-23T07:45:00.000-07:00</published><updated>2012-03-23T07:45:45.796-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DAO"/><category scheme="http://www.blogger.com/atom/ns#" term="many to many"/><category scheme="http://www.blogger.com/atom/ns#" term="recordset object"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>The DAO Recordset in Action - An Example Lending Library Database</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
Last week I wrote a post on &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2012/03/accessing-data-with-vba-code.html&quot; target=&quot;_blank&quot;&gt;How to Access Data with VBA Code&lt;/a&gt;. &amp;nbsp;Instrumental in this was the use of the &lt;b&gt;&lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2012/03/accessing-data-with-vba-code.html&quot; target=&quot;_blank&quot;&gt;DAO Recordset&lt;/a&gt;&lt;/b&gt; Object. &amp;nbsp;Through using this object we were able to &lt;i&gt;add&lt;/i&gt;, &lt;i&gt;find&lt;/i&gt;, &lt;i&gt;edit &lt;/i&gt;and &lt;i&gt;delete &lt;/i&gt;records from an Access Database table or query. This week I am going to provide a working example of how the DAO Recordset is used in an actual database application. &amp;nbsp;In order to do this, I have created part of a &lt;b&gt;&lt;a href=&quot;http://www.dealing-with-data.net/exercises/LendingLibrary.accdb&quot; target=&quot;_blank&quot;&gt;Lending Library Database&lt;/a&gt; &lt;/b&gt;for demonstration purposes. This&amp;nbsp;can downloaded by clicking the link.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;The Lending Library Database&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The table at the centre of this database is the &lt;i&gt;Loans &lt;/i&gt;table (&lt;b&gt;jnkLoan&lt;/b&gt;). &amp;nbsp;&amp;nbsp; As you can see from figure 1, it is a junction table (from a &lt;a href=&quot;http://ms-access-tips.blogspot.co.uk/2011/04/many-to-many-relationship.html&quot; target=&quot;_blank&quot;&gt;Many to Many Relationship&lt;/a&gt;) which contains the foreign key from both the &lt;i&gt;Library Users&lt;/i&gt; table (&lt;b&gt;tblLibraryUser&lt;/b&gt;) and the &lt;i&gt;Library Stock&lt;/i&gt; Table (&lt;b&gt;tblLibraryStock&lt;/b&gt;). &amp;nbsp;The purpose of &lt;b&gt;tblLoans &lt;/b&gt;is to store the details of each loan transaction whereby a library user &lt;i&gt;borrows&lt;/i&gt; or &lt;i&gt;returns &lt;/i&gt;an item of library stock. &amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2RCgLnaVNUAN7VZDHbW771Tu958rkxCIIE2FUDK-n2fySVkKkuQwHj2ZZGwm038DZzPo5bcTXckTthk-TzT35t2b3K6Rr5rbOy5SnNmR6iu_UNfwZgnXspleh8dIYYrF7yNHySGzfMRY/s1600/relationships.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2RCgLnaVNUAN7VZDHbW771Tu958rkxCIIE2FUDK-n2fySVkKkuQwHj2ZZGwm038DZzPo5bcTXckTthk-TzT35t2b3K6Rr5rbOy5SnNmR6iu_UNfwZgnXspleh8dIYYrF7yNHySGzfMRY/s1600/relationships.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1: &lt;/b&gt;The table relationships from the &lt;i&gt;Lending Library Database&lt;/i&gt;.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Figure 2 below shows the &lt;b&gt;Library User Account&lt;/b&gt; Form where these loan transactions are made. &amp;nbsp;Transactions are occur when the user enters a number into the ITEM BARCODE text box, and clicks the ISSUE or DISCHARGE command button. &amp;nbsp;&lt;i&gt;This then runs a VBA sub procedure which uses the DAO Recordset to create a loan record in &lt;b&gt;tblLoan&lt;/b&gt;&lt;/i&gt;.&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf3n5N7T0L0ZBy1BH6Q8QZnthaGTxmtWP2n1OaydxarPRxIAUuZ-ryh7kUsx4gtBWvVzCmiMzywkoBFvjIEISxxu017jeJIRZlxb73NR2xP2R87F_S9rqA7ybqXJ3tmS9deCjd5y4Vp3g/s1600/user-account-form.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;352&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf3n5N7T0L0ZBy1BH6Q8QZnthaGTxmtWP2n1OaydxarPRxIAUuZ-ryh7kUsx4gtBWvVzCmiMzywkoBFvjIEISxxu017jeJIRZlxb73NR2xP2R87F_S9rqA7ybqXJ3tmS9deCjd5y4Vp3g/s640/user-account-form.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 2: &lt;/b&gt;The &lt;b&gt;User Account &lt;/b&gt;form. Library items are &lt;i&gt;issued &lt;/i&gt;and &lt;i&gt;discharged &lt;/i&gt;from here.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The &lt;b&gt;User Account Form&lt;/b&gt; also has an&amp;nbsp;&lt;b&gt;On Loan&lt;/b&gt; subform to list items out on loan to the library user. &amp;nbsp;The RECORD SOURCE for this subform is &lt;b&gt;qryLoansSub&lt;/b&gt;, and contains fields from the &lt;b&gt;jnkLoan&lt;/b&gt;, &lt;b&gt;tblLibraryStock&lt;/b&gt;, and &lt;b&gt;tblBook &lt;/b&gt;tables. &amp;nbsp;There is a criteria value of &lt;b&gt;Is Null&lt;/b&gt;&amp;nbsp;on the &lt;b&gt;ReturnDate &lt;/b&gt;field. &amp;nbsp;As such, any loan transaction without a &lt;b&gt;ReturnDate &lt;/b&gt;(belonging to the &lt;b&gt;UserBarcode &lt;/b&gt;from the parent form) is listed as being&amp;nbsp;&lt;b&gt;On Loan&lt;/b&gt;. &amp;nbsp;Moreoever, the VBA code initiated by the ISSUE and DISCHARGE buttons ends with a line to requery the subform. &amp;nbsp;This ensures the subform updates as soon as a stock item is &lt;i&gt;issued &lt;/i&gt;or &lt;i&gt;discharged&lt;/i&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Issuing an Item&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So lets have a look at the VBA code which runs when the ISSUE button is clicked:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;Private Sub cmdIssue_Click()&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;On Error GoTo trapError&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Dim rstLoan As DAO.Recordset&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If IsNull(DLookup(&quot;StockBarcode&quot;, &quot;tblLibraryStock&quot;, &quot;StockBarcode = &quot; &amp;amp; Me!txtIssueBarcode)) = True Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox &quot;Sorry - Barcode Does Not Exist&quot;, vbInformation, &quot;Invalid Barcode&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GoTo leave&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Else&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set rstLoan = CurrentDb.OpenRecordset(&quot;jnkLoan&quot;, dbOpenDynaset)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.FindLast &quot;StockBarcodeFK = &quot; &amp;amp; Me!txtIssueBarcode&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If rstLoan.NoMatch = False Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If IsNull(rstLoan!returndate) = True Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox &quot;Book Is Already On Loan. &amp;nbsp;Please discharge before Issuing.&quot;, vbExclamation, &quot;Already On Loan&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GoTo leave&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.AddNew&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!StockBarcodeFK = Me!txtIssueBarcode&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!UserBarcodeFK = Me!UserBarcode&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!IssueDate = Date&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!DueDate = DateAdd(&quot;d&quot;, 30, Date)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.Update&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me!subOnLoan.Requery&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me!txtIssueBarcode = Null&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DoCmd.GoToControl &quot;txtissuebarcode&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;leave:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If Not rstLoan Is Nothing Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.Close: Set rstLoan = Nothing&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Exit Sub&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;trapError:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; MsgBox &quot;Error &quot; &amp;amp; Err.Number &amp;amp; &quot;: &quot; &amp;amp; Error$&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Resume leave&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
The code begins by checking that the item barcode actually exists, and is not, therefore, a data entry error. This is done using the &lt;b&gt;DLookUp &lt;/b&gt;function on the &lt;b&gt;StockBarcode &lt;/b&gt;field of &lt;b&gt;tblLibaryStock&lt;/b&gt;. &amp;nbsp;If it does not exist, a warning message is displayed, and the sub procedure comes to an end. &amp;nbsp;If it &lt;i&gt;does &lt;/i&gt;exist, the code continues to open a &lt;i&gt;DAO Recordset object&lt;/i&gt; based on &lt;b&gt;jnkLoan&lt;/b&gt;. &amp;nbsp;This is then searched using the FINDLAST method of the recordset object to find the most recent transaction involving that particular item. &amp;nbsp;If a record is found, the &lt;b&gt;ReturnDate &lt;/b&gt;value is checked to make sure the item is not&lt;i&gt; recorded &lt;/i&gt;as &lt;i&gt;already &lt;/i&gt;being&amp;nbsp;&lt;i&gt;on loan &lt;/i&gt;(it is an not an uncommon human error for some items to be shelved without first being discharged). &amp;nbsp;If the item is recorded as being &lt;i&gt;On Loan &lt;/i&gt;&amp;nbsp;an error message is displayed asking the staff member to discharge the book before re-issuing. &amp;nbsp;The procedure then comes to an end. &amp;nbsp;If there had not been a previous transaction for that item, or if the previous transaction has a &lt;b&gt;ReturnDate &lt;/b&gt;value, the code continues to create a new record in &lt;b&gt;jnkLoan&lt;/b&gt;. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The following block of code (a section extracted from the main code above) is where the new record is created:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp;rstLoan.AddNew&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!StockBarcodeFK = Me!txtIssueBarcode&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!UserBarcodeFK = Me!UserBarcode&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!IssueDate = Date&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!DueDate = DateAdd(&quot;d&quot;, 30, Date)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; rstLoan.Update&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here the &lt;b&gt;AddNew &lt;/b&gt;method of the &lt;b&gt;Recordset &lt;/b&gt;Object is called to create the new record. &amp;nbsp;Then the &lt;b&gt;StockBarcodeFK &lt;/b&gt;field is set to the value of the &lt;b&gt;Item Barcode &lt;/b&gt;textbox; the &lt;b&gt;UserBarcodeFK &lt;/b&gt;field is set to the value of the &lt;b&gt;UserBarcode &lt;/b&gt;on the &lt;b&gt;User Account Form&lt;/b&gt;; the &lt;b&gt;IssueDate &lt;/b&gt;field is set to the current date via the &lt;b&gt;Date &lt;/b&gt;function; and the &lt;b&gt;DueDate &lt;/b&gt;field&amp;nbsp;is set to &lt;i&gt;30 days&lt;/i&gt; from the &lt;i&gt;current date&lt;/i&gt; via the &lt;b&gt;DateAdd &lt;/b&gt;function. &amp;nbsp;The changes made to the &lt;b&gt;rstLoan Recordset&lt;/b&gt; are&amp;nbsp;then saved back to &lt;b&gt;tblLoan &lt;/b&gt;via the recordset object&#39;s&amp;nbsp;&lt;b&gt;Update&amp;nbsp;&lt;/b&gt;method.&amp;nbsp;Finally the code re-queries the &lt;b&gt;OnLoan &lt;/b&gt;subform, puts the focus back on the &lt;b&gt;Item Barcode&lt;/b&gt; textbox, and closes the recordset.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Discharging an Item&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
The sub procedure which runs when a book is discharged is very similar. &amp;nbsp;The main difference is that rather than creating a new loan transaction record, the last loan transaction record is found, and then&amp;nbsp;&lt;i&gt;edited&lt;/i&gt;&amp;nbsp;by putting the current date in the&amp;nbsp;&lt;b&gt;ReturnDate &lt;/b&gt;field. &amp;nbsp;&amp;nbsp;Here is the discharge code:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;Private Sub cmdDischarge_Click()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;On Error GoTo trapError&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Dim rstLoan As DAO.Recordset&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If IsNull(DLookup(&quot;StockBarcode&quot;, &quot;tblLibraryStock&quot;, &quot;StockBarcode = &quot; &amp;amp; Me!txtIssueBarcode)) = True Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox &quot;Sorry - Barcode Does Not Exist&quot;, vbInformation, &quot;Invalid Barcode&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GoTo leave&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Else&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set rstLoan = CurrentDb.OpenRecordset(&quot;jnkLoan&quot;, dbOpenDynaset)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.FindLast &quot;StockBarcodeFK = &quot; &amp;amp; Me!txtIssueBarcode&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If rstLoan.NoMatch = False Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If IsNull(rstLoan!returndate) = False Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox &quot;Book Not On Loan.&quot;, vbExclamation, &quot;Already On Loan&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GoTo leave&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.Edit&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan!returndate = Date&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.Update&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me!subOnLoan.Requery&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me!txtIssueBarcode = Null&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DoCmd.GoToControl &quot;txtissuebarcode&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;leave:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If Not rstLoan Is Nothing Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstLoan.Close: Set rstLoan = Nothing&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Exit Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;trapError:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; MsgBox &quot;Error &quot; &amp;amp; Err.Number &amp;amp; &quot;: &quot; &amp;amp; Error$&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Resume leave&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you would like to try all this out, please feel free to download the sample &lt;b&gt;&lt;a href=&quot;http://www.dealing-with-data.net/exercises/LendingLibrary.accdb&quot; target=&quot;_blank&quot;&gt;Lending Library Database&lt;/a&gt;.&lt;/b&gt;&amp;nbsp;You can view a list of library item barcodes to work with by clicking the LIBRARY STOCK command button at the top of the User Account Form.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/2765750544485099795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/03/dao-recordset-in-action-example-lending.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2765750544485099795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/2765750544485099795'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/03/dao-recordset-in-action-example-lending.html' title='The DAO Recordset in Action - An Example Lending Library Database'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2RCgLnaVNUAN7VZDHbW771Tu958rkxCIIE2FUDK-n2fySVkKkuQwHj2ZZGwm038DZzPo5bcTXckTthk-TzT35t2b3K6Rr5rbOy5SnNmR6iu_UNfwZgnXspleh8dIYYrF7yNHySGzfMRY/s72-c/relationships.JPG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4571149434548631087</id><published>2012-03-16T09:54:00.000-07:00</published><updated>2012-03-23T02:38:51.615-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DAO"/><category scheme="http://www.blogger.com/atom/ns#" term="data access"/><category scheme="http://www.blogger.com/atom/ns#" term="recordset object"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><title type='text'>Accessing Data with VBA Code - Introducing the DAO Recordset</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
This post is all about how we can use VBA code to access the data stored in our database. &amp;nbsp;By access, I mean, being able to &lt;i&gt;add&lt;/i&gt;, &lt;i&gt;find&lt;/i&gt;, &lt;i&gt;edit&amp;nbsp;&lt;/i&gt;or &lt;i&gt;delete &lt;/i&gt;records. &amp;nbsp;In so doing we are effectively automating data access thereby enabling us to create some very powerful database applications.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Creating a Reference&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To do this we are going to make use of &lt;b&gt;Data Access Objects (DAO)&lt;/b&gt; which is contained in the&amp;nbsp;&lt;b&gt;Microsoft Office 12 Access database engine Object Library&lt;/b&gt;. &amp;nbsp;The very first thing we must do is create a reference to this library if it does not already exist. &amp;nbsp;The procedure for doing this is really quite simple:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Open the VBA Editor.&lt;/li&gt;
&lt;li&gt;Open the TOOLS menu.&lt;/li&gt;
&lt;li&gt;Select REFERENCES from the TOOLS menu.&lt;/li&gt;
&lt;li&gt;When the REFERENCES dialog form opens, check to see whether &lt;b&gt;Microsoft Office 12 Access database engine Object Library &lt;/b&gt;has a tick against it. &amp;nbsp;If it has it should be towards the top of the list (all checked references appear above the others, and those that are not, appear in alphabetical order below).&lt;/li&gt;
&lt;li&gt;If the library mentioned in stage 4 is &lt;u&gt;not&lt;/u&gt; ticked, you will need to scroll down the list to find it, and then tick the check box.&lt;/li&gt;
&lt;li&gt;Click OK to close the dialog form.&lt;/li&gt;
&lt;/ol&gt;
The reference has been created and you are now ready to start using &lt;i&gt;Data Access Objects&lt;/i&gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Introducing the DAO Recordset&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The DAO Recordset is basically a VBA object which enables us to gain access to information stored in database tables or queries via code. &amp;nbsp;It is VBA&#39;s representation of the table or query, and we make use of the methods and properties of the DAO Recordset to manipulate the data that it contains.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The first coding task we have to perform is to create an instance of the recordset object. &amp;nbsp;This is then stored as an &lt;i&gt;object variable&lt;/i&gt;. We do this with the following line of code:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;Dim rstNameList as DAO.Recordset&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This creates an object variable called &lt;b&gt;rstNameList&lt;/b&gt;. &amp;nbsp;&amp;nbsp; Our the next task is to set the value of &amp;nbsp;this object variable. This effectively means that we are setting&amp;nbsp;
&lt;b&gt;rstNameList&lt;/b&gt;&amp;nbsp;to represent a particular table or query in our database. &amp;nbsp;This is done as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Set rstNameList = Application.CurrentDb.OpenRecordset(&quot;tblNames&quot;, dbOpenDynaset)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This line of code sets the value of object variable &lt;b&gt;rstNameList &lt;/b&gt;to a DAO Recordset based on a table called &lt;b&gt;tblNames&lt;/b&gt;. &amp;nbsp;This is done by using the &lt;b&gt;OpenRecordset &lt;/b&gt;method of the &lt;b&gt;Recordset &lt;/b&gt;Object. &amp;nbsp;This is applied against an object reference to the current database - hence our use of the &lt;b&gt;CurrentDb &lt;/b&gt;method of the &lt;b&gt;Application &lt;/b&gt;object preceding &lt;b&gt;OpenRecordset&lt;/b&gt;. &amp;nbsp;Don&#39;t worry if this sounds confusing, just remember to enter the name of your table or query as the first parameter of the &lt;b&gt;OpenRecordset &lt;/b&gt;method. &amp;nbsp;The second parameter, &lt;b&gt;dbOpenDynaset &lt;/b&gt;simply opens the recordset as a Dynaset type (which is a particularly versatile type). &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We can now apply the methods and properties of the Recordset class against the object variable&amp;nbsp;&lt;b&gt;rstNameList&lt;/b&gt;.&amp;nbsp;As we do so, remember that they are acting on a virtual representation of the database table or query being used. &amp;nbsp;Lets look at how we can add a record to our table via &lt;b&gt;rstNameList&lt;/b&gt;:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Adding Records&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Imagine our table is comprised of four fields: &lt;b&gt;Id&lt;/b&gt;, &lt;b&gt;FirstName&lt;/b&gt;, &lt;b&gt;Surname&lt;/b&gt;, and &lt;b&gt;DOB &lt;/b&gt;(ie date of birth). &amp;nbsp;This is the data our table currently holds:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1gyXR-Ekq2rEFX9CD0pk4KcfN6TGcfDCl_bk0hu0cAk7H_oxcQeBVXb-gW_Jfq9gAYBSB7EYiukc5jrJL4sVtNPoZrIUD5Esc9DVaXk04IZ_BmyecJmLtEOOYMrEpDz4cP5QtltWwF_Y/s1600/table-data.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1gyXR-Ekq2rEFX9CD0pk4KcfN6TGcfDCl_bk0hu0cAk7H_oxcQeBVXb-gW_Jfq9gAYBSB7EYiukc5jrJL4sVtNPoZrIUD5Esc9DVaXk04IZ_BmyecJmLtEOOYMrEpDz4cP5QtltWwF_Y/s1600/table-data.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 1:&lt;/b&gt; Table data from &lt;b&gt;tblNames&lt;/b&gt;. &lt;br /&gt;
The &lt;b&gt;rstNameList &lt;/b&gt;Recordset Object is based on this table.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The following code is designed to add a new record for a person called &lt;i&gt;Graham Bell&lt;/i&gt;:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Private Sub cmdAdd_Click()&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Dim rstNameList As DAO.Recordset&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Set rstNameList = Application.CurrentDb.OpenRecordset(&quot;tblNames&quot;, dbOpenDynaset)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rstNameList.AddNew&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList!FirstName = &quot;Graham&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList!Surname = &quot;Bell&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList!DOB = #7/10/1970#&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rstNameList.Update&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If Not rstNameList Is Nothing Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList.Close: Set rstNameList = Nothing&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Lets go through this:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This code is triggered when a command button called &lt;b&gt;cmdAdd &lt;/b&gt;is clicked by the user. &amp;nbsp;The code then declares an object variable called &lt;b&gt;rstNameList &lt;/b&gt;which is subsequently set to a Recordset based on &lt;b&gt;tblNames&lt;/b&gt;. &amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The central block of code calls the &lt;b&gt;AddNew &lt;/b&gt;method of the &lt;b&gt;Recordset&lt;/b&gt; object. &amp;nbsp;This basically signals that a new record is going to be added to the recordset. &amp;nbsp;The next three lines reference the &lt;b&gt;FirstName&lt;/b&gt;, &lt;b&gt;Surname &lt;/b&gt;and &lt;b&gt;DOB &lt;/b&gt;fields, setting their values respectively. &amp;nbsp;As such the &lt;b&gt;FirstName &lt;/b&gt;field value is set to &quot;&lt;b&gt;Graham&lt;/b&gt;&quot;, Surname to &quot;&lt;b&gt;Bell&lt;/b&gt;&quot;, and &lt;b&gt;DOB &lt;/b&gt;to &lt;b&gt;7/10/1970&lt;/b&gt;. &amp;nbsp;Note the &lt;b&gt;FirstName &lt;/b&gt;and &lt;b&gt;Surname &lt;/b&gt;fields are of the STRING data type, so are consequently enclosed within &lt;i&gt;quotation &lt;/i&gt;marks ie &quot;&quot;; whereas the &lt;b&gt;DOB &lt;/b&gt;field is of the DATE data type so is enclosed between &lt;i&gt;hash &lt;/i&gt;marks using the American Date Format ie #mm/dd/yyyy#. (Had we used the number data type this would not have needed to be enclosed by anything). Finally the central block of code saves the new record by calling the &lt;b&gt;Update &lt;/b&gt;method of the Recordset object.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The final block of code simply closes the recordset object and destroys the object variable reference so as not to use unnecessary memory.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can now go back to the original table &lt;b&gt;tblNames,&amp;nbsp;&lt;/b&gt;and click Refresh to see the new record:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0Zdovye7NLSK5a8EKsrHQcVxphVUtLSz8OiLbNr8gS72H3qTm0QDHcXlIFOkGOYUiSohKmdpOvPRvPKLGIfH6gZfGHOw8gTs1sKZfzMfsXGZqRc057onkWVzP7hrnn6iFW5U6WqpCn4Q/s1600/new-record.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0Zdovye7NLSK5a8EKsrHQcVxphVUtLSz8OiLbNr8gS72H3qTm0QDHcXlIFOkGOYUiSohKmdpOvPRvPKLGIfH6gZfGHOw8gTs1sKZfzMfsXGZqRc057onkWVzP7hrnn6iFW5U6WqpCn4Q/s1600/new-record.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Figure 2: The&amp;nbsp;&lt;b&gt;tblNames &lt;/b&gt;table&lt;b&gt;&amp;nbsp;&lt;/b&gt;after new record is &lt;i&gt;added &lt;/i&gt;via VBA Code.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
As you can see, the new record has been added at the bottom of the table. &amp;nbsp;Note that we did not need to set the value of the ID field as this is of the AUTONUMBER data type and is added by Access automatically.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Editing Records&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The code for updating a particular record is very similar to the central block of code in the in the previous example. &amp;nbsp;The main difference is, however, that we must find the record prior to making any changes. &amp;nbsp;To do this we are going to use the &lt;b&gt;FindFirst &lt;/b&gt;method of the Recordset object. &amp;nbsp;The syntax for this is as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp;rstNameList.FindFirst &quot;Id = 5&quot;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Notice that this method passes the parameter &quot;Id = 5&quot;. &amp;nbsp;This is basically an SQL WHERE clause without the WHERE keyword. &amp;nbsp;It tells access to find the first record in the recordset where the value of the ID field is 5. &amp;nbsp;There is more information on SQL Where in my &lt;a href=&quot;http://ms-access-tips.blogspot.com/2011/05/gentle-introduction-to-access-sql.html&quot; target=&quot;_blank&quot;&gt;Gentle Introduction to Access SQL&lt;/a&gt;. Just remember that the parameter must be enclosed within quotation marks, so if the value searched for is itself a string, you must not only enclose the parameter within quotation marks ie &quot;&quot;, but you must also enclose the actual value to be found within single quotation marks ie &#39; &#39;. For example if you wanted to search for the surname &lt;b&gt;Lang&lt;/b&gt;, the syntax would be:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;rstNameList.FindFirst &quot;Surname = &#39;Lang&#39; &quot;&lt;/b&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
It is also possible to test whether a record has actually been found using the &lt;b&gt;NoMatch &lt;/b&gt;property of the Recordset object as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;If rstNameList.NoMatch = false Then&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/b&gt;.... code to run if record is found.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Else&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;....code to run if no record is found.&amp;nbsp;&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;End if&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Once we have found the record, we can then go on to edit any, or all, of its fields. &amp;nbsp;This is done with the following code:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;rstNameList.Edit&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList!DOB = #8/10/1970#&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;rstNameList.Update&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Notice how we have used the &lt;b&gt;Edit &lt;/b&gt;method of the &lt;b&gt;Recordset &lt;/b&gt;object instead of &lt;b&gt;AddNew&lt;/b&gt;. &amp;nbsp;The rule is use &lt;b&gt;Edit &lt;/b&gt;if you want to edit an &lt;i&gt;existing &lt;/i&gt;record, and use &lt;b&gt;AddNew &lt;/b&gt;if you want to create a &lt;i&gt;new &lt;/i&gt;record. &amp;nbsp;Once the record has been edited it needs to be saved using the &lt;b&gt;Update &lt;/b&gt;method as before. &amp;nbsp;So lets look at the whole code snippet:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Dim rstNameList As DAO.Recordset&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Set rstNameList = Application.CurrentDb.OpenRecordset(&quot;tblNames&quot;, dbOpenDynaset)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rstNameList.FindFirst &quot;Id=5&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If rstNameList.NoMatch = False Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList.Edit&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList!dob = #8/10/1970#&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rstNameList.Update&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;If Not rstNameList Is Nothing Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rstNameList.Close: Set rstNameList = Nothing&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If we refresh the data in &lt;b&gt;tblNames&lt;/b&gt;, you can see that our code has put a DOB value in Sally Lang&#39;s record:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEgwrjo3zU9bbkt8NrSbWLYlKloZEOTCXz0EaafrbQexmg35MutROrYuyaU0qiEzuo5YENB_xg5Jf9nUgAI8tuHHoZsNtGjDtIZWG0AIF5qmJmyX5D92p_fsoHqlAsdYtvXJGBIBk3vYo/s1600/edit-record.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEgwrjo3zU9bbkt8NrSbWLYlKloZEOTCXz0EaafrbQexmg35MutROrYuyaU0qiEzuo5YENB_xg5Jf9nUgAI8tuHHoZsNtGjDtIZWG0AIF5qmJmyX5D92p_fsoHqlAsdYtvXJGBIBk3vYo/s1600/edit-record.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 3:&lt;/b&gt; The record of &lt;b&gt;Sally Lang&lt;/b&gt; (ID &lt;b&gt;5&lt;/b&gt;) now has a &lt;b&gt;DOB &lt;/b&gt;value &lt;br /&gt;
after her record was &lt;i&gt;edited &lt;/i&gt;with our code.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Deleting Records&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
When it comes to deleting a record, we start by finding the particular record that we want to delete. &amp;nbsp;Again this is achieved using the &lt;b&gt;FindFirst &lt;/b&gt;method of the &lt;b&gt;Recordset &lt;/b&gt;Object. &amp;nbsp;So suppose we wanted to delete Graham Bell&#39;s record, we could do a &lt;b&gt;FindFirst &lt;/b&gt;search on his record ID which is 8.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;color: #20124d; font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;rstNameList.FindFirst &quot;Id = 8&quot;&lt;/b&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
All we do then is apply the &lt;b&gt;Delete &lt;/b&gt;method of the &lt;b&gt;Recordset &lt;/b&gt;Object as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;rstNameList.Delete&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Again, it is a good idea to nest the above line in an &lt;b&gt;If ...Then... Else&lt;/b&gt; statement to test that a matching record has been found. &amp;nbsp;As such the full code to delete record 8 is as follows:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Dim rstNameList As DAO.Recordset&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Set rstNameList = Application.CurrentDb.OpenRecordset(&quot;tblNames&quot;, dbOpenDynaset)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;rstNameList.FindFirst &quot;Id=8&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;If rstNameList.NoMatch = False Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rstNameList.Delete&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;Else&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; MsgBox &quot;Record Not Found&quot;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;If Not rstNameList Is Nothing Then&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; rstNameList.Close: Set rstNameList = Nothing&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #20124d; font-family: Times,&#39;Times New Roman&#39;,serif;&quot;&gt;&lt;b&gt;End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The record has now been removed from the table:&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAbtVL-vEvsD-IZMroLKwT_ssDzuRZqPqL38ptYESlSUFHY1MiVwO-CAkAI7mDCsQvXMZwr1cYe6lCL6lfDU8RVQEJNl6tl7TmPgdA_YLe_62203t64iTvKcyIRqsda7Gz7yA8_O_NV90/s1600/deleted-record.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAbtVL-vEvsD-IZMroLKwT_ssDzuRZqPqL38ptYESlSUFHY1MiVwO-CAkAI7mDCsQvXMZwr1cYe6lCL6lfDU8RVQEJNl6tl7TmPgdA_YLe_62203t64iTvKcyIRqsda7Gz7yA8_O_NV90/s1600/deleted-record.JPG&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;Figure 4:&lt;/b&gt; Our code has &lt;i&gt;deleted &lt;/i&gt;the intended record.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
These have all been basic examples to demonstrate how we can access and manipulate data using VBA code. &amp;nbsp;How we use the Recordset object in a real database application depends entirely on what needs doing. I have found the possible uses of the DAO Recordset to be virtually endless. It is an extremely &amp;nbsp; powerful tool to draw upon when needed. &amp;nbsp;As such, I hope to show some applied examples of its possible uses in a future post.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-access-tips.blogspot.com/feeds/4571149434548631087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ms-access-tips.blogspot.com/2012/03/accessing-data-with-vba-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4571149434548631087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/777975398841809391/posts/default/4571149434548631087'/><link rel='alternate' type='text/html' href='http://ms-access-tips.blogspot.com/2012/03/accessing-data-with-vba-code.html' title='Accessing Data with VBA Code - Introducing the DAO Recordset'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1gyXR-Ekq2rEFX9CD0pk4KcfN6TGcfDCl_bk0hu0cAk7H_oxcQeBVXb-gW_Jfq9gAYBSB7EYiukc5jrJL4sVtNPoZrIUD5Esc9DVaXk04IZ_BmyecJmLtEOOYMrEpDz4cP5QtltWwF_Y/s72-c/table-data.jpg" height="72" width="72"/><thr:total>0</thr:total></entry></feed>