<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"><id>tag:blogger.com,1999:blog-777975398841809391</id><updated>2012-02-26T08:36:57.687-08:00</updated><category term="access screen" /><category term="external data" /><category term="dialog" /><category term="SQL" /><category term="MS Access" /><category term="summary data" /><category term="subform" /><category term="many to many" /><category term="database objects" /><category term="import" /><category term="events" /><category term="not in list" /><category term="relationships" /><category term="functions" /><category term="export" /><category term="enabled" /><category term="outer join" /><category term="If Then Else" /><category term="query" /><category term="Append Query" /><category term="sum" /><category term="GUI" /><category term="tables" /><category term="dLookUp" /><category term="one to many relationship" /><category term="inner join" /><category term="forms" /><category term="Immediate Window" /><category term="Quick Tip" /><category term="LIKE operator" /><category term="Action Query" /><category term="calculated field" /><category term="intermediate" /><category term="DAO" /><category term="MS Excel" /><category term="record source" /><category term="access tip" /><category term="Update Query" /><category term="reports" /><category term="primary key" /><category term="group by" /><category term="DateDiff" /><category term="Loops" /><category term="client/server" /><category term="tutorial" /><category term="Controls" /><category term="table relationships" /><category term="graphical user interface" /><category term="intermediate tip" /><category term="Crosstab Query" /><category term="advanced" /><category term="text box" /><category term="properties" /><category term="filters" /><category term="VBA" /><category term="expressions" /><category term="DSum" /><category term="calculated control" /><category term="linking" /><category term="Conditional Formatting" /><category term="design" /><category term="parameter" /><category term="Debug" /><category term="combo box" /><category term="Access Options" /><category term="IIf" /><category term="wildcard" /><category term="DatePart" /><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="alternate" type="text/html" href="http://ms-access-tips.blogspot.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>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>50</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/MicrosoftAccessTips" /><feedburner:info uri="microsoftaccesstips" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-1346812487488732089</id><published>2012-02-24T02:44:00.000-08:00</published><updated>2012-02-24T02:44:25.773-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="calculated field" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="many to many" /><category scheme="http://www.blogger.com/atom/ns#" term="relationships" /><category scheme="http://www.blogger.com/atom/ns#" term="reports" /><title type="text">Using Calculated Fields in Queries</title><content type="html">&lt;div style="text-align: justify;"&gt;Queries play an important part (in relational database design) in pulling information from different tables together. Consider the &lt;a href="http://ms-access-tips.blogspot.com/2011/04/many-to-many-relationship.html" target="_blank"&gt;Many to Many relationship&lt;/a&gt; at the centre of an Order Management System. &amp;nbsp;Here we have three tables - &lt;b&gt;Orders&lt;/b&gt;, &lt;b&gt;Order Details&lt;/b&gt; and &lt;b&gt;Products&lt;/b&gt;. &amp;nbsp;When we come to create the record source for the &lt;i&gt;order items&lt;/i&gt; section of the invoice report, &amp;nbsp;it is necessary to get data regarding an order items &lt;i&gt;quantity &lt;/i&gt;from the &lt;b&gt;Order Details&lt;/b&gt; table, and that of product c&lt;i&gt;ost per unit&amp;nbsp;&lt;/i&gt;from the &lt;b&gt;Products Table&lt;/b&gt;. Then it is the &lt;b&gt;OrderId&lt;/b&gt; from the &lt;b&gt;Orders&lt;/b&gt; Table which groups all &lt;b&gt;Order Details&lt;/b&gt; records into a single order.&lt;br /&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;a href="http://3.bp.blogspot.com/-YSAjyMs_0kY/T0aMMkhGnMI/AAAAAAAAAso/IjXixlUYqKA/s1600/Many-To-Many-Relationship-Structure.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-YSAjyMs_0kY/T0aMMkhGnMI/AAAAAAAAAso/IjXixlUYqKA/s1600/Many-To-Many-Relationship-Structure.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="font-size: 13px;"&gt;&lt;b&gt;Figure 1 (above):&lt;/b&gt; &amp;nbsp;A simplified example of a &lt;i&gt;Many to Many Relationship&lt;/i&gt; from an Order Management Database.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-llbKEVFq43c/T0df1gwazgI/AAAAAAAAAtA/ZkqzgSN7YE0/s1600/invoice-report.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="601" src="http://4.bp.blogspot.com/-llbKEVFq43c/T0df1gwazgI/AAAAAAAAAtA/ZkqzgSN7YE0/s640/invoice-report.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;A sample Invoice Report taken from one of my Order Management Database designs. &lt;br /&gt;The &lt;b&gt;Order Items&lt;/b&gt; Section is located in the middle of the report. &amp;nbsp;&lt;b&gt;CostPerUnit &lt;/b&gt;is &lt;br /&gt;displayed here as &lt;b&gt;Unit Cost&lt;/b&gt; and &lt;b&gt;Amount &lt;/b&gt;as &lt;b&gt;Total&lt;/b&gt;. &amp;nbsp;This &amp;nbsp;section contains&lt;br /&gt;details of each individual order item which,&amp;nbsp;taken together, &lt;br /&gt;makes up&amp;nbsp;the whole order.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As well as bringing information together in this way, query's play another important role in as much as they are commonly used to calculate and process information from these tables. &amp;nbsp;This may be done by means of a &lt;i&gt;Calculated Field&lt;/i&gt;. &amp;nbsp;This is basically a new query column, the values of which being derived from some calculation or expression. &amp;nbsp;As such, we are effectively creating new data for our database. &amp;nbsp;So why is this important? &amp;nbsp;Well, consider the Order Management Database Invoice mentioned earlier. &amp;nbsp;As already stated, the &lt;b&gt;Order Details&lt;/b&gt; table contains data pertaining to an order items &lt;i&gt;quantity&lt;/i&gt;, and the &lt;b&gt;Products &lt;/b&gt;table to an items &lt;i&gt;Cost Per Unit&lt;/i&gt;. &amp;nbsp;There is nowhere in a well designed ('normalised') database where we &lt;i&gt;store &lt;/i&gt;the total of &lt;i&gt;quantity*cost per unit&lt;/i&gt;. It is considered good practice to &lt;i&gt;calculate &lt;/i&gt;this information (so we avoid storing unnecessary data which uses extra memory, and makes the database less efficient and user friendly). &amp;nbsp;The &lt;i&gt;Calculated Field &lt;/i&gt;used in a query is a common way of doing this.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Creating a calculated field is really quite easy. &amp;nbsp;Rather selecting a table field on the top row of the query design grid, we manually type the name (or &lt;i&gt;alias&lt;/i&gt;), followed by a colon, then followed by the calculation or expression. &amp;nbsp;So if we wanted to create a calculated field to process &lt;i&gt;quantity &lt;/i&gt;* &lt;i&gt;cost per unit&lt;/i&gt;, we would use this syntax:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Amount: [Quantity]*[CostPerUnit]&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;I should point out that the alias used here - ie &lt;b&gt;Amount -&amp;nbsp;&lt;/b&gt;is entirely arbitrary text chosen by the database developer. It is, however, good practice to make it something meaningful in order to make it easier for the developer to understand at a later point in time.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Let look at how this fits in with the rest of the query:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-3U7ETYZKC4U/T0aWEyB8-MI/AAAAAAAAAs4/uLoaZAWjbrU/s1600/calculated-field.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-3U7ETYZKC4U/T0aWEyB8-MI/AAAAAAAAAs4/uLoaZAWjbrU/s1600/calculated-field.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3: &lt;/b&gt;Query with Calculated Field on the right.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As you can see the query contains a mixture of fields from all three tables involved in the many to many relationship. &amp;nbsp;The Calculated Field has been added to the column on the right. &amp;nbsp;You may have noticed that the calculated field looks slightly more complicated than the syntax I wrote earlier in the post. &amp;nbsp;This is because we are also specifying the table name as well as the field name. &amp;nbsp;As such:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;[tblOrderDetails].[Quantity]&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: inherit;"&gt;... refers to the &lt;b&gt;Quantity &lt;/b&gt;field of &lt;b&gt;tblOrderDetails&lt;/b&gt;, and:&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-family: inherit;"&gt;&amp;nbsp;&lt;/span&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;[tblProducts].[CostPerUnit]&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;... refers to the &lt;b&gt;CostPerUnit &lt;/b&gt;field of &lt;b&gt;tblProducts&lt;/b&gt;. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;It is essential to write the full reference in this way if any tables or sub-queries involved in the query contain duplicated field names. &amp;nbsp;Although this is not the case in this example, it does no harm to get into the habit of writing the full syntax anyway.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;And this is the output from the query showing the result of the calculated field on the right:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-F_H1YEGWmAY/T0aUd2KzMcI/AAAAAAAAAsw/zdwt-0JRBYM/s1600/item-totals.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-F_H1YEGWmAY/T0aUd2KzMcI/AAAAAAAAAsw/zdwt-0JRBYM/s1600/item-totals.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: &lt;/b&gt;The Query Output.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Since this query has an ID field corresponding to &lt;b&gt;tblOrder.OrderId&lt;/b&gt;, it can now be used as the record source for the &lt;i&gt;Order Items&lt;/i&gt; section of an Invoice Report or Orders Subform. &amp;nbsp;To do this the LINK MASTER FIELDS property of the subform is set to &lt;b&gt;ID&lt;/b&gt; and the LINK CHILD FIELDS is set to &lt;b&gt;OrderId&lt;/b&gt;. &amp;nbsp;There is then the matter of creating the record source for the main section of the invoice report or orders form (this also involves creating Calculated Fields to get the Order Totals). &amp;nbsp;Unfortunately this goes beyond the scope of this particular post.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-1346812487488732089?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yTaiIw1zHUZ6FLt9AiRVn6TEQ54/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yTaiIw1zHUZ6FLt9AiRVn6TEQ54/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yTaiIw1zHUZ6FLt9AiRVn6TEQ54/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yTaiIw1zHUZ6FLt9AiRVn6TEQ54/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/IWcVV3kfWDc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/1346812487488732089/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/02/using-calculated-fields-in-queries.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/1346812487488732089" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/1346812487488732089" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/IWcVV3kfWDc/using-calculated-fields-in-queries.html" title="Using Calculated Fields in Queries" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-YSAjyMs_0kY/T0aMMkhGnMI/AAAAAAAAAso/IjXixlUYqKA/s72-c/Many-To-Many-Relationship-Structure.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/02/using-calculated-fields-in-queries.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-3238699501997193072</id><published>2012-02-17T05:01:00.000-08:00</published><updated>2012-02-17T05:02:23.586-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><title type="text">More on DoCmd OpenForm: Control Form Opening Part Two</title><content type="html">&lt;div style="text-align: justify;"&gt;Last week I blogged about how to &lt;a href="http://ms-access-tips.blogspot.com/2012/02/control-form-opening-datamode-openargs.html" target="_blank"&gt;Control Form Opening&lt;/a&gt; using&amp;nbsp;the&amp;nbsp;&lt;b&gt;DoCmd OpenForm&lt;/b&gt;&amp;nbsp;method of VBA. &amp;nbsp;I covered the &lt;i&gt;DataMode &lt;/i&gt;and &lt;i&gt;OpenArgs &lt;/i&gt;parameters in some detail. &amp;nbsp;Since being able to control form opening is an important part of database customization, I shall continue by looking at two other parameters of this method - namely the &lt;b&gt;VIEW &lt;/b&gt;and &lt;b&gt;WHERE &lt;/b&gt;parameters. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If we recap briefly on what we learnt last week, you may remember that we used &lt;b&gt;DoCmd OpenForm&lt;/b&gt; to control whether the form was opened ready to &lt;i&gt;add&lt;/i&gt; a new record, or &lt;i&gt;edit &lt;/i&gt;an existing record. A label caption was also set according the value passed to the form in the statement's &lt;b&gt;OpenArgs &lt;/b&gt;parameter. This time we are going to try something slightly different. &amp;nbsp;We are going to create a command button, which when pressed by the user, opens that &lt;i&gt;same &lt;/i&gt;form in &lt;b&gt;DATASHEET VIEW&lt;/b&gt; as well as displaying records &lt;i&gt;matching a given criteria&lt;/i&gt;. The end result will be a datasheet list of all employees where the &lt;b&gt;Position &lt;/b&gt;field contains the value of "&lt;i&gt;Manager&lt;/i&gt;".&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Let's remind ourselves of the syntax for &lt;b&gt;DoCmd OpenForm&lt;/b&gt;:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif; font-size: x-small;"&gt;&lt;b&gt;DoCmd.OpenForm "FormName", View, "FilterName", "WhereCondition", &amp;nbsp;DataMode, WindowMode, "OpenArgs"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As you may remember, only the &lt;b&gt;FormName &lt;/b&gt;parameter is required, all others being optional. &amp;nbsp;Just remember to include a comma if any of the parameters are not used (unless they comes &lt;i&gt;after &lt;/i&gt;&amp;nbsp;the last used parameter, in which case they are not needed). &amp;nbsp;So let's look at the specific syntax we need in order to achieve the task of producing a list of &lt;i&gt;Managers &lt;/i&gt;in &lt;i&gt;Datasheet View&lt;/i&gt;:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;DoCmd.OpenForm "frmEmployees", &amp;nbsp;acFormDS, , "position = 'manager'"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As you can see, the &lt;b&gt;VIEW &lt;/b&gt;parameter has been set to &lt;b&gt;acFormDS&lt;/b&gt;. &amp;nbsp;This value simply indicates that we want the form to open in Datasheet View. When you come to enter this yourself, you will see that&amp;nbsp;intellisense opens a drop down list of valid parameter values:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-bdhvxi3GEwg/Tz4rVyMNgxI/AAAAAAAAAsM/4_Ha3LeQwFs/s1600/view-parameter.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-bdhvxi3GEwg/Tz4rVyMNgxI/AAAAAAAAAsM/4_Ha3LeQwFs/s1600/view-parameter.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt;&amp;nbsp;Intellisense displaying a list of valid parameter values for VIEW.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;The next used parameter is the &lt;b&gt;WhereCondition&lt;/b&gt;. &amp;nbsp;This is basically an SQL WHERE clause, but without the &amp;nbsp;WHERE keyword (see my &lt;a href="http://ms-access-tips.blogspot.com/2011/05/gentle-introduction-to-access-sql.html" target="_blank"&gt;Introduction to Access SQL&lt;/a&gt; for more information about SQL WHERE). &amp;nbsp;You may also think of this as being like the criteria you enter in the &lt;b&gt;Criteria Row&lt;/b&gt;&amp;nbsp;of a Query Design Grid. When used as a OpenForm parameter, &amp;nbsp;just remember to enclose it within quotation marks, as it is a string value - ie:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;"position = 'manager'"&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Now that we have grasped the particular syntax for &lt;b&gt;DoCmd OpenForm&lt;/b&gt;, we are going to add a command button to the Switchboard form we created last week, and add the following code to its &lt;b&gt;OnClick&lt;/b&gt; Event:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Private Sub ctlManagers_Click()&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenForm "frmEmployees", acFormDS, , "position = 'manager'"&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; DoCmd.Close acForm, Me.Name&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: inherit; font-size: xx-small;"&gt;NB the DoCmd.Close statement simply closes the switchboard so it does not get in the way once our employees form opens.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Our Switchboard should now look like this:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-nRMXevWSkxU/Tz4xpipOBGI/AAAAAAAAAsU/Rzg4-R82QWw/s1600/new-switchboard.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-nRMXevWSkxU/Tz4xpipOBGI/AAAAAAAAAsU/Rzg4-R82QWw/s1600/new-switchboard.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; The new updated switchboard from last week.&lt;br /&gt;The code above it is written behind the &lt;b&gt;ctlManagers &lt;/b&gt;button's (top) &lt;b&gt;OnClick &lt;/b&gt;Event.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Here is the result when the user clicks the&amp;nbsp;&lt;b&gt;ctlManagers &lt;/b&gt;button&amp;nbsp;(captioned "&lt;i&gt;List Managers&lt;/i&gt;"):&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-cMaqFnNsgnQ/Tz40DC2hX8I/AAAAAAAAAsc/_mkfC1p0lT0/s1600/datasheet-form.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-cMaqFnNsgnQ/Tz40DC2hX8I/AAAAAAAAAsc/_mkfC1p0lT0/s1600/datasheet-form.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; frmEmployees displayed in &lt;i&gt;Datasheet View&lt;/i&gt; with &lt;i&gt;WhereCondition &lt;/i&gt;applied.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;As you can see, rather than our employees form being displayed in standard &lt;i&gt;Form View&lt;/i&gt;, passing the &lt;b&gt;acFormDS &lt;/b&gt;as the &lt;b&gt;View &lt;/b&gt;parameter has instead opened &lt;b&gt;frmEmployees &lt;/b&gt;as a &lt;i&gt;Datasheet &lt;/i&gt;similar to a table or query; and out of a list of 22 employees, passing&amp;nbsp;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;"position = 'manager'" &lt;/b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;as&lt;/span&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp;&lt;/b&gt;the &amp;nbsp;&lt;b&gt;WhereCondition&amp;nbsp;&lt;/b&gt;&amp;nbsp;parameter has&lt;b&gt;&amp;nbsp;&lt;/b&gt;provided a list of the two employees who have "&lt;i&gt;Manager&lt;/i&gt;" as their &lt;b&gt;Position&lt;/b&gt;. &amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If you have not already created this database for yourself, you might like to &lt;a href="http://www.dealing-with-data.net/exercises/CustomizeOpenForm2.accdb" target="_blank"&gt;download the completed solution&lt;/a&gt; and experiment by changing, amongst others, the &lt;b&gt;WhereCondition,&amp;nbsp;&lt;/b&gt;to see the versatility of &lt;b&gt;DoCmd OpenForm&lt;/b&gt; for yourself.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-3238699501997193072?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7P_NAsVJF-cC6t9za5RdypNu-wQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7P_NAsVJF-cC6t9za5RdypNu-wQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7P_NAsVJF-cC6t9za5RdypNu-wQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7P_NAsVJF-cC6t9za5RdypNu-wQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/UpZGKXL6KFc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/3238699501997193072/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/02/more-on-docmd-openform-control-form.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/3238699501997193072" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/3238699501997193072" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/UpZGKXL6KFc/more-on-docmd-openform-control-form.html" title="More on DoCmd OpenForm: Control Form Opening Part Two" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-bdhvxi3GEwg/Tz4rVyMNgxI/AAAAAAAAAsM/4_Ha3LeQwFs/s72-c/view-parameter.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/02/more-on-docmd-openform-control-form.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-192924892328888644</id><published>2012-02-10T04:07:00.000-08:00</published><updated>2012-02-10T04:07:33.805-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><title type="text">Control Form Opening: DataMode, OpenArgs, and the DoCmd.OpenForm Method</title><content type="html">&lt;div style="text-align: justify;"&gt;Lets imagine we have an employees form to add and edit our employee records.&amp;nbsp; The form is accessed via the database switchboard which contains a couple of Command Buttons.&amp;nbsp; The user clicks the &lt;b&gt;NEW EMPLOYEE&lt;/b&gt; button and the form opens in DATA ENTRY MODE; that is, as a blank form ready for a new record to be entered.&amp;nbsp; If, however, he or she clicks the &lt;b&gt;EDIT&lt;/b&gt; &lt;b&gt;EMPLOYEE &lt;/b&gt;button, the form opens in FORM EDIT MODE; at an actual employee record ready to be edited as required.&amp;nbsp; What's more, the form contains a label displaying a caption inviting the user to add a new employee, or edit an existing employee record depending on which button was pressed on the switchboard.&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-cBDMwUKeUy0/TzQfBefwoFI/AAAAAAAAArc/zGs19Pupwm8/s1600/switchboard.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="215" src="http://2.bp.blogspot.com/-cBDMwUKeUy0/TzQfBefwoFI/AAAAAAAAArc/zGs19Pupwm8/s320/switchboard.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure1 (above):&lt;/b&gt; The Switchboard with Command Buttons &lt;br /&gt;to open &lt;b&gt;frmEmployees&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HDP2pMZW9YI/TzQe_PeZwGI/AAAAAAAAArU/KCSvzgBTxsU/s1600/form-design.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="243" src="http://3.bp.blogspot.com/-HDP2pMZW9YI/TzQe_PeZwGI/AAAAAAAAArU/KCSvzgBTxsU/s400/form-design.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;Form Design for frmEmployees.&amp;nbsp; &lt;br /&gt;Note the label containing the text "Instructions": this text is &lt;br /&gt;dynamically reset as the form opens.&lt;/td&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Since we have learnt some &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;basic VBA programming skills&lt;/a&gt; at the end of last year, lets look at how we can do this using the &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; method. &amp;nbsp; As we shall soon see, this method passes a number of parameters to the opening form, determining various aspects of how we want it to function.&amp;nbsp; &lt;b&gt;DataMode &lt;/b&gt;and &lt;b&gt;OpenArgs &lt;/b&gt;are the two parameters we shall be using to accomplish the task set out in the above mentioned scenario. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;DoCmd.OpenForm"formName",View,"FilterName","WhereCondition",DataMode, WindowMode,"OpenArgs"&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-a2_D_YUaaQw/TzTq2hWIQWI/AAAAAAAAArk/ngU45-Y7wVo/s1600/open-form-method.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-a2_D_YUaaQw/TzTq2hWIQWI/AAAAAAAAArk/ngU45-Y7wVo/s1600/open-form-method.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; The &lt;b&gt;IntelliSense &lt;/b&gt;feature of the VBA Editor will&lt;br /&gt;help when you come to enter the &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; parameters.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Here is an outline of the tasks involved:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create the Switchboard Form with two Command buttons - &lt;b&gt;ctlNew &lt;/b&gt;and &lt;b&gt;ctlEdit&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Add code to each of the command buttons which opens &lt;b&gt;frmEmployees &lt;/b&gt;in the desired &lt;b&gt;DataMode &lt;/b&gt;and with the corresponding label caption for adding or editing.&lt;/li&gt;&lt;li&gt;Create &lt;b&gt;frmEmployees &lt;/b&gt;along with its underlying data source (ie an employees table). &amp;nbsp;The form should have a label control (&lt;b&gt;lblInstuctions&lt;/b&gt;), and text boxes/combo boxes for each of the fields. &amp;nbsp;NB for the purposes of this exercise it does not particularly matter what the fields are.&lt;/li&gt;&lt;li&gt;Add the relevant code to the &lt;b&gt;OnOpen &lt;/b&gt;Event of &lt;b&gt;frmEmployees&lt;/b&gt;. &amp;nbsp;This is going to read the value of the forms &lt;b&gt;OpenArgs&lt;/b&gt; Property, which is set when the user clicks one of the two command buttons on the switchboard. &amp;nbsp;Then, depending on what that value is, display the appropriate caption for &lt;b&gt;lblInstructions&lt;/b&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;(&lt;a href="http://www.dealing-with-data.net/exercises/CustomizeOpenForm.accdb"&gt;Download the complete solution here&lt;/a&gt;)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let's go through stage two and stage four in more detail. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To begin with lets look at the code used behind each of the two command buttons on frmSwitchboard. These statements are executed behind each command button's &lt;b&gt;OnClick Event&lt;/b&gt;:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Stage Two Code:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub ctlEdit_Click()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenForm "frmEmployees", , , , acFormEdit, , "Edit"&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub ctlNew_Click()&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenForm "frmEmployees", , , , acFormAdd, , "Add"&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As you can see, the &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; method has a total of seven parameters, but only the first of these is required (as opposed to optional).&amp;nbsp; Not suprisingly the required parameter is the name of the form to be opened, which in our case is "&lt;b&gt;frmEmployees&lt;/b&gt;". &amp;nbsp;In addition to the form name we also set the &lt;b&gt;DataMode &lt;/b&gt;and &lt;b&gt;OpenArgs &lt;/b&gt;parameters.&amp;nbsp; For our scenario, &lt;b&gt;DataMode &lt;/b&gt;determines whether the form is going to be opened in DataEntry (&lt;b&gt;acFormAdd&lt;/b&gt;) or Edit (&lt;b&gt;acFormEdit&lt;/b&gt;) mode.&amp;nbsp; It is the &lt;i&gt;fifth &lt;/i&gt;parameter in the list.&amp;nbsp;The &amp;nbsp;&lt;b&gt;OpenArgs&amp;nbsp;&lt;/b&gt;parameter, on the other hand, is &lt;i&gt;seventh&lt;/i&gt; in the list.&amp;nbsp; This is simply a string value which will set the opening form's&amp;nbsp;&lt;b&gt;OpenArgs &lt;/b&gt;&lt;i&gt;property&lt;/i&gt;.&amp;nbsp; Once the form has opened, we are going to read the value of this property to determine which message we are going to display in the label caption shown in figure two above. As such we are going to pass a string value which indicates whether we are adding or editing the employee record. &amp;nbsp;Please note that the text of the string value is entirely arbitrary.&amp;nbsp; We just need to choose a unique value in order to differentiate between &lt;i&gt;adding &lt;/i&gt;and &lt;i&gt;editing &lt;/i&gt;as the form opens. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is the code we need to enter behind the frmEmployees&amp;nbsp;&lt;b&gt;OnOpen &lt;/b&gt;Event:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Stage Four Code:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Private Sub Form_Open(Cancel As Integer)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If Me.OpenArgs = "Edit" Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblInstructions.Caption = "Please Edit Employee Record"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; ElseIf Me.OpenArgs = "Add" Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblInstructions.Caption = "Please Add New Employee Record"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As you can see this code reads the value stored &amp;nbsp;in the opening form's &lt;b&gt;OpenArgs &lt;/b&gt;property and uses a &lt;a href="http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html" target="_blank"&gt;If ... Then ... Else Statement&lt;/a&gt; to determine whether our instructions label should display information pertaining to &lt;i&gt;Editing &lt;/i&gt;or &lt;i&gt;Adding &lt;/i&gt;an Employee Record. &amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-4oCrchbo1g4/TzTwa44idYI/AAAAAAAAAr8/i7mXgBr293w/s1600/edit.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="226" src="http://3.bp.blogspot.com/-4oCrchbo1g4/TzTwa44idYI/AAAAAAAAAr8/i7mXgBr293w/s400/edit.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: frmEmployees &lt;/b&gt;for&amp;nbsp;&lt;i&gt;Editing&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Vy2xcICnQYg/TzTwb3FI-yI/AAAAAAAAAsE/W5S18Tm7swA/s1600/add.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="226" src="http://4.bp.blogspot.com/-Vy2xcICnQYg/TzTwb3FI-yI/AAAAAAAAAsE/W5S18Tm7swA/s400/add.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 5:&amp;nbsp;&lt;/b&gt;&amp;nbsp;&lt;b&gt;frmEmployees&amp;nbsp;&lt;/b&gt;for&amp;nbsp;&lt;i&gt;Adding &lt;/i&gt;(DataEntry).&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;As you can see, the screenshot in &lt;i&gt;Figure 4&lt;/i&gt; shows what our form looks like when it opens for &lt;i&gt;Editing&lt;/i&gt;, and that in &lt;i&gt;Figure 5&lt;/i&gt; shows what it looks like for &lt;i&gt;Adding&lt;/i&gt;. So despite being exactly the same form, we have dynamically controlled how it looks and functions by setting the &lt;b&gt;DataMode&lt;/b&gt; and &lt;b&gt;OpenArgs &lt;/b&gt;parameters of the &lt;b&gt;DoCmd.OpenForm&lt;/b&gt; method.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-192924892328888644?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AAYZlNfYF66cDj195U0mWQm2OP0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AAYZlNfYF66cDj195U0mWQm2OP0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AAYZlNfYF66cDj195U0mWQm2OP0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AAYZlNfYF66cDj195U0mWQm2OP0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/xIfyT-hkJ2E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/192924892328888644/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/02/control-form-opening-datamode-openargs.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/192924892328888644" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/192924892328888644" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/xIfyT-hkJ2E/control-form-opening-datamode-openargs.html" title="Control Form Opening: DataMode, OpenArgs, and the DoCmd.OpenForm Method" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-cBDMwUKeUy0/TzQfBefwoFI/AAAAAAAAArc/zGs19Pupwm8/s72-c/switchboard.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/02/control-form-opening-datamode-openargs.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-5408385842410992983</id><published>2012-02-03T05:54:00.000-08:00</published><updated>2012-02-03T05:55:33.309-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="combo box" /><category scheme="http://www.blogger.com/atom/ns#" term="many to many" /><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><category scheme="http://www.blogger.com/atom/ns#" term="relationships" /><category scheme="http://www.blogger.com/atom/ns#" term="subform" /><title type="text">Creating a Form for a Many to Many Relationship</title><content type="html">&lt;div style="text-align: justify;"&gt;I was recently asked how to create a form to input order management data where there is an underlying &lt;a href="http://ms-access-tips.blogspot.com/2011/04/many-to-many-relationship.html" target="_blank"&gt;Many to Many Relationship&lt;/a&gt; in place. &amp;nbsp;There are, of course, many ways of dealing with this common scenario, but the particular solution I suggested involved creating an &lt;b&gt;Order Form&lt;/b&gt;, with an &lt;b&gt;Order Details&lt;/b&gt; subform. &amp;nbsp;When the user enters the Order Details data on the subform, he or she is able to select a Product Item from a &lt;i&gt;Combo Box list&lt;/i&gt;. The Row Source used for the Combo Box list is data drawn from the Products table. &amp;nbsp;Hence we have all sides of the Many to Many Relationship represented on a single form.&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-45A3b266vjk/Tyu02eUVQuI/AAAAAAAAAq0/cKSNM5RloSk/s1600/Many-To-Many-Form.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="494" src="http://3.bp.blogspot.com/-45A3b266vjk/Tyu02eUVQuI/AAAAAAAAAq0/cKSNM5RloSk/s640/Many-To-Many-Form.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1 (Above):&amp;nbsp;&lt;/b&gt;The Many to Many Form; the solution I suggested&lt;br /&gt;in answer to&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/04/many-to-many-relationship.html?showComment=1327721978559#c4734690328919634021" target="_blank"&gt;dcodding's question&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-WrygUBj7-Lo/Tyu62YvvHYI/AAAAAAAAAq8/DOK261wGsJg/s1600/Many-To-Many-Relationship-Structure.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="266" src="http://3.bp.blogspot.com/-WrygUBj7-Lo/Tyu62YvvHYI/AAAAAAAAAq8/DOK261wGsJg/s640/Many-To-Many-Relationship-Structure.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&amp;nbsp;&lt;b&gt;Figure 2:&lt;/b&gt;&amp;nbsp;The underlying Many to Many&lt;br /&gt;Relationship Structure, upon which the form is based.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;It is interesting to note where each of the fields from the Order Form is located in the underlying Many to Many Relationship structure. &amp;nbsp;So let me briefly take you through this. &lt;br /&gt;&lt;br /&gt;The main section of the order form has three fields derived from&amp;nbsp;&lt;b&gt;tblOrder&lt;/b&gt;, the left hand table in figure 2 above. &amp;nbsp;These are the &lt;b&gt;OrderId &lt;/b&gt;and &lt;b&gt;OrderDate &lt;/b&gt;fields. &amp;nbsp;In addition to this we also have the &lt;b&gt;CustomerId &lt;/b&gt;field which is the foreign key from &lt;b&gt;tblCustomer &lt;/b&gt;(a table which is not part of the Many to Many Relationship, therefore &lt;i&gt;not &lt;/i&gt;shown in Figure 2). &lt;br /&gt;&lt;br /&gt;The relationship between the main section of the Order Form and it's subform is modelled on the One to Many Relationship between &lt;b&gt;tblOrder &lt;/b&gt;and &lt;b&gt;tblOrderDetails&lt;/b&gt;. However, because we have an underlying Many to Many Relationship, I have created a query for the Subforms' Record Source which has fields from both &lt;b&gt;tblOrderDetails&lt;/b&gt; and &lt;b&gt;tblProducts&lt;/b&gt;. &amp;nbsp;Moreover, the second&amp;nbsp;&lt;b&gt;ProductId&amp;nbsp;&lt;/b&gt;field is actually a combo box which uses data from &lt;b&gt;tblProducts&lt;/b&gt; as its Row Source.&lt;br /&gt;&lt;br /&gt;Lets take a closer look at the subform's design and underlying query:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-gAOQITOT5gQ/Tyu9pXLZSdI/AAAAAAAAArE/fjBgHBVxqhY/s1600/subform.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="181" src="http://3.bp.blogspot.com/-gAOQITOT5gQ/Tyu9pXLZSdI/AAAAAAAAArE/fjBgHBVxqhY/s400/subform.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3 (Above):&lt;/b&gt; The Order Details Subform design grid.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-bgvq4PWlka0/TyvABh_AvEI/AAAAAAAAArM/wvXm6YSXqbQ/s1600/query-design-grid.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="441" src="http://1.bp.blogspot.com/-bgvq4PWlka0/TyvABh_AvEI/AAAAAAAAArM/wvXm6YSXqbQ/s640/query-design-grid.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4:&lt;/b&gt; The Query used for the Subform's Record Source.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;As you can see,&amp;nbsp;&lt;b&gt;ProductId&lt;/b&gt;, &lt;b&gt;ProductId&lt;/b&gt;,&amp;nbsp;and&amp;nbsp;&lt;b&gt;Quantity &lt;/b&gt;are derived from &lt;b&gt;tblOrderDetails&lt;/b&gt;, and &lt;b&gt;CostPerUnit &lt;/b&gt;is derived from &lt;b&gt;tblProducts&lt;/b&gt;. &amp;nbsp;&lt;b&gt;ProductId &lt;/b&gt;is, of course the foreign key from &lt;b&gt;tblProducts&lt;/b&gt;. There is also a Calculated Field (&lt;b&gt;Total&lt;/b&gt;) which multiplies the &lt;b&gt;CostPerUnit &lt;/b&gt;by &lt;b&gt;Quantity &lt;/b&gt;to provide the actual purchase price. &lt;br /&gt;&lt;br /&gt;So why then do we have &lt;i&gt;two &lt;/i&gt;&lt;b&gt;ProductId&lt;/b&gt;'s? &amp;nbsp;The reason for this is that the second ProductId does not actually display the Id number &lt;i&gt;per se&lt;/i&gt;. Since this field is represented by a Combo Box control on the subform, the data which is displayed can be different to that which it is bound to. &amp;nbsp;So in order to make the subform more user friendly, the control is set up to display the product's &lt;b&gt;ItemName &lt;/b&gt;from &lt;b&gt;tblProducts &lt;/b&gt;whilst being bound to the &lt;b&gt;tblOrderDetails.ProductId&lt;/b&gt; field. This is done by setting the combo box Control Source property to &lt;b&gt;ProductId&lt;/b&gt;, &amp;nbsp;and its Row Source property to &lt;b&gt;tblProducts&lt;/b&gt;. As such, using the Combo Box in this way has enabled the subform to obtain information from the products table on the right hand side of the Many to Many Relationship.&amp;nbsp;For detailed information on how to do work with Combo Boxes in this way, you might like to see my post on &lt;a href="http://ms-access-tips.blogspot.com/2011/07/customizing-access-combo-box.html" target="_blank"&gt;Customizing an Access Combo Box&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;So what happens when the user comes to enter data in the subform? If &amp;nbsp;the user knows the &lt;b&gt;productId&lt;/b&gt; number for the Order Item in question, he or she will enter that number in the first column of the subform. &amp;nbsp;Since this is the foreign key for the Products table, doing so will 'bring' any other subform field derived from &lt;b&gt;tblProducts &lt;/b&gt;along with it. &amp;nbsp;In other words once the user enters a &lt;b&gt;productId&lt;/b&gt;, data in the &lt;b&gt;CostPerUnit &lt;/b&gt;field for that product record is displayed in the appropriate field of the subform. &amp;nbsp;In addition to this, the &lt;b&gt;ItemName &lt;/b&gt;for the product is displayed in the Combo Box control, since its &lt;i&gt;Row Source&lt;/i&gt; is bound to &lt;b&gt;ItemName &lt;/b&gt;in &lt;b&gt;tblProducts&lt;/b&gt;. &amp;nbsp;If, on the other hand, the user does not know the &lt;b&gt;ProductId&lt;/b&gt;, he/she may leave the first field blank, and select a value from the Combo Box drop down list. &amp;nbsp;Since the Combo Box &lt;i&gt;Control Source&lt;/i&gt; is bound to &lt;b&gt;ProductId &lt;/b&gt;of &lt;b&gt;tblOrderDetails&lt;/b&gt;, and its &lt;i&gt;Row Source&lt;/i&gt;, as we know, is bound to &lt;b&gt;ItemName &lt;/b&gt;of &lt;b&gt;tblProducts&lt;/b&gt;, this is effectively the same as entering the &lt;b&gt;ProductId &lt;/b&gt;number directly. &amp;nbsp;What's more, data from &lt;b&gt;tblProducts &lt;/b&gt;is 'brought' over to the subform as before. &amp;nbsp;Hence, the first &lt;b&gt;productId&lt;/b&gt; field of the subform is filled in automatically.&lt;br /&gt;&lt;br /&gt;We see, therefore, that this relatively simple and user friendly form not only represents all tables in this Many to Many Relationship, but also provides a practical example of how the Many to Many Relationship works in action.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-5408385842410992983?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fouLxuCKjyoOhzO7YyokFRizMMY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fouLxuCKjyoOhzO7YyokFRizMMY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fouLxuCKjyoOhzO7YyokFRizMMY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fouLxuCKjyoOhzO7YyokFRizMMY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/GIwpHpks5pg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/5408385842410992983/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/02/creating-form-for-many-to-many.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/5408385842410992983" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/5408385842410992983" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/GIwpHpks5pg/creating-form-for-many-to-many.html" title="Creating a Form for a Many to Many Relationship" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-45A3b266vjk/Tyu02eUVQuI/AAAAAAAAAq0/cKSNM5RloSk/s72-c/Many-To-Many-Form.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/02/creating-form-for-many-to-many.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-7671073820320868149</id><published>2012-01-27T01:50:00.000-08:00</published><updated>2012-01-27T01:50:28.053-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="wildcard" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="LIKE operator" /><title type="text">Using the LIKE Operator and Wildcards to Match Patterns Between Strings</title><content type="html">&lt;div style="text-align: justify;"&gt;When we enter a criteria for a text field in an Access Query, the results can be a little limiting when we use the equality operator (ie = ). &amp;nbsp;So, for example, if we have a list of employees and we want to search for all Sales Representatives, we could use &lt;span style="color: #0b5394;"&gt;="Sales Representative"&lt;/span&gt; as the criteria. &amp;nbsp;This would correctly produce a list of employees containing this exact value in the &lt;b&gt;Position &lt;/b&gt;field. &amp;nbsp;This is all fine and good. &amp;nbsp;However, what if we wanted a list of all employees that have the word&amp;nbsp;&lt;i&gt;sales &lt;/i&gt;appearing at the start of this field? &amp;nbsp;Take a look at this screen shot of the table in question:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-fKapdEky1Kg/TyGz-nfE6AI/AAAAAAAAAp8/NxpGeZYIlGg/s1600/employees+list.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-fKapdEky1Kg/TyGz-nfE6AI/AAAAAAAAAp8/NxpGeZYIlGg/s400/employees+list.JPG" width="343" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1&lt;/b&gt;: The Employees Table&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;As you can see, there are three different job titles beginning with the word &lt;i&gt;Sales - &lt;/i&gt;there is &lt;i&gt;Sales Manager&lt;/i&gt;, &lt;i&gt;Sales Representative&lt;/i&gt;, and &lt;i&gt;Sales Assistant&lt;/i&gt;. &amp;nbsp;Despite this fact,&amp;nbsp;&amp;nbsp;if we were to enter&amp;nbsp;&lt;span style="color: #0b5394;"&gt;= "sales" &lt;/span&gt;as the criteria, no records would be returned in the query results. &amp;nbsp;This is because it is not an &lt;i&gt;exact &lt;/i&gt;match for any job title.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This is where the LIKE operator comes in handy. &amp;nbsp;The LIKE operator is used in conjunction with one of the Access &lt;i&gt;Wildcard&amp;nbsp;&lt;/i&gt;symbols to compare a pattern between two strings. &amp;nbsp;So instead of entering the criteria &lt;span style="color: #0b5394;"&gt;= "sales"&lt;/span&gt; we could enter &lt;span style="color: #0b5394;"&gt;LIKE "sales*"&lt;/span&gt;.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-zEM-P1mAtto/TyG4xZFLYEI/AAAAAAAAAqE/9g69Fy_TBUk/s1600/like-query-criteria.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="140" src="http://2.bp.blogspot.com/-zEM-P1mAtto/TyG4xZFLYEI/AAAAAAAAAqE/9g69Fy_TBUk/s640/like-query-criteria.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;Query Criteria using the &lt;b&gt;LIKE &lt;/b&gt;operator.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;This latter criteria would return all records beginning with the word "sales". &amp;nbsp;So any word letter or character coming after "&lt;i&gt;sales&lt;/i&gt;" is ignored. &amp;nbsp;As such, our query now returns records containing any of the three above mentioned job titles in the &lt;b&gt;Position &lt;/b&gt;field.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-S4ZYkFJIUXc/TyG4zejvBgI/AAAAAAAAAqM/mxtiYTxO6OE/s1600/like-query-results.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="253" src="http://1.bp.blogspot.com/-S4ZYkFJIUXc/TyG4zejvBgI/AAAAAAAAAqM/mxtiYTxO6OE/s400/like-query-results.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3&lt;/b&gt;:Query results returning all three job titles&lt;br /&gt;beginning with the word "&lt;i&gt;sales&lt;/i&gt;"...&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;The type and position of Wildcard is crucial in all this. &amp;nbsp;We used the * wildcard symbol indicating that it is representing any number of characters (including zero).&amp;nbsp;This is in contrast to the ? wildcard symbol which just represents a single character (eg &lt;span style="color: #0b5394;"&gt;LIKE "Sales Representativ?"&lt;/span&gt; to return &lt;b&gt;"Sales Representative"&lt;/b&gt;), or the # wildcard symbol representing a single digit from 0 to 9 (eg &lt;span style="color: #0b5394;"&gt;LIKE "Person#"&lt;/span&gt; to return &lt;b&gt;"Person1"&lt;/b&gt;. &amp;nbsp;We could also specify a range of characters between square brackets - for example &lt;span style="color: #0b5394;"&gt;LIKE "Person[1-5]" &lt;/span&gt;would return the string &lt;b&gt;"Person1"&lt;/b&gt;, or&amp;nbsp;&lt;b&gt;"Person2"&lt;/b&gt;etc, but not &lt;b&gt;"Person6"&lt;/b&gt; or above. &amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;These wildcard symbols can appear anywhere in the search string. &amp;nbsp;We placed ours after at the end of the search string to return any string &lt;i&gt;beginning &lt;/i&gt;with &lt;b&gt;"Sales ..."&lt;/b&gt;. &amp;nbsp;Had we wanted to return any job title &lt;i&gt;ending &lt;/i&gt;in&lt;b&gt; "... Assistant"&lt;/b&gt;, we would have placed the wildcard at the beginning of the search string ie&amp;nbsp;&lt;span style="color: #0b5394;"&gt;LIKE "*Assistant"&lt;/span&gt;&lt;span style="color: #0b5394;"&gt;&amp;nbsp;&lt;/span&gt;. There are even scenarios where a wildcard may be used in a specific place in the middle of a string too. &amp;nbsp;Try experimenting with all this - it's the best way to learn!&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-7671073820320868149?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cewyHwv1zr32J6GocHykBlV96Lw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cewyHwv1zr32J6GocHykBlV96Lw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cewyHwv1zr32J6GocHykBlV96Lw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cewyHwv1zr32J6GocHykBlV96Lw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/-EAvrgmM39A" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/7671073820320868149/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/01/using-like-operator-and-wildcards-to.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/7671073820320868149" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/7671073820320868149" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/-EAvrgmM39A/using-like-operator-and-wildcards-to.html" title="Using the LIKE Operator and Wildcards to Match Patterns Between Strings" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-fKapdEky1Kg/TyGz-nfE6AI/AAAAAAAAAp8/NxpGeZYIlGg/s72-c/employees+list.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/01/using-like-operator-and-wildcards-to.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-5578977983765454443</id><published>2012-01-20T02:44:00.000-08:00</published><updated>2012-01-20T02:45:42.364-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Append Query" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="Action Query" /><title type="text">Append Queries: Automatically Append Data from One Table to Another</title><content type="html">Append Queries are really useful when you acquire a new table full of data, and want to add it to an existing table in your database. &amp;nbsp;This scenario may arise, for example, if your company purchases a mailing list, and you are asked to add the new names to those you already have stored. &amp;nbsp;Rather than having to retype the new names by hand, an append query can be set up to copy the data from the new table into that which is already in use.&lt;br /&gt;&lt;br /&gt;I have created an exercise to demonstrate how this process works. &amp;nbsp;Lets begin by looking at the two tables we are going to be working with:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-4w5iSRWrgQA/Txhv0q_7pFI/AAAAAAAAApU/l0yBeySZ_hg/s1600/tblContacts.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-4w5iSRWrgQA/Txhv0q_7pFI/AAAAAAAAApU/l0yBeySZ_hg/s1600/tblContacts.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; &lt;b&gt;tblContacts &lt;/b&gt;- the existing table consisting&lt;br /&gt;of &amp;nbsp;&lt;b&gt;ID &lt;/b&gt;(autonumber), &lt;b&gt;FirstName &lt;/b&gt;(text) and &lt;b&gt;Surname &lt;/b&gt;(text).&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-0V3WHkQs-CY/Txhv2ed4cGI/AAAAAAAAApc/QLtfINHxbWk/s1600/tblMoreNames.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="197" src="http://3.bp.blogspot.com/-0V3WHkQs-CY/Txhv2ed4cGI/AAAAAAAAApc/QLtfINHxbWk/s320/tblMoreNames.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;&lt;b&gt;tblMoreNames &lt;/b&gt;- new data to be appended, consisting of&lt;br /&gt;&lt;b&gt;CustomerId &lt;/b&gt;(autonumber), &lt;b&gt;Title &lt;/b&gt;(text), &lt;b&gt;Initials&lt;/b&gt; (text), and &lt;b&gt;LastName &lt;/b&gt;(text).&lt;br /&gt;Notice the fields names are somwhat different and&amp;nbsp;there is also a&lt;br /&gt;risk of duplicating the ID fields from&amp;nbsp;both tables. &lt;br /&gt;More about this soon.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;As you can see, figure 1 shows&amp;nbsp;&lt;b&gt;tblContacts&lt;/b&gt;, our existing table containing 15 records. &amp;nbsp;We are going to create an append query to add the 10 new records from &lt;b&gt;tblMoreNames &lt;/b&gt;to the data already stored in this&amp;nbsp;table.&amp;nbsp;&amp;nbsp;You may have noticed that the field names contained in both tables are slightly different, and&amp;nbsp;&lt;b&gt;tblMoreNames&amp;nbsp;&lt;/b&gt;has a&amp;nbsp;&lt;b&gt;Title&amp;nbsp;&lt;/b&gt;field which&amp;nbsp;&lt;b&gt;tblContacts&amp;nbsp;&lt;/b&gt;does not. &amp;nbsp;You may also have spotted that there is a risk of us attempting to append duplicate data from the &lt;b&gt;CustomerID &lt;/b&gt;field of &lt;b&gt;tblMoreNames&lt;/b&gt;. &amp;nbsp;Access would prevent this because the ID field in&amp;nbsp;&lt;b&gt;tblContacts&amp;nbsp;&lt;/b&gt;is a Primary Key, so needs to be a unique value. &amp;nbsp; The simple solution to this, is for us not to include the&amp;nbsp;&lt;b&gt;customerId&amp;nbsp;&lt;/b&gt;field (or anyother incompatible field) &amp;nbsp;in the append query. &amp;nbsp;As such, we shall just append data from the&amp;nbsp;&lt;b&gt;Initials&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;LastName&amp;nbsp;&lt;/b&gt;fields of &lt;b&gt;tblMoreNames &lt;/b&gt;to the &lt;b&gt;FirstName &lt;/b&gt;and &lt;b&gt;Surname &lt;/b&gt;fields of &lt;b&gt;tblContacts&lt;/b&gt;. &amp;nbsp;Although the field names are slightly different, the data they contain &lt;i&gt;is&lt;/i&gt; compatible, and for the purposes of this exercise, it is ok for us to append an &lt;i&gt;Initial &lt;/i&gt;in place of a &lt;i&gt;FirstName&lt;/i&gt; - the idea here is to demonstrate that the field names&amp;nbsp;&lt;i&gt;do&lt;/i&gt;&amp;nbsp;&lt;i&gt;not have to match exactly&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;Creating an Append Query&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Here is the procedure for creating the append query:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Click the QUERY DESIGN icon (located in the OTHER group of the CREATE ribbon). &amp;nbsp;The QUERY DESIGN window then opens along with the SHOW TABLE dialog form.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;The next step is to add&amp;nbsp;&lt;b&gt;tblMoreNames &lt;/b&gt;to the QUERY DESIGN window. &amp;nbsp;Do this by clicking ADD in the SHOW TABLE dialog form. &amp;nbsp;Notice it is the table containing the &lt;i&gt;data to be appended&lt;/i&gt; that we have selected.&lt;/li&gt;&lt;li&gt;Click the APPEND icon from the QUERY TYPE group of the DESIGN ribbon. &amp;nbsp;As you do this, you will see the APPEND dialog box open.&lt;/li&gt;&lt;li&gt;You are now asked to select the name of the original table to which the new data is to be appended. So select &lt;b&gt;tblContacts &lt;/b&gt;from the drop down list. &amp;nbsp;&lt;/li&gt;&lt;li&gt;You are also asked whether this table is stored in the current database or in an external database. In this exercise both tables are stored in the current database. &amp;nbsp;This is the default button displayed in the option group, so there should not be any need to change it.&lt;/li&gt;&lt;li&gt;Click OK to close the dialog box.&lt;/li&gt;&lt;li&gt;Next we are going to select the fields from &lt;b&gt;tblMoreNames &lt;/b&gt;to be appended. To do this drag and drop the &lt;b&gt;Initials&amp;nbsp;&lt;/b&gt;and &lt;b&gt;LastName &lt;/b&gt;fields from the table (in the top half of the window) down onto the design grid.&lt;/li&gt;&lt;li&gt;Next we are going to tell Access which fields the data from &lt;b&gt;Initials &lt;/b&gt;and &lt;b&gt;Lastname &lt;/b&gt;will be appended &lt;i&gt;to&lt;/i&gt;. &amp;nbsp;To do this go down to the APPEND TO row of the design grid (see figure 3 below), and select &lt;b&gt;FirstName &lt;/b&gt;in the &lt;b&gt;Initials &lt;/b&gt;column, and &lt;b&gt;Surname&lt;/b&gt; in the &lt;b&gt;LastName &lt;/b&gt;Column.&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-CBbzggDOBTo/Txk5YW_IHKI/AAAAAAAAApk/VK10P9AAwfs/s1600/design-grid.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-CBbzggDOBTo/Txk5YW_IHKI/AAAAAAAAApk/VK10P9AAwfs/s1600/design-grid.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; The Query Design Grid.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;li&gt;We could add query criteria at this stage, but this particular exercise does not require any. &amp;nbsp;If we did, however, this is added in the CRITERIA row just like it is with a select query.&amp;nbsp;&lt;/li&gt;&lt;li&gt;If you want to view the data that is going to be appended, click the VIEW icon from the RESULTS group of the DESIGN ribbon. &amp;nbsp;It is especially important to do this if any if any criteria is applied in step 9 above.&lt;/li&gt;&lt;li&gt;Once you are satisfied the correct data is going to be appended, click the RUN icon, again from the RESULTS group of the DESIGN ribbon.&lt;/li&gt;&lt;li&gt;A dialog box opens informing us that 10 rows are going to be appended, and asking us to confirm that we want to go ahead with this operation. &amp;nbsp;Click YES to complete.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;To see the result of our Append Query, re-open tblContacts. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gdgGH957zNQ/Txk-rPgcY_I/AAAAAAAAAps/0vxUJGMCyOQ/s1600/appended-data.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-gdgGH957zNQ/Txk-rPgcY_I/AAAAAAAAAps/0vxUJGMCyOQ/s400/appended-data.JPG" width="212" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: tblContacts &lt;/b&gt;after the &lt;br /&gt;&lt;i&gt;Append Query&lt;/i&gt; has been run.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;We can now see the new records appended to the end of our original data. &amp;nbsp;Notice each of the newly appended records has been automatically allocated a unique ID number. &amp;nbsp;This, of course, is because the ID field in the original table had been set to the AUTONUMBER datatype. &amp;nbsp;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-5578977983765454443?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/W15g5ZN28YS1K1qKSPBGCwlSXzk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/W15g5ZN28YS1K1qKSPBGCwlSXzk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/W15g5ZN28YS1K1qKSPBGCwlSXzk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/W15g5ZN28YS1K1qKSPBGCwlSXzk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/35GyWuFmCgQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/5578977983765454443/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/01/append-queries-automatically-appending.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/5578977983765454443" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/5578977983765454443" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/35GyWuFmCgQ/append-queries-automatically-appending.html" title="Append Queries: Automatically Append Data from One Table to Another" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-4w5iSRWrgQA/Txhv0q_7pFI/AAAAAAAAApU/l0yBeySZ_hg/s72-c/tblContacts.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/01/append-queries-automatically-appending.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2641324450048296834</id><published>2012-01-13T01:37:00.000-08:00</published><updated>2012-01-13T01:37:09.862-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="filters" /><category scheme="http://www.blogger.com/atom/ns#" term="reports" /><title type="text">Using VBA to Filter Report Results</title><content type="html">Earlier this week I was asked how to filter the results of a report using a criteria selected from three Combo Boxes on a search form. &amp;nbsp;You can see Marwa's question posted on my &lt;a href="http://www.facebook.com/pages/Access-2007-Tutorial/201397826545638" target="_blank"&gt;Access Tutorial Facebook Page&lt;/a&gt; (&lt;i&gt;Tuesday 10th January 2012&lt;/i&gt;). &amp;nbsp;The solution I suggested involved creating a Parameter Query with three separate criteria referencing the values contained in the Combo Boxes on the Search Form. &amp;nbsp;You can see the full response I gave in my comment below her question. &lt;br /&gt;&lt;br /&gt;By co-incidence I have also been working on a similar task in my work as an Access Developer. &amp;nbsp;One of the projects I am currently working on is a Journal Database which uses descriptive tags to categorise journal entries. &amp;nbsp; So, for example, if users made an entry about their progress learning Microsoft Access, they might use tags such as &amp;nbsp;"&lt;i&gt;Database Development&lt;/i&gt;", "&lt;i&gt;Reports&lt;/i&gt;", and "&lt;i&gt;Filters&lt;/i&gt;" to categorise their entry.&lt;br /&gt;&lt;br /&gt;I wanted to create an quick way for users to search their journal by tag name, so that all records categorised by a given tag may be extracted and displayed in a report. &amp;nbsp;To do this I created a really basic search form that consisted of just one unbound &lt;a href="http://ms-access-tips.blogspot.com/2011/07/customizing-access-combo-box.html" target="_blank"&gt;Combo Box&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-CTIf44JD498/Tw818zxdmSI/AAAAAAAAApA/oEULufdyRtg/s1600/tag-search.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="286" src="http://3.bp.blogspot.com/-CTIf44JD498/Tw818zxdmSI/AAAAAAAAApA/oEULufdyRtg/s320/tag-search.JPG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The ROW SOURCE for the Combo Box is a table containing all of the tag names used in the database. &amp;nbsp;The idea is that the user selects a tag from the drop down list, thereby triggering a block of VBA code in order to open the report filtered by the selected tag name. &amp;nbsp;The screen shot below shows the report filtered by the tag name "ADO.Net":&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-sP2vdR7hLO4/Tw88r7_37tI/AAAAAAAAApI/AKysbaKdYR8/s1600/filtered-report.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="190" src="http://2.bp.blogspot.com/-sP2vdR7hLO4/Tw88r7_37tI/AAAAAAAAApI/AKysbaKdYR8/s640/filtered-report.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;span style="font-size: xx-small;"&gt;The underlying table structure for this report is based on a query with &lt;br /&gt;three tables from a &lt;a href="http://ms-access-tips.blogspot.com/2011/04/many-to-many-relationship.html" target="_blank"&gt;many to many relationship&lt;/a&gt;. &amp;nbsp;There is a table for the Entries, and a &lt;br /&gt;separate table for Tags. &amp;nbsp;There is also a junction table to store each instance of&lt;br /&gt;a tag used in any particular Entry. &amp;nbsp;As such a journal entry can be related to &lt;br /&gt;many tags records, and any tag record can be related to many Entries.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;So how does this work? &amp;nbsp;When the user selects a tag name from the drop down list, Access fires the Combo Box AFTER UPDATE event. &amp;nbsp;This in turn executes the followingVBA code that I wrote for this event:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub comTag_AfterUpdate()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Dim varSQLWhere As String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; varSQLWhere = "tagId = '" &amp;amp; Me!comTag &amp;amp; "'"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.Close acForm, Me.Name&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenReport "rptTagSearch", acViewReport, , varSQLWhere&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: xx-small;"&gt;NB for sake of clarity, I have removed all code related to error handling.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The code begins by defining a string type variable called&amp;nbsp;&lt;b&gt;varSQLWhere &lt;/b&gt;- this is going to contain the code for an &lt;a href="http://ms-access-tips.blogspot.com/2011/05/gentle-introduction-to-access-sql.html" target="_blank"&gt;SQL WHERE&lt;/a&gt; clause (minus the WHERE keyword). &amp;nbsp;Next I set the value of this variable to &lt;b&gt;"tagId = '" &amp;amp; Me!comTag &amp;amp; "'"&lt;/b&gt;. &amp;nbsp;&lt;b&gt;TagId &lt;/b&gt;is the name of the primary key of the table containing all of the tag names. &amp;nbsp;In fact, &lt;b&gt;tblTags &lt;/b&gt;only contains this one field. &amp;nbsp;&lt;b&gt;Me!comTag &lt;/b&gt;is a reference to the name of the Combo box used on the search form. &amp;nbsp;Note the manner in which it has been concatenated into the string variable. Due to fact that the value contained in the combo box is itself a string, I have had to build two single quotation makes into the &lt;b&gt;varSQLWhere &lt;/b&gt;string. &amp;nbsp;So for example, if the user had selected the tag name 'Visual Studio' in the Combo Box, the contents of the string variable would be&amp;nbsp;&lt;b&gt;"tagId = 'Visual Studio'"&lt;/b&gt;&amp;nbsp;.&lt;br /&gt;&lt;br /&gt;The next line of code closes the search form so it does not get in the way when the form opens.&lt;br /&gt;&lt;br /&gt;The penultimate line of code is the &lt;b&gt;DoCmd.OpenReport&lt;/b&gt; method. &amp;nbsp;This not only opens our report, but also passes our &lt;b&gt;varSQLWhere &lt;/b&gt;variable as one of the method's parameters (the &lt;b&gt;WhereCondition&lt;/b&gt;). When this is passed, only records matching our &lt;b&gt;WhereCondition &lt;/b&gt;are displayed in the report results. &amp;nbsp;As such, our report effectively filters our report results by the tag name selected by the user in the search form combo box.&lt;br /&gt;&lt;br /&gt;It's not too difficult to apply this type of solution to the application that Marwa is building. The only real difference is that her Database search form consists of three combo boxes. &amp;nbsp;This means that she would also need to use a &amp;nbsp;Command Button ONCLICK event to start the search rather than relying on one of the Combo Box AfterUpdate Events. &amp;nbsp;Then she would need to construct the &lt;b&gt;varSQLWhere &lt;/b&gt;variable from all three combo box values. &amp;nbsp;This would look something like:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;span style="font-size: x-small;"&gt;varSQLWhere = "fld1 = '" &amp;amp; Me!Combo1 &amp;amp; "' AND fld2 = '" &amp;amp; Me!Combo2 &amp;amp; "' AND fld3 = '" &amp;amp; Me!Combo3 &amp;amp; "'"&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So its slightly more complicated, but the same principles apply.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-2641324450048296834?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/gRxvo37UuVDZcztwWz7XY6IvpZ8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gRxvo37UuVDZcztwWz7XY6IvpZ8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/gRxvo37UuVDZcztwWz7XY6IvpZ8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/gRxvo37UuVDZcztwWz7XY6IvpZ8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/AEnX9_myIeA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/2641324450048296834/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/01/using-vba-to-filter-report-results.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/2641324450048296834" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/2641324450048296834" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/AEnX9_myIeA/using-vba-to-filter-report-results.html" title="Using VBA to Filter Report Results" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-CTIf44JD498/Tw818zxdmSI/AAAAAAAAApA/oEULufdyRtg/s72-c/tag-search.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/01/using-vba-to-filter-report-results.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2207494623165917292</id><published>2012-01-06T06:07:00.000-08:00</published><updated>2012-01-06T06:07:51.026-08:00</updated><title type="text">Finding out Maximum and Minimum Value's - The DMax and DMin Functions</title><content type="html">So we have a table of sales figures for 2011. &amp;nbsp;Suppose we want to find out the largest and smallest sales value for the month of May. Access has two functions ideal for this task - these are the &lt;b&gt;DMax&lt;/b&gt; and &lt;b&gt;DMin &lt;/b&gt;functions.&lt;br /&gt;&lt;br /&gt;DMax and DMin basically examine a &lt;i&gt;domain &lt;/i&gt;of values, returning the largest and smallest value respectively. &amp;nbsp;The syntax for using these functions follow the same format as the other domain related functions such as &lt;a href="http://ms-access-tips.blogspot.com/2011/07/using-dlookup-function.html" target="_blank"&gt;DLookUp&lt;/a&gt; and &lt;a href="http://ms-access-tips.blogspot.com/2011/08/using-dsum-function.html" target="_blank"&gt;DSum &lt;/a&gt;which I blogged about last year. &amp;nbsp;As such, we pass parameters for &lt;b&gt;field name&lt;/b&gt;, the &lt;b&gt;domain&lt;/b&gt; from which the field belongs (the table or query, for example), and an optional &lt;b&gt;criteria &lt;/b&gt;if we are just interested in particular records (such as &lt;i&gt;May&lt;/i&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;sales for example).&lt;br /&gt;&lt;br /&gt;Lets take a look at the syntax for DMax and DMin respectively:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;DMax("fieldName", "tableName", "criteria")&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;pre&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;DMin("fieldName", "tableName", "criteria")&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;/pre&gt;This is the table that we are going to use in our particular scenario:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-IvRDLOewr74/TwbQPhRnvtI/AAAAAAAAAow/O336MOwItx8/s1600/order-table.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-IvRDLOewr74/TwbQPhRnvtI/AAAAAAAAAow/O336MOwItx8/s400/order-table.JPG" width="366" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;If you remember, we are interested in the largest and smallest sale during the month of &lt;i&gt;May&lt;/i&gt;. &amp;nbsp;As such, we are going to pass the field name &lt;b&gt;"Total"&amp;nbsp;&lt;/b&gt;for the first parameter, the table name&lt;b&gt; "tblOrders"&amp;nbsp;&lt;/b&gt;for the second, and the criteria&amp;nbsp;&lt;b&gt;"OrderDate &amp;gt;= #05/01/2011# and OrderDate &amp;lt;= #05/31/2011#" &lt;/b&gt;for the third. &amp;nbsp;Note the third criteria is basically a &lt;a href="http://ms-access-tips.blogspot.com/2011/05/gentle-introduction-to-access-sql.html" target="_blank"&gt;SQL WHERE&lt;/a&gt; Statement (without the WHERE keyword) and uses the &lt;i&gt;American Date Format &lt;/i&gt;(ie &amp;nbsp;&lt;i&gt;Month&lt;/i&gt;/&lt;i&gt;Day&lt;/i&gt;/&lt;i&gt;Year&lt;/i&gt;), rather than&amp;nbsp;the&amp;nbsp;International Date Format. &amp;nbsp;This is the full syntax:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;DMin("Total", "tblOrders", "OrderDate &amp;gt;= #5/1/2011# and OrderDate &amp;lt;= #5/31/2011#")&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In previous posts I have shown you how to use Access Functions in Queries and Calculated Controls&amp;nbsp;(see posts on&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/08/calculating-date-difference-using.html" target="_blank"&gt;Calculating Date Difference&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/07/using-dlookup-function.html" target="_blank"&gt;DLookUp&lt;/a&gt;). &amp;nbsp;For this example I would like to use the function within a &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;VBA sub procedure&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I have created a form with an unbound text box called &lt;b&gt;txtResult &lt;/b&gt;and two command buttons, &lt;b&gt;cmdMax &lt;/b&gt;and &lt;b&gt;cmdMin&lt;/b&gt;. &amp;nbsp;When the user clicks one of the command buttons - lets say it is the &lt;b&gt;cmdMax &lt;/b&gt;button&amp;nbsp;- the VBA procedure containing the DMax function runs, calculating the maximum sale for the month of May, and displaying the result in &lt;b&gt;txtResult&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-47GBiykyvm0/TwbYe9KlowI/AAAAAAAAAo4/xsnfOFkS1qA/s1600/form.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="217" src="http://3.bp.blogspot.com/-47GBiykyvm0/TwbYe9KlowI/AAAAAAAAAo4/xsnfOFkS1qA/s400/form.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Here is the VBA code that I used:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub cmdMax_Click()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Dim varMax As Currency&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; varMax = DMax("Total", "tblOrders", "OrderDate &amp;gt;= #5/1/2011# and OrderDate &amp;lt;= #5/31/2011#")&lt;/span&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Me!txtResult = varMax&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub cmdMin_Click()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Dim varMin As Currency&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; varMin = DMin("Total", "tblOrders", "OrderDate &amp;gt;= #5/1/2011# and OrderDate &amp;lt;= #5/31/2011#")&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Me!txtResult = varMin&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you can see each sub runs when it's respective command button's ONCLICK event is triggered. &amp;nbsp;The result returned by the function is stored in a currency type variable called &lt;b&gt;varMax &lt;/b&gt;or &lt;b&gt;varMin&lt;/b&gt;. &amp;nbsp;The value of &lt;b&gt;txtResult &lt;/b&gt;is then set to that of the variable in order to display the result.&lt;br /&gt;&lt;br /&gt;You can download this &lt;a href="http://www.dealing-with-data.net/exercises/D_Max_Min_Example.accdb"&gt;DMax/Min&lt;/a&gt; example database by clicking the link. &amp;nbsp;Please feel free to experiment &amp;nbsp;using different criteria and adding new data to the table etc.&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-2207494623165917292?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-4X1mufZI4U0tgx0PQQ8Ca5FCc8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-4X1mufZI4U0tgx0PQQ8Ca5FCc8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-4X1mufZI4U0tgx0PQQ8Ca5FCc8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-4X1mufZI4U0tgx0PQQ8Ca5FCc8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/AIwqUmE7oF4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/2207494623165917292/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2012/01/finding-out-maximum-and-minimum-values.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/2207494623165917292" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/2207494623165917292" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/AIwqUmE7oF4/finding-out-maximum-and-minimum-values.html" title="Finding out Maximum and Minimum Value's - The DMax and DMin Functions" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-IvRDLOewr74/TwbQPhRnvtI/AAAAAAAAAow/O336MOwItx8/s72-c/order-table.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2012/01/finding-out-maximum-and-minimum-values.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-6227059166329857655</id><published>2011-12-15T12:34:00.000-08:00</published><updated>2011-12-16T02:06:40.737-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="dLookUp" /><category scheme="http://www.blogger.com/atom/ns#" term="properties" /><category scheme="http://www.blogger.com/atom/ns#" term="events" /><category scheme="http://www.blogger.com/atom/ns#" term="Controls" /><category scheme="http://www.blogger.com/atom/ns#" term="enabled" /><title type="text">Enable and Disable a Form Control using VBA</title><content type="html">Earlier this week I was working on a design for an Order Management Database, and one of the tasks I dealt with involved dynamically Enabling or Disabling one of the form's Command Buttons' using &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;VBA&lt;/a&gt;. &amp;nbsp;This gave me the idea for the present Access tip.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The command button was located on a Customer Details form which had an Orders Subform in the lower section. &amp;nbsp;The reason I wanted to Enable or Disable the Command Button (located on the parent form), was that it was used to Delete the selected record highlighted in the Orders Subform's datasheet. I needed to get the Delete Button to enforce the business rule whereby &lt;i&gt;once an order has been confirmed, it should not be deleted&lt;/i&gt;. As such, if the user highlighted a &lt;i&gt;confirmed &lt;/i&gt;order in the subform, the &lt;b&gt;Delete &lt;/b&gt;button is dynamically disabled, and vice versa.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To do this I made use of the Order Subforms ON CURRENT &lt;a href="http://ms-access-tips.blogspot.com/2011/11/using-events-and-manipulating-property.html" target="_blank"&gt;event&lt;/a&gt;. &amp;nbsp;This event is triggered whenever the focus moves from one record to another, or when the first record receives the focus as the form opens. &amp;nbsp;As such, if a user selects a record in the subform datasheet by clicking on one of the rows, the subform's ON CURRENT event fires. &amp;nbsp;This is the code I wrote to determine whether the Delete button should be Enabled or Disabled.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;If IsNull(DLookup("OrderConfirmed", "tblOrders", "OrderId = " &amp;amp; Me!OrderId)) = False Then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Forms!frmcustomer!ctlDeleteOrder.Enabled = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Forms!frmcustomer!ctlDeleteOrder.Enabled = True&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End If&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;As you can see, I have used an &lt;a href="http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html" target="_blank"&gt;If ... Then ... Else&lt;/a&gt; Statement to determine whether or not the Order has been confirmed. &amp;nbsp;In order to create the conditional expression, I used the &lt;b&gt;IsNull&lt;/b&gt; and &lt;a href="http://ms-access-tips.blogspot.com/2011/07/using-dlookup-function.html" target="_blank"&gt;&lt;b&gt;DLookUp&lt;/b&gt;&lt;/a&gt; functions together to see if &amp;nbsp;the &lt;b&gt;OrderConfirmed &lt;/b&gt;field of &lt;b&gt;tblOrders &lt;/b&gt;contained a date. The&amp;nbsp;&lt;b&gt;IsNull &lt;/b&gt;function&amp;nbsp;returns a boolean value, True or False, to indicate whether its parameter&amp;nbsp;&lt;/span&gt;(in this case the result of a DLookUp function) &lt;u&gt;is&lt;/u&gt; or &lt;u&gt;is not&lt;/u&gt; &lt;i&gt;null&lt;/i&gt;;&amp;nbsp; and the DLookUp function, looks up the value contained in the &lt;b&gt;OrderConfirmed &lt;/b&gt;field of &lt;b&gt;tblOrders &lt;/b&gt;&lt;i&gt;where &lt;/i&gt;&lt;b&gt;OrderId &lt;/b&gt;matches that of the current record displayed on the Orders subform. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Since the presence of a date in the OrderConfirmed field indicates that the order &lt;i&gt;has &lt;/i&gt;been confirmed, the &lt;b&gt;IsNull &lt;/b&gt;function returning the value of FALSE (remember this is a double negative!), tells us the order &lt;i&gt;has indeed &lt;/i&gt;been confirmed, and vice versa. &amp;nbsp; As such, when the condition of the first line of the If Statement is False, the Delete Command Button on the main form should be disabled. &amp;nbsp;This is done by referencing the Delete Command Button's ENABLED property, and setting it to FALSE:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp;Forms!frmcustomer!ctlDeleteOrder.Enabled = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;And if the result of the If ... Then ... Else Statement had returned TRUE, the Delete Command Button is Enabled by setting it's ENABLED property to TRUE:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Forms!frmcustomer!ctlDeleteOrder.Enabled = True&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 class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-6227059166329857655?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4bLAzPS1_wZPqVjmZQAqU5TNpTM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4bLAzPS1_wZPqVjmZQAqU5TNpTM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4bLAzPS1_wZPqVjmZQAqU5TNpTM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4bLAzPS1_wZPqVjmZQAqU5TNpTM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/LOsqzCC8WZI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/6227059166329857655/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/12/enable-and-disable-form-control-using.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/6227059166329857655" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/6227059166329857655" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/LOsqzCC8WZI/enable-and-disable-form-control-using.html" title="Enable and Disable a Form Control using VBA" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/12/enable-and-disable-form-control-using.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4236020122997466924</id><published>2011-12-09T02:39:00.000-08:00</published><updated>2011-12-09T02:44:18.461-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="calculated field" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="expressions" /><title type="text">An Expression to Obtain a Full Name from Three Separate Fields</title><content type="html">There is a very good reason why we separate name fields when we create an &lt;a href="http://www.dealing-with-data.net/create-access-table.html" target="_blank"&gt;Access Table&lt;/a&gt;. &amp;nbsp;If we store the &lt;i&gt;Title&lt;/i&gt;, &lt;i&gt;First Name&lt;/i&gt; and S&lt;i&gt;urname &lt;/i&gt;in a single field, we limit the capability of our application to interrogate this part of our data. &amp;nbsp;For example, if we store a full name in a single field, we would not be able to sort a list of names into alphabetical order (because Access cannot differentiate between a title, first name and surname). Moreover, we would also not be able to&amp;nbsp;extract just the &lt;i&gt;title &lt;/i&gt;and &lt;i&gt;surname &lt;/i&gt;in order to address a letter. This is because the individuals first name comes in between, thereby preventing us from using the name in a mail merge operation.&lt;br /&gt;&lt;br /&gt;As such, there is a general database design convention of storing all the elements of a name in separate fields. This gives us maximum flexibility and control when we come to process this data. &amp;nbsp;What's more, we still have the capability of joining (concatenating) the full name back together again through use of an expression in a query's &lt;i&gt;calculated field&lt;/i&gt;, for example. &amp;nbsp;So how is this done exactly?&lt;br /&gt;&lt;br /&gt;Imagine we have a list of names stored in a table. &amp;nbsp;We have separate fields for &lt;b&gt;Title&lt;/b&gt;, &lt;b&gt;FirstName&lt;/b&gt;, and&amp;nbsp;&lt;b&gt;Surname&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-VKoxAB6_E2A/TuEVq7tCzTI/AAAAAAAAAn0/-K1VpUwm0EU/s1600/names.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="210" src="http://2.bp.blogspot.com/-VKoxAB6_E2A/TuEVq7tCzTI/AAAAAAAAAn0/-K1VpUwm0EU/s320/names.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; &amp;nbsp;An Access Table containing a list of names&lt;br /&gt;stored in separate fields.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;The expression we are going to use to concatenate the name into a single whole is as follows:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [Title] &amp;amp;" " &amp;amp; [FirstName] &amp;amp; " " &amp;amp; [Surname]&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;The three fields are separated by two ampersands (&amp;amp;), and a string containing a single space in between. &amp;nbsp;The ampersand concatenates the various elements of the name, and the empty space between the quotation marks simply creates a space between the three fields when joined together. &amp;nbsp;So we have a total of &lt;i&gt;five &lt;/i&gt;separate elements concatenated by the ampersand operator - ie &lt;b&gt;Title &lt;/b&gt;&amp;amp;&amp;nbsp;&lt;b&gt;space &lt;/b&gt;&amp;amp;&amp;nbsp;&lt;b&gt;FirstName&lt;/b&gt; &amp;amp;&amp;nbsp;&lt;b&gt;space &lt;/b&gt;&amp;amp;&amp;nbsp;&lt;b&gt;Surname&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;As mentioned above, this expression can be used in a calculated field of an &lt;a href="http://www.dealing-with-data.net/create-access-query.html" target="_blank"&gt;Access Query&lt;/a&gt;. &amp;nbsp;To do so, just enter an alias (ie the name we are going to call the calculated field) with a colon &lt;i&gt;in front&lt;/i&gt; of the expression. &amp;nbsp;For example:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FullName:&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;[Title] &amp;amp; " " &amp;amp; [FirstName] &amp;amp; " " &amp;amp; [Surname]&lt;/b&gt;&lt;br /&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;This is entered into the FIELD row of the query design grid as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-QyI3FTR8AmY/TuEdIzTSqbI/AAAAAAAAAoE/Ld_ych5JBf4/s1600/calculated-field.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="325" src="http://4.bp.blogspot.com/-QyI3FTR8AmY/TuEdIzTSqbI/AAAAAAAAAoE/Ld_ych5JBf4/s400/calculated-field.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; Expression to concatenate a full name&lt;br /&gt;entered into the Query Design Grid.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Then, when we run the query we get a list of full names, each one &lt;i&gt;appearing &lt;/i&gt;as a single field:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-d6Zpao8Kkqw/TuEhKJFZr6I/AAAAAAAAAok/efT-xR5WOpQ/s1600/concatenated-names.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-d6Zpao8Kkqw/TuEhKJFZr6I/AAAAAAAAAok/efT-xR5WOpQ/s400/concatenated-names.JPG" width="286" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; Concatenated Names appearing in&lt;br /&gt;Query Result.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-4236020122997466924?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pArk5JuoKTC0lIZvbuOdQhS3k0k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pArk5JuoKTC0lIZvbuOdQhS3k0k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pArk5JuoKTC0lIZvbuOdQhS3k0k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pArk5JuoKTC0lIZvbuOdQhS3k0k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/DWLTZtmt0Sw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/4236020122997466924/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/12/expression-to-obtain-full-name-from.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/4236020122997466924" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/4236020122997466924" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/DWLTZtmt0Sw/expression-to-obtain-full-name-from.html" title="An Expression to Obtain a Full Name from Three Separate Fields" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-VKoxAB6_E2A/TuEVq7tCzTI/AAAAAAAAAn0/-K1VpUwm0EU/s72-c/names.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/12/expression-to-obtain-full-name-from.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-8941822291193573621</id><published>2011-12-01T12:22:00.000-08:00</published><updated>2011-12-02T05:52:22.605-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="reports" /><title type="text">Adding a Group and Sort to an Access Report</title><content type="html">Adding a &lt;i&gt;Group &lt;/i&gt;and &lt;i&gt;Sort &lt;/i&gt;to an Access Report has the potential to make our data much easier to read. &amp;nbsp;This is because our information may appear in a clear and more logical format. Take a list of Contacts for example. &amp;nbsp;We may have a number of contacts working for the same organisation: wouldn't it be convenient for our contact list to be &lt;i&gt;grouped by organisation&lt;/i&gt;? Then, depending on how many contacts we have within each organization, it may also make sense to &lt;i&gt;sort &lt;/i&gt;each organizations' contact's into alphabetical order.&lt;br /&gt;&lt;br /&gt;So instead of having a list like this:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-yjODHScLu44/TtfeLKq-nHI/AAAAAAAAAm8/xKDhIUUwF1Y/s1600/all-contacts.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="425" src="http://4.bp.blogspot.com/-yjODHScLu44/TtfeLKq-nHI/AAAAAAAAAm8/xKDhIUUwF1Y/s640/all-contacts.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; Contact list without &lt;i&gt;Group &lt;/i&gt;or &lt;i&gt;Sort&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;We have a list like this:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-4WEOGXZE_8A/Ttfee4BPLaI/AAAAAAAAAnM/x7elTa7XkDY/s1600/contacts-by-organization.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-4WEOGXZE_8A/Ttfee4BPLaI/AAAAAAAAAnM/x7elTa7XkDY/s1600/contacts-by-organization.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; Contact list &lt;i&gt;grouped &lt;/i&gt;by Company and &lt;i&gt;sorted&lt;/i&gt; by surname and first name.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Both contain exactly the same data, but the list in figure 2 has been &lt;i&gt;grouped &lt;/i&gt;by company and &lt;i&gt;sorted &lt;/i&gt;by surname and first name (within each group). &amp;nbsp;You can download these reports by clicking this link: &lt;a href="http://www.dealing-with-data.net/exercises/GroupAndSort.accdb"&gt;Group and Sort Sample Database&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Lets take a look at how these reports were created.&lt;br /&gt;&lt;br /&gt;I began by creating the report from &lt;i&gt;figure 1&lt;/i&gt;. I&amp;nbsp;then opened it in DESIGN VIEW and added the &lt;i&gt;Group &lt;/i&gt;and &lt;i&gt;Sorts&lt;/i&gt;&amp;nbsp;before re-aligning the columns. &amp;nbsp;Here are the step by step instructions:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Stage One - Create a Basic Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Highlight the &lt;i&gt;Contacts Table&lt;/i&gt; in the NAVIGATION PANE. &amp;nbsp;The table in the sample database is called &lt;b&gt;tblContacts&lt;/b&gt;, and it is the RECORD SOURCE for both Reports.&lt;/li&gt;&lt;li&gt;Click the REPORT icon (located in the REPORTS group of the CREATE ribbon). &amp;nbsp;This is the quickest way to create a report based on a particular record source.&lt;br /&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-nnMufNwFOy4/TtikVJbN0hI/AAAAAAAAAnU/IVsX7F1G0s8/s1600/report-icon.JPG" /&gt;&lt;/li&gt;&lt;li&gt;When the report opens in LAYOUT VIEW, click this symbol: &amp;nbsp;&lt;img border="0" src="http://1.bp.blogspot.com/-6jTzU-q6lh0/TtimNuin3NI/AAAAAAAAAnc/cbVzRn6Aans/s1600/remove.JPG" /&gt;&amp;nbsp;(it should be located at the top left corner of the ID column). &amp;nbsp;This highlights all the cells which are currently joined together.&amp;nbsp;&lt;/li&gt;&lt;li&gt;Then click the REMOVE icon to separate them. &amp;nbsp;This icon is located in the CONTROL LAYOUT group of the ARRANGE ribbon. &amp;nbsp;It will now be possible to move individual text boxes and labels independently when we go to DESIGN VIEW. &amp;nbsp;However, before we do that, we shall first add the &lt;i&gt;Group &lt;/i&gt;and &lt;i&gt;Sorts&lt;/i&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large; font-weight: bold;"&gt;Stage Two - Adding the Group and Sorts&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Select the HOME ribbon, and then pick DESIGN VIEW from the VIEWS group.&lt;/li&gt;&lt;li&gt;Make sure the GROUP, SORT AND TOTAL icon is highlighted (it is located in the GROUPING AND TOTALS group of the DESIGN ribbon). &amp;nbsp;You should see the GROUP, SORT AND TOTALS pane open below the DESIGN GRID.&lt;/li&gt;&lt;li&gt;Click ADD A GROUP from the GROUP, SORT AND TOTALS pane (see &lt;i&gt;figure 3&lt;/i&gt; below).&lt;/li&gt;&lt;li&gt;Then select the &lt;b&gt;Company &lt;/b&gt;field from the list which appears. &amp;nbsp;This creates a &lt;b&gt;Company Header &lt;/b&gt;(see &lt;i&gt;figure 4 &lt;/i&gt;below).&lt;/li&gt;&lt;li&gt;Highlight the Company text box and make sure no other controls are highlighted.&lt;/li&gt;&lt;li&gt;Cut and past the Company text box so that it is positioned close to the left margin within the &lt;b&gt;Company Header&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Reposition the labels and text boxes so that they are aligned in a neat logical fashion (see figure 4 below).&lt;/li&gt;&lt;li&gt;Next click ADD A SORT in the GROUP, SORT AND TOTALS pane. &amp;nbsp;&lt;/li&gt;&lt;li&gt;Then select &lt;b&gt;Surname &lt;/b&gt;from the list. &amp;nbsp;Notice how a new level has been created below the&amp;nbsp;&lt;b&gt;Company Group&lt;/b&gt;. &amp;nbsp;This is because we want Access to apply the &lt;i&gt;group &lt;/i&gt;first and then sort the surnames &lt;i&gt;within &lt;/i&gt;the&amp;nbsp;group.&lt;/li&gt;&lt;li&gt;Click ADD A SORT again.&lt;/li&gt;&lt;li&gt;Then select &lt;b&gt;Firstname &lt;/b&gt;from the list. This creates another sort, but this time on &lt;b&gt;Firstname&lt;/b&gt;. &amp;nbsp;Notice how this sort is on a level below the first sort. &amp;nbsp;This is because we want Access to begin by sorting the &lt;i&gt;&lt;b&gt;Surnames&lt;/b&gt;&lt;/i&gt;, and then if there are duplicates, to sort on &lt;b&gt;FirstName&lt;/b&gt;. &amp;nbsp;This follows the general convention of placing the &lt;i&gt;whole&amp;nbsp;&lt;/i&gt;name in alphabetical order.&lt;/li&gt;&lt;/ol&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ULORokXIAXE/TtizSz3PH7I/AAAAAAAAAns/MdDq7m_jorg/s1600/group-sort-total-pane.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="97" src="http://4.bp.blogspot.com/-ULORokXIAXE/TtizSz3PH7I/AAAAAAAAAns/MdDq7m_jorg/s640/group-sort-total-pane.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3: &lt;/b&gt;The &lt;i&gt;Group, Sort and Total &lt;/i&gt;pane.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-bwTHu4ly1xM/TtizQKavvII/AAAAAAAAAnk/XLkU8QMAuAc/s1600/design-view.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="444" src="http://1.bp.blogspot.com/-bwTHu4ly1xM/TtizQKavvII/AAAAAAAAAnk/XLkU8QMAuAc/s640/design-view.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: &lt;/b&gt;Report Design View showing a &lt;i&gt;Group Header&lt;/i&gt; for the &lt;b&gt;Company &lt;/b&gt;field.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;You can now open the report in REPORT VIEW to see the grouped and sorted results.&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;/ol&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-8941822291193573621?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/EbsSI3Ao5sm8d8JjqoEBAfvKYlg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EbsSI3Ao5sm8d8JjqoEBAfvKYlg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/EbsSI3Ao5sm8d8JjqoEBAfvKYlg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EbsSI3Ao5sm8d8JjqoEBAfvKYlg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/2r2DrCHLkHc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/8941822291193573621/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/12/adding-group-and-sort-to-access-report.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/8941822291193573621" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/8941822291193573621" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/2r2DrCHLkHc/adding-group-and-sort-to-access-report.html" title="Adding a Group and Sort to an Access Report" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-yjODHScLu44/TtfeLKq-nHI/AAAAAAAAAm8/xKDhIUUwF1Y/s72-c/all-contacts.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/12/adding-group-and-sort-to-access-report.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-7216282913474964001</id><published>2011-11-24T10:55:00.001-08:00</published><updated>2011-11-25T11:25:37.659-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><title type="text">Using Events and Manipulating Property Settings - Learning Access VBA - Tutorial 4</title><content type="html">&lt;br /&gt;This is the last post in the&amp;nbsp;series of&amp;nbsp;introductory&amp;nbsp;tutorials on&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt;. &amp;nbsp;So far we have covered a wide range of areas - the&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;VBA Development Environment, variables, referencing form controls&lt;/a&gt;, the conditional&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html" target="_blank"&gt;IF ... THEN... ELSE&lt;/a&gt;&amp;nbsp;statement, and&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/11/introduction-to-vba-loops-learning.html" target="_blank"&gt;Loops&lt;/a&gt;. &amp;nbsp;There is still much more we could have covered, even at an introductory level (arrays for example). &amp;nbsp;However, I wanted to end the series by focusing on how we use VBA to automate the access database applications that we create. &amp;nbsp;To do this we are going to examine how to trigger our VBA code through tapping into events and manipulating form property values.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Using Events&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If you have been following the&amp;nbsp;&lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt;&amp;nbsp;series, you will already be familiar with the Command Button's&amp;nbsp;&lt;b&gt;ON CLICK&lt;/b&gt;&amp;nbsp;event. &amp;nbsp;The user clicks the command button at run time thereby firing the ON CLICK event, which in turn triggers any code that we have written in that event's sub routine. There are many more events which we can also use to trigger our code. &amp;nbsp;A text box control has, for example, an&amp;nbsp;&lt;b&gt;ENTER&amp;nbsp;&lt;/b&gt;event and an&amp;nbsp;&lt;b&gt;EXIT&amp;nbsp;&lt;/b&gt;event. &amp;nbsp;The ENTER event fires when the user moves the cursor into the text box, and the EXIT event fires when it moves out again. &amp;nbsp;The code that you may attach to such events depends entirely on the particular needs of the application. &amp;nbsp;The point is, they are there to use&lt;i&gt;&amp;nbsp;if&lt;/i&gt;&amp;nbsp;we have written any code to trigger in response to the particular event in question.&lt;br /&gt;&lt;br /&gt;So far I have only mentioned events for individual&amp;nbsp;&lt;i&gt;controls&lt;/i&gt;. &amp;nbsp;Some of the more important events, however, occur at&amp;nbsp;&lt;i&gt;Form&amp;nbsp;&lt;/i&gt;or&amp;nbsp;&lt;i&gt;Report&amp;nbsp;&lt;/i&gt;level. &amp;nbsp; These include the Forms ON CURRENT, BEFORE UPDATE and ON LOAD events. &amp;nbsp;The ON CURRENT event fires just before a form displays a new record; BEFORE UPDATE occurs just before the record is saved; and the ON LOAD event occurs as a form loads data contained in a table, or derived from a query.&lt;br /&gt;&lt;br /&gt;You can see the whole range of form or reports events by opening the PROPERTIES pane (whilst in design view) and clicking the EVENTS tab. &amp;nbsp;In today's exercise, however, we are just going to focus on the form&amp;nbsp;&lt;b&gt;ON OPEN&lt;/b&gt;&amp;nbsp;event. &amp;nbsp;This fires as the form opens, but before any data is loaded from the forms RECORD SOURCE. &amp;nbsp;As such it occurs before the ON LOAD even which was mentioned above. &amp;nbsp;Consequently, this is a good event to use for triggering code for tasks like prompting the user for parameters, applying filters, or even changing the form's RECORD SOURCE property. &amp;nbsp;In the exercise we shall be doing, we are going to use the ON LOAD event to determine whether a form opens in DATA ENTRY, EDIT or read only mode. Before we begin, lets first take a look at how we can manipulate form properties using VBA code.&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;a href="http://3.bp.blogspot.com/-M_ChuHXx_h0/Ts9odyFy5jI/AAAAAAAAAmc/nJpQX3EKoI8/s1600/events-tab.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-M_ChuHXx_h0/Ts9odyFy5jI/AAAAAAAAAmc/nJpQX3EKoI8/s400/events-tab.JPG" width="237" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="font-size: 13px;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt;&amp;nbsp;Some of the&amp;nbsp;&lt;b&gt;Events&amp;nbsp;&lt;/b&gt;listed in the&lt;br /&gt;&lt;b&gt;EVENTS&lt;/b&gt;&amp;nbsp;tab&amp;nbsp;of the&amp;nbsp;&lt;b&gt;PROPERTY SHEET&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Manipulating Properties&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You may already have experience of setting properties&amp;nbsp;in Design View&amp;nbsp;using the PROPERTIES sheet . &amp;nbsp;With VBA we can also read, test and dynamically change property setting during runtime. &amp;nbsp;The key to doing this is understanding how to correctly reference the property of the control, form or report. &amp;nbsp;This task is easier when our code is contained within the VBA Module of the form or report being referenced. &amp;nbsp;Suppose we want to reference the DATA ENTRY property of a form called&amp;nbsp;&lt;b&gt;frmCustomers&lt;/b&gt;. &amp;nbsp;If we were referencing the property from the VBA module attached to&amp;nbsp;&lt;b&gt;frmCustomers&amp;nbsp;&lt;/b&gt;we can use the&amp;nbsp;&lt;b&gt;ME&amp;nbsp;&lt;/b&gt;keyword. &amp;nbsp;This acts as a short cut when referencing the attached form. &amp;nbsp;This is how it works:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Me.DataEntry&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;If, on the other hand, we were attempting to make the same reference from a module outside of frmCustomer we would need to write the full reference like this:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Forms![frmCustomers].DataEntry&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;As you can see, we not only need to write the name of the form in question but we also need to specify the FORMS collection object to which it belongs. &amp;nbsp;It is also worth pointing out that in VBA we use the exclamation mark (&lt;b&gt;!&lt;/b&gt;) to separate two objects when the preceding object&amp;nbsp;&lt;i&gt;belongs&amp;nbsp;&lt;/i&gt;to the one coming after, but we use the full stop (&lt;b&gt;.&lt;/b&gt;) to separate an object from one of its&amp;nbsp;&lt;i&gt;properties&lt;/i&gt;. &amp;nbsp;Any&amp;nbsp;&lt;i&gt;form&lt;/i&gt;,&amp;nbsp;&lt;i&gt;report&amp;nbsp;&lt;/i&gt;or&amp;nbsp;&lt;i&gt;control&amp;nbsp;&lt;/i&gt;name in the reference also need to be contained within square brackets if the name contains a space or a reserved word (but this is not essential if the name is constructed without these 'problematic' elements).&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Now we know how to create property references, we can use them in our code to read, test or dynamically change property values. For example:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;To store a property setting in a variable called varDataEntry:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; varDataEntry = Me.DataEntry&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;To test the value of a property setting:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; If Me.DataEntry = true Then&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;To change the value of a property setting:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Me.DataEntry = False&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Exercise&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the following exercise we are going to create a switchboard form with three command buttons - these are &lt;b&gt;ctlAdd&lt;/b&gt;, &lt;b&gt;ctlEdit &lt;/b&gt;and &lt;b&gt;ctlRead&lt;/b&gt;. All three buttons open the same form, &lt;b&gt;frmContacts&lt;/b&gt;, but the first button opens the form in &lt;i&gt;Data Entry&lt;/i&gt; mode, the second in &lt;i&gt;Edit&lt;/i&gt; mode and the third as&lt;i&gt; Read Only&lt;/i&gt;. &amp;nbsp;So how does it do this?&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-4MMQPQAaWG0/Ts_gLzl9UkI/AAAAAAAAAms/ATMflPJWews/s1600/switchboard.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="195" src="http://4.bp.blogspot.com/-4MMQPQAaWG0/Ts_gLzl9UkI/AAAAAAAAAms/ATMflPJWews/s320/switchboard.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: frmSwitchboard&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;When the user clicks one of the command buttons, it fires the command button's ON CLICK event where there is some VBA code to open the form with the DoCmd.OpenForm method. &amp;nbsp;One of the parameters of the OpenForm method passes an &lt;b&gt;OpenArgs&amp;nbsp;&lt;/b&gt;parameter to &lt;b&gt;frmContact&lt;/b&gt;. &amp;nbsp;The value of this parameter (which is a string) is then stored by Access in &lt;b&gt;frmContacts &lt;/b&gt;OPENARGS (Open Argument's) property.&lt;br /&gt;&lt;br /&gt;As &lt;b&gt;frmContacts &lt;/b&gt;opens, the ON OPEN event fires, triggering another block of VBA code. &amp;nbsp;This code tests the value of the forms OPENARGS property using the &lt;a href="http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html" target="_blank"&gt;IF ... THEN ... ELSE&lt;/a&gt; statement. This is to ascertain whether the value contained in the OPENARGS property is &amp;nbsp;"&lt;i&gt;Add&lt;/i&gt;", "&lt;i&gt;Edit&lt;/i&gt;" or "&lt;i&gt;Read&lt;/i&gt;". &amp;nbsp;These were passed by the OpenForm method as mentioned above. &amp;nbsp;If the OPENARGS property value is "Add" our code will set the form's DATA ENTRY property to TRUE; if the value is "Edit", DATA ENTRY is set to FALSE; if "Read", the DATA ENTRY, ALLOW ADDITIONS, ALLOW DELETIONS, and ALLOW EDITS properties are all set to FALSE.&lt;br /&gt;&lt;br /&gt;You can download the completed solution by clicking this link: &lt;a href="http://www.dealing-with-data.net/exercises/OnLoadExample.accdb" target="_blank"&gt;Events and Properties Exercise&lt;/a&gt;. &amp;nbsp;The instruction for creating the exercise follow below:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Stage One - Creating the Switchboard&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create an unbound switchboard form called &lt;b&gt;frmSwitchBoard&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Add three Command Buttons called &lt;b&gt;ctlAdd&lt;/b&gt;, &lt;b&gt;ctlEdit&lt;/b&gt;, and &lt;b&gt;ctlRead&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Attach the following code to the Command Button's &lt;b&gt;ON CLICK&lt;/b&gt; event - see the first tutorial in the &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning AccessVBA&lt;/a&gt; series if you need help doing this.&lt;/li&gt;&lt;/ol&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub ctlAdd_Click()&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenForm "frmContacts", , , , , , "add"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub ctlEdit_Click()&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenForm "frmContacts", , , , , , "edit"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub ctlExit_Click()&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; Application.Quit&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub ctlRead_Click()&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenForm "frmContacts", , , , , , "read"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;NB You may have noticed there are a number of blank parameters passed in our use of the OpenForm method - hence the comma's . &amp;nbsp;That is because many of the parameters are optional. &amp;nbsp;We are just passing two parameters - the name of the form to be opened, and the OpenArgs parameter as discussed above. &amp;nbsp; Incidentally we could have used the &lt;b&gt;DataMode &lt;/b&gt;parameter to accomplish the object of this exercise more directly, but I wanted &amp;nbsp;to demonstrate the working of the form ON LOAD event. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Stage Two - Creating frmContacts&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Before you create &lt;b&gt;frmContacts &lt;/b&gt;you will first need to create the table - &lt;b&gt;tblContacts &lt;/b&gt;- which is going to be its record source. &amp;nbsp;It's not particularly import which fields are used, but the example database I created has 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;Company&lt;/b&gt;, and the following sample data:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-_RIAUVNaLGc/Ts_frz2Uj6I/AAAAAAAAAmk/CeqTGH5NzQE/s1600/sample-data.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="258" src="http://1.bp.blogspot.com/-_RIAUVNaLGc/Ts_frz2Uj6I/AAAAAAAAAmk/CeqTGH5NzQE/s320/sample-data.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3: tblContacts&lt;/b&gt; with sample data.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-5P1B7aL4cck/Ts_mNbSywmI/AAAAAAAAAm0/hSfI8QHsERI/s1600/contacts-form.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="237" src="http://2.bp.blogspot.com/-5P1B7aL4cck/Ts_mNbSywmI/AAAAAAAAAm0/hSfI8QHsERI/s400/contacts-form.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: frmContacts&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a new form called &lt;b&gt;frmContacts&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Set the forms RECORD SOURCE property to tblContacts.&lt;/li&gt;&lt;li&gt;Add the four fields of tblContacts to the form&lt;/li&gt;&lt;li&gt;Add the following code to the forms ON OPEN event:&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub Form_Open(Cancel As Integer)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; If Me.OpenArgs = "add" Then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.DataEntry = True&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; ElseIf Me.OpenArgs = "edit" Then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.DataEntry = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; ElseIf Me.OpenArgs = "read" Then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.DataEntry = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.AllowAdditions = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.AllowDeletions = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Me.AllowEdits = False&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp; &amp;nbsp; End If&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;When you have done this, save your work, and open the switchboard to try out the different buttons.&lt;br /&gt;&lt;br /&gt;This concludes the &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html"&gt;Learning Access VBA&lt;/a&gt; series of tutorials. &amp;nbsp;I hope you have found them helpful, and that they have given you a basic introduction to&amp;nbsp;Access&amp;nbsp;programming . &amp;nbsp;I intend to cover more advanced VBA topics next year.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-7216282913474964001?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LaBzib3PqZ_u2e1JoFywvv6TNg0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LaBzib3PqZ_u2e1JoFywvv6TNg0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LaBzib3PqZ_u2e1JoFywvv6TNg0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LaBzib3PqZ_u2e1JoFywvv6TNg0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/SbKaRCKbloQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/7216282913474964001/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/11/using-events-and-manipulating-property.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/7216282913474964001" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/7216282913474964001" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/SbKaRCKbloQ/using-events-and-manipulating-property.html" title="Using Events and Manipulating Property Settings - Learning Access VBA - Tutorial 4" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-M_ChuHXx_h0/Ts9odyFy5jI/AAAAAAAAAmc/nJpQX3EKoI8/s72-c/events-tab.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/11/using-events-and-manipulating-property.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-3431816813600482144</id><published>2011-11-18T02:22:00.001-08:00</published><updated>2012-02-26T08:32:48.897-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Immediate Window" /><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="Debug" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><category scheme="http://www.blogger.com/atom/ns#" term="Loops" /><title type="text">Introduction to VBA Loops - Learning Access VBA Tutorial 3</title><content type="html">This is the third tutorial in the &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt; series. In the first tutorial we learnt how to create a simple &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;VBA Sub Procedure&lt;/a&gt; and set up up &lt;i&gt;Variables&lt;/i&gt;; and in the second, we looked at &lt;a href="http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html" target="_blank"&gt;Evaluating Conditions&lt;/a&gt; with the IF THEN ELSE statement. &amp;nbsp;Today we are going to move on to VBA&lt;i&gt; Loops&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Loops are are common feature of most programming languages, and VBA is no exception. &amp;nbsp;Loops enable lines within in a defined section of code to be repeated as many times as is necessary, until a specific point is reached when the program flow may move on to the next section of code. &amp;nbsp;There are different kinds of loops in VBA. &amp;nbsp;The &lt;b&gt;FOR ... NEXT&lt;/b&gt; loop, for example, repeats the loop a set number of times. &amp;nbsp;We would use &amp;nbsp;this if we wanted the loop to repeat, say, 10 times, and then move on. &amp;nbsp;With the &lt;b&gt;DO ... UNTIL&lt;/b&gt; loop, on the other hand, the defined section of code would repeat indefinitely, until a specified condition arises. &amp;nbsp;This may be something to use if you want to repeat the loop until a user enters a specific value into an input box.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;The FOR ... NEXT Loop&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Let take a look at how the FOR ... NEXT loop is constructed.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;&lt;span class="Apple-style-span" style="color: #20124d;"&gt;&lt;b&gt;For&lt;/b&gt;&lt;/span&gt;&amp;nbsp;I = 1 &lt;span class="Apple-style-span" style="color: #20124d;"&gt;&lt;b&gt;To&lt;/b&gt;&lt;/span&gt; 10&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &lt;i&gt;lines of code to be repeated&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Times,'Times New Roman',serif;"&gt;&lt;span class="Apple-style-span" style="color: #20124d;"&gt;&lt;b&gt;Next&lt;/b&gt;&lt;/span&gt; I&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The FOR NEXT loop has a counter which is referred to above as &lt;b&gt;I&lt;/b&gt;. &amp;nbsp;This is basically a variable name - we could have called it a different name if we had wanted. &amp;nbsp;The first line of the statement (For I = 1 to 10) sets the counter at 1, and tells the procedure to continue repeating the lines of code until the counter reaches 10. &amp;nbsp;Each time the program flow executes the NEXT keyword at the end of the statement, the counter is increased by 1. &amp;nbsp;As it does so, it also checks whether the counter has reached 10 (or whatever level it had been set). &amp;nbsp;If it has not, the lines of code repeat another time until the Next keyword executes again, increasing the count by another 1. &amp;nbsp;Once it reaches the level set, the program flow continues past the NEXT keyword into the next section of code.&lt;br /&gt;&lt;br /&gt;So let's try an exercise to see how the FOR ... NEXT loop works in practice. &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a new unbound form in Design View.&lt;/li&gt;&lt;li&gt;Add a Command Button.&lt;/li&gt;&lt;li&gt;Add the VBA code (listed below) to the button's &lt;b&gt;OnClick Event&lt;/b&gt; (please see the first &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning VBA Tutorial&lt;/a&gt; if you need help with this, or any of the previous steps):&lt;/li&gt;&lt;li&gt;Click the SAVE icon.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Dim I As Integer&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Dim x As Integer&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Stop&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;For I = 1 To 10&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; Randomize&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; x = (9 * Rnd() + 1)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; Debug.Print "Counter = " &amp;amp; &amp;nbsp;I &amp;nbsp;&amp;amp; "; &amp;nbsp;Random Number = " &amp;amp; &amp;nbsp;x&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Next I&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Before we try out the code, we are going to open the VBA Editor's &lt;i&gt;Immediate Window&lt;/i&gt;. &amp;nbsp;To do this, &amp;nbsp;click the VBA VIEW menu, and then click IMMEDIATE WINDOW from the menu list. &amp;nbsp;When we run the code, the STOP statement will re-open the VBA editor during runtime, to allow us to &lt;i&gt;Step Into&lt;/i&gt;&amp;nbsp;each&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;line of code as it executes. &amp;nbsp;Then when the program flow reaches the &lt;b&gt;Debug.Print&lt;/b&gt; line, the &lt;b&gt;Counter &lt;/b&gt;value and the value of variable &lt;b&gt;x&lt;/b&gt; (a random number generated by the code) is displayed in the immediate window.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;When you are ready, open the Access form and click the command button we created earlier. &amp;nbsp;The VBA editor will then open. &amp;nbsp;The current line being executed is highlighted in yellow. &amp;nbsp;To advance to the next line we click &lt;i&gt;Step Into &lt;/i&gt;from the DEBUG menu (alternative use the &lt;b&gt;F8 key&lt;/b&gt; which is far more convenient). &amp;nbsp;Then watch what happens as the program flow progresses through the loop. &amp;nbsp;Also take note of the counter value which is displayed before the random number in the immediate window.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-2aOmbyEFNuA/TsaDOan5cmI/AAAAAAAAAmI/72deg2px0Ro/s1600/immediate-window.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="504" src="http://1.bp.blogspot.com/-2aOmbyEFNuA/TsaDOan5cmI/AAAAAAAAAmI/72deg2px0Ro/s640/immediate-window.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; The &lt;b&gt;VBA Editor&lt;/b&gt; with &lt;b&gt;Immediate Window&lt;/b&gt;. &amp;nbsp;The editor was opened during&lt;br /&gt;run time due to the STOP command which acted as a breakpoint. &lt;br /&gt;Another way of adding a break point is to click on a line &lt;br /&gt;and then select TOGGLE BREAKPOINT from the DEBUG menu.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;The DO ... UNTIL Loop&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let's take a quick look at the how the DO ... UNTIL loop is constructed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d;"&gt;&lt;b&gt;Do Until&lt;/b&gt;&lt;/span&gt; variableName = thisValue&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp;&lt;i&gt; lines of code to be repeated&lt;/i&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d;"&gt;&lt;b&gt;Loop&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The first line of the DO ... UNTIL loop is testing whether the specified condition is true or not. &amp;nbsp;If it is &lt;u&gt;not&lt;/u&gt; true, the lines of code within the loop are executed until the LOOP keyword is reached at the end of the statement. Then the program flow returns to the first line of the statement where the condition is tested again. &amp;nbsp;If the lines of code within the loop had changed the value of the variable being tested so the condition becomes true, the program flow exits the loop at this top line.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is an example of a DO ... UNTIL Loop that you may &amp;nbsp;like to try for yourself. &amp;nbsp;Just change the code from the first exercise so that this runs in its place.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Dim varNumber As Integer&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Dim varResponse As Integer&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Randomize&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;varNumber = 9 * Rnd() + 1&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Do Until varResponse = varNumber&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; varResponse = InputBox("Enter a Number Between 1 and 10", "Guess A Number")&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; If varResponse &amp;gt; varNumber Then&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "Your Guess is too High"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; ElseIf varResponse &amp;lt; varNumber Then&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "Your Guess is too Low"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; Else&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "Congratulations: Your Guess is Correct."&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; End If&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Loop&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; MsgBox "Game Over!!!"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: inherit; font-size: x-small;"&gt;(NB for the sake of clarity, this code does not deal with the possibility that the user may click cancel or enter an empty value in the input box. &amp;nbsp;If this happens an error results, and the procedure crashes!)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;This code is for a simple Guess the Number Game. &amp;nbsp;The user clicks the command button to begin. &amp;nbsp;The code then generate a random number and stores it in a variable called &lt;b&gt;varNumber&lt;/b&gt;. &amp;nbsp;Once the program flow gets to the loop, the variable &lt;b&gt;varResponse &lt;/b&gt;is tested to determine whether it is equal to the random number stored in &lt;b&gt;varNumber&lt;/b&gt;. &amp;nbsp;If it is not, the lines of code within the loop are executed. &amp;nbsp;The user is asked to guess the number in a pop up input box. &amp;nbsp;The code then enters an IF ... THEN ... ELSE statement where the user is informed whether his guess is &lt;i&gt;too high&lt;/i&gt;, &lt;i&gt;too low&lt;/i&gt;, or is indeed &lt;i&gt;correct&lt;/i&gt;. &amp;nbsp;When the LOOP keyword is reached, the program flow returns to the DO UNTIL keyword where the value of the guess is tested against the random number to determine whether the lines of code should be repeated, or whether the program flow can continue past the LOOP keyword.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;When you try this code, please feel free to enter a BREAKPOINT so you can follow the program flow for yourself. &amp;nbsp;You can do this by entering the STOP statement as we did in the first exercise. &amp;nbsp;Alternatively, click the line where you want to insert the breakpoint, and then click TOOGLE BREAKPOINT from the DEBUG menu. &amp;nbsp;The line is then highlighted in red., but the action is the same.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-3431816813600482144?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZCdJVRVHKowa6QOIKMUYSBLfIIc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZCdJVRVHKowa6QOIKMUYSBLfIIc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZCdJVRVHKowa6QOIKMUYSBLfIIc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZCdJVRVHKowa6QOIKMUYSBLfIIc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/j_ee36S5R6Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/3431816813600482144/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/11/introduction-to-vba-loops-learning.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/3431816813600482144" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/3431816813600482144" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/j_ee36S5R6Y/introduction-to-vba-loops-learning.html" title="Introduction to VBA Loops - Learning Access VBA Tutorial 3" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-2aOmbyEFNuA/TsaDOan5cmI/AAAAAAAAAmI/72deg2px0Ro/s72-c/immediate-window.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/11/introduction-to-vba-loops-learning.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-3264777206630153592</id><published>2011-11-11T01:37:00.001-08:00</published><updated>2011-11-18T02:24:03.249-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><category scheme="http://www.blogger.com/atom/ns#" term="If Then Else" /><category scheme="http://www.blogger.com/atom/ns#" term="tutorial" /><title type="text">Evaluating Conditions with the If...Then...Else Statement - Learning Access VBA.  Tutorial 2.</title><content type="html">This the second post in the &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt; series. &amp;nbsp;Last week I introduced you to the VBA Development Environment where we we also learnt a little about &lt;i&gt;variables. &amp;nbsp;&lt;/i&gt;We completed a simple exercise which referenced the values entered by the user into two text boxes, stored the values in variables, and added the values contained therein together. The result was then displayed in a third text box. &amp;nbsp;This week we are going to move on, and look at how VBA deals with &lt;i&gt;Conditions &lt;/i&gt;using the&lt;b&gt; If &lt;/b&gt;... &lt;b&gt;Then &lt;/b&gt;...&lt;b&gt; Else&lt;/b&gt; Statement.&lt;br /&gt;&lt;br /&gt;So what do we mean by the term&amp;nbsp;&lt;i&gt;conditions &lt;/i&gt;or the &lt;i&gt;Conditional&lt;/i&gt;? &amp;nbsp;Basically as our VBA code is executed (that is to say, as the code runs, line by line, processing each statement in turn) the program flow may well reach various points where it needs to &lt;i&gt;branch &lt;/i&gt;according to whether a given condition &lt;i&gt;has&lt;/i&gt; or &lt;i&gt;has not&lt;/i&gt; been met. &amp;nbsp; For example, we may want our code to run a short block of nested code if the value of a specified variable is greater than a given number. &amp;nbsp;If the condition is met, the program flow runs the statement contained in the nested code below; whereas, if the condition is &lt;u&gt;not &lt;/u&gt;met, the program flow may branch to the next statement &lt;i&gt;after &lt;/i&gt;the nested code - the nested code is, in effect, skipped.&lt;br /&gt;&lt;br /&gt;Lets take a look at how the &lt;b&gt;If&lt;/b&gt; ... &lt;b&gt;Then&lt;/b&gt; ... &lt;b&gt;Else&lt;/b&gt; Statement is constructed:&lt;br /&gt;&lt;br /&gt;&lt;div style="color: blue; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;b&gt;IF&lt;/b&gt; &lt;condition is="" met=""&gt;&lt;i&gt;&lt;span style="color: black;"&gt;conditon is met&lt;/span&gt;&lt;/i&gt; &lt;b&gt;THEN&lt;/b&gt;&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;condition is="" met=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: black;"&gt; &lt;i&gt;nested code1&lt;/i&gt;&lt;/span&gt;&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;b&gt;&lt;condition is="" met=""&gt;ELSE&lt;/condition&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="color: blue; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;condition is="" met=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: black;"&gt;&lt;i&gt;nested code2&lt;/i&gt; &lt;/span&gt;&lt;/condition&gt;&lt;/div&gt;&lt;condition is="" met=""&gt;&lt;b&gt;&lt;span style="color: blue; font-family: Times,'Times New Roman',serif;"&gt;END IF&lt;/span&gt;&lt;/b&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;b&gt;&lt;span style="color: blue; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp;&lt;span style="background-color: black;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="color: black;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;The &lt;b&gt;IF&lt;/b&gt; keyword tests whether the condition is true or not.&amp;nbsp; If it is true, the &lt;b&gt;THEN &lt;/b&gt;keyword directs the program flow to the code contained in &lt;i&gt;nested code1&lt;/i&gt;.&amp;nbsp; &lt;b&gt;ELSE&lt;/b&gt; is optional. If we use it, &lt;b&gt;ELSE &lt;/b&gt;directs the program flow to that contained&lt;i&gt; &lt;/i&gt;in&lt;i&gt; nested code2&lt;/i&gt; if the condition after the &lt;b&gt;IF&lt;/b&gt; keyword had not been met.&amp;nbsp; Had we not used the &lt;b&gt;ELSE &lt;/b&gt;keyword (with &lt;i&gt;nested code2&lt;/i&gt;), the program flow would have skipped &lt;i&gt;nested code1&lt;/i&gt; and gone straight to the END IF keyword. &lt;/condition&gt;&lt;br /&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;So, for example, our code may read:&amp;nbsp;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;br /&gt;&lt;/condition&gt;&lt;br /&gt;&lt;div style="color: #20124d; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;condition is="" met=""&gt;&lt;b&gt;IF&lt;/b&gt; varFirstNumber &amp;gt; varSecondNumber &lt;b&gt;THEN&lt;/b&gt;&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;condition is="" met=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox("First Number is Greater than Second Number")&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;b&gt;&lt;condition is="" met=""&gt;ELSE&lt;/condition&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;condition is="" met=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox("First Number is not Greater than Second Number")&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;"&gt;&lt;b&gt;&lt;condition is="" met=""&gt;END IF&lt;/condition&gt;&lt;/b&gt;&lt;/div&gt;&lt;condition is="" met=""&gt;&lt;br /&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;This tests whether the number contained in variable &lt;b&gt;varFirstNumber &lt;/b&gt;is greater than that contained in &lt;b&gt;varSecondNumber&lt;/b&gt;.&amp;nbsp; If the condition &lt;u&gt;was &lt;/u&gt;met, the nested code below the IF keyword would run.&amp;nbsp; This displays a message box saying "First Number is Greater than Second Number".&amp;nbsp; If the condition was &lt;u&gt;not&lt;/u&gt; met, the nested code below the ELSE statement would have run instead.&amp;nbsp; This would have displayed a message box saying "First Number is Not Greater than Second Number".&amp;nbsp; The END IF keyword closes the &lt;b&gt;If&lt;/b&gt; ... &lt;b&gt;Then&lt;/b&gt; ... &lt;b&gt;Else&lt;/b&gt; Statement.&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;There is one other optional keyword which is well worth mentioning - that is &lt;b&gt;ELSEIF. &amp;nbsp;&lt;/b&gt;When we only use IF/THEN and ELSE, we have just two possible branches in the program code. &amp;nbsp;However, suppose there are three or more possible conditions? &amp;nbsp;For example, suppose we want to test whether the variable &lt;b&gt;varFirstNumber &lt;/b&gt;is (a)&amp;nbsp;&lt;i&gt;greater than&lt;/i&gt;, (b)&amp;nbsp;&lt;i&gt;less than&lt;/i&gt;, or (c)&amp;nbsp;&lt;i&gt;equal to&lt;/i&gt;, the second variable? &amp;nbsp;ELSEIF is a good way to do this. &amp;nbsp;Lets see how we would code this scenario:&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;/condition&gt;&lt;br /&gt;&lt;div style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;condition is="" met=""&gt;&lt;b&gt;IF&lt;/b&gt;&amp;nbsp;varFirstNumber &amp;gt; varSecondNumber&amp;nbsp;&lt;b&gt;THEN&lt;/b&gt;&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;condition is="" met=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msgbox("First Number is Greater than Second Number")&lt;/condition&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;condition is="" met=""&gt;ELSEIF varFirstNumber &amp;lt; varSecondNumber THEN&lt;/condition&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;condition is="" met=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; msgbox("First Number is Less than Second Number")&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;b&gt;&lt;condition is="" met=""&gt;ELSE&lt;/condition&gt;&lt;/b&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;b&gt;&lt;condition is="" met=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/condition&gt;&lt;/b&gt;&lt;/condition&gt;msgbox("First Number is Equal to Second Number")&lt;/div&gt;&lt;div style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;condition is="" met=""&gt;END IF&lt;/condition&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;As we can see, the &lt;b&gt;ELSEIF &lt;/b&gt;keyword has allowed us to enter a second &lt;i&gt;specified &lt;/i&gt;condition to test, in the event of the initial condition proving false. &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;As such, when the program flow reaches the &lt;b&gt;If &lt;/b&gt;... &lt;b&gt;Then &lt;/b&gt;... &lt;b&gt;Else &lt;/b&gt;Statement, the initial condition is tested by the first&amp;nbsp;&lt;b&gt;IF&lt;/b&gt; keyword; if this is true, the nested code in the line directly below is executed, and then the program flow branches to the END IF keyword at the bottom of the statement. &amp;nbsp;However, if the first condition had been false, the first block of nested code is skipped, and the program flow goes to the ELSEIF keyword and the second conditional expression is then tested; if this proves true, the second block of nested code is executed. &amp;nbsp;However, if the 2nd expression had also proven false, then the 2nd nested code would also be skipped, and the program flow would move down to the ELSE keyword. &amp;nbsp;There is no condition to test here, so the 3rd block of nested code is executed unconditionally.&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;(NB In the above scenario there were three possible outcomes. &amp;nbsp;However, it is also worth mentioning that by adding additional ELSEIF keywords into the statement, the number of possible conditions to test is potentially endless.)&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit; font-size: large;"&gt;&lt;b&gt;Compare Numbers Exercise&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;condition is="" met=""&gt;&lt;span style="color: black;"&gt;&lt;span style="font-family: inherit;"&gt;Let's end this tutorial by applying what we have learnt above to the following exercise. &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/condition&gt;&lt;br /&gt;&lt;br /&gt;We are going to create a form with two text boxes named &lt;b&gt;txtFirstNumber &lt;/b&gt;and &lt;b&gt;txtSecondNumber&lt;/b&gt;. &amp;nbsp;Then we will add a command button, &lt;b&gt;ctlCompare&lt;/b&gt;, with some code attached to it's ON CLICK event. &amp;nbsp;We learnt how to do this in last weeks &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt; tutorial. However this time our code will compare the numbers entered into the two text boxes by the user at runtime, and display a message box informing the him/her whether the First Number is (a) Greater than, (b) Less than, or (c) Equal to, the Second.&lt;br /&gt;&lt;br /&gt;This is a screenshot of our form in action:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Q1FYeQz-Khs/Tr0t85QHhgI/AAAAAAAAAmA/EKAN4ZAjsoA/s1600/number-comparison.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-Q1FYeQz-Khs/Tr0t85QHhgI/AAAAAAAAAmA/EKAN4ZAjsoA/s1600/number-comparison.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Here the user has entered &lt;b&gt;10 &lt;/b&gt;in &lt;b&gt;txtFirstNumber &lt;/b&gt;and &lt;b&gt;20 &lt;/b&gt;in &lt;b&gt;txtSecondNumber&lt;/b&gt;. &lt;br /&gt;After the user clicks the &lt;b&gt;Compare &lt;/b&gt;command button, Access runs the VBA code&lt;br /&gt;that compares the two numbers and displays the appropriate message.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Instructions&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I won't go into great detail regarding instructions - we should have leant all the required skills from last weeks post on &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt;. &amp;nbsp;There is also more information about creating an unbound Access Form in the post about &lt;a href="http://ms-access-tips.blogspot.com/2009/11/creating-access-2007-form-from-scratch.html" target="_blank"&gt;Creating an Access Form from Scratch&lt;/a&gt;. &amp;nbsp;I advise you to check out these posts if you need a reminder:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a new unbound &lt;a href="http://ms-access-tips.blogspot.com/2009/11/creating-access-2007-form-from-scratch.html" target="_blank"&gt;Access Form&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Add two text boxes called &lt;b&gt;txtFirstNumber &lt;/b&gt;and &lt;b&gt;txtSecondNumber&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Add a Command Button called &lt;b&gt;ctlCompare&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Select the Command Button and open the PROPERTIES SHEET.&lt;/li&gt;&lt;li&gt;Click the Events tab of the PROPERTY SHEET.&lt;/li&gt;&lt;li&gt;Click the three dots&amp;nbsp;symbol&amp;nbsp;&amp;nbsp;(&lt;b&gt;...&lt;/b&gt;)&amp;nbsp;on the right of the ON CLICK property cell.&lt;/li&gt;&lt;li&gt;Open the VBA Editor by clicking CODE BUILDER from the CHOOSE BUILDER menu.&lt;/li&gt;&lt;li&gt;Copy and paste the code listed below (excluding the first and last line which should have been added to the VBA editor automatically).&lt;/li&gt;&lt;li&gt;Click the save Icon and close the VBA Editor.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;Private Sub ctlQuestion_Click()&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; Dim varFirstNumber As Integer&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; Dim varSecondNumber As Integer&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; varFirstNumber = Me!txtFirstNumber&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; varSecondNumber = Me!txtSecondNumber&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; If varFirstNumber &amp;gt; varSecondNumber Then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "First Number is Greater than Second Number"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; ElseIf varFirstNumber &amp;lt; varSecondNumber Then&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "First Number is Less than Second Number"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; Else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "First Number is Equal to Second Number"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp; End If&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times,'Times New Roman',serif;"&gt;End Sub&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;To test out the code, open your form in FORM VIEW, enter a number in each of the text boxes, and click the COMPARE button. &amp;nbsp;NB for clarity there is no code to validate whether two numbers have been entered in the text boxes. &amp;nbsp;An error message will result if one or both of the text boxes is empty when the compare button is clicked.&lt;br /&gt;&lt;br /&gt;The code begins by declaring two variables, and then assigns values to each one by referencing the two respective text boxes (see &lt;a href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html" target="_blank"&gt;Learning Access VBA&lt;/a&gt; for more information about this process). &amp;nbsp;The &lt;b&gt;If &lt;/b&gt;... &lt;b&gt;Then &lt;/b&gt;... &lt;b&gt;Else &lt;/b&gt;statement then tests whether the first number is &lt;i&gt;greater than&lt;/i&gt;, &lt;i&gt;less than &lt;/i&gt;or &lt;i&gt;equal to,&amp;nbsp;&lt;/i&gt;the second number. &amp;nbsp;A message box opens containing the result.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-3264777206630153592?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PABOJwzSNnQtpdzn-j8WItZquNY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PABOJwzSNnQtpdzn-j8WItZquNY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PABOJwzSNnQtpdzn-j8WItZquNY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PABOJwzSNnQtpdzn-j8WItZquNY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/dzFiNBWTYaE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/3264777206630153592/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/3264777206630153592" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/3264777206630153592" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/dzFiNBWTYaE/evaluating-conditions-with-ifthenelse.html" title="Evaluating Conditions with the If...Then...Else Statement - Learning Access VBA.  Tutorial 2." /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-Q1FYeQz-Khs/Tr0t85QHhgI/AAAAAAAAAmA/EKAN4ZAjsoA/s72-c/number-comparison.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/11/evaluating-conditions-with-ifthenelse.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-7099160789812716795</id><published>2011-11-04T12:33:00.000-07:00</published><updated>2011-11-05T03:20:47.638-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VBA" /><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="tutorial" /><title type="text">Learning Access VBA - A Beginners Guide</title><content type="html">&lt;div style="text-align: justify;"&gt;This post is all about getting started with the Access VBA programming language - &amp;nbsp;a first tutorial starting right at the beginning. &amp;nbsp;As you may already know, the Access Database comes with its own programming language called &lt;i&gt;Visual Basic for Applications&lt;/i&gt;, or VBA. &amp;nbsp;It offers a powerful way to &lt;i&gt;automate&lt;/i&gt; and generally &lt;i&gt;control&lt;/i&gt; how an access database application operates. &amp;nbsp;However, whilst relatively easy to use, getting started can seem a little daunting to the newcomer. &amp;nbsp;As such, this tutorial is intended to help the beginner feel at home in the programming environment.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-I5FPIu3ospA/TrLwDudpf7I/AAAAAAAAAlo/lflhJsG7Z-A/s1600/visual-basic-icon.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-I5FPIu3ospA/TrLwDudpf7I/AAAAAAAAAlo/lflhJsG7Z-A/s1600/visual-basic-icon.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1: &lt;/b&gt;The&lt;b&gt; Visual Basic &lt;/b&gt;Icon&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;The first problem faced by the beginner is finding out how to get into this thing called VBA. &amp;nbsp;This is because,&amp;nbsp;technically,&amp;nbsp;VBA is a separate software package which works alongside Access. &amp;nbsp;That said, we can only open the VBA Editor (see figure 2 below) from within the Access database itself. &amp;nbsp;The most direct way of doing this is by clicking the VISUAL BASIC icon (located in the MACRO's group of the DATABASE TOOLS ribbon - see figure one above). &amp;nbsp;You might like to download the &lt;i&gt;&lt;a href="http://www.dealing-with-data.net/exercises/LearningVBA.accdb"&gt;Learning Visual Basic Sample Database&lt;/a&gt;&lt;/i&gt;, and give this a try.&lt;/div&gt;&lt;br /&gt;&lt;a href="http://www.dealing-with-data.net/exercises/LearningVBA.accdb"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Learning Visual Basic Sample Database&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-HXVDBzDGAV8/TrO4TKW3WhI/AAAAAAAAAlw/X-u2kNSFT0A/s1600/vba-editor.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/-HXVDBzDGAV8/TrO4TKW3WhI/AAAAAAAAAlw/X-u2kNSFT0A/s400/vba-editor.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; The &lt;b&gt;VBA Editor&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;The sample database consists of an unbound form which acts as a simple calculator. &amp;nbsp;There are three Text Boxes and two Command Buttons. &amp;nbsp;The user enters two numbers in the top two text boxes and clicks the &lt;i&gt;&amp;nbsp;equals &lt;/i&gt;(&lt;b&gt;=&lt;/b&gt;)&lt;i&gt; &lt;/i&gt;buton. &amp;nbsp;This runs a block of VBA code (called a &lt;i&gt;sub procedure&lt;/i&gt;) which reads the numbers from the two text boxes, adds them together, and displays the result in the third text box. &amp;nbsp;The user can then click the Clear button (&lt;b&gt;C&lt;/b&gt;). This runs a different block of code to clear all the existing numbers from the text boxes so new numbers can be entered and calculated.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-0hrByECHYJ4/TrO9xn1JMBI/AAAAAAAAAl4/_KN5TbL1OaE/s1600/unbound-form.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="151" src="http://2.bp.blogspot.com/-0hrByECHYJ4/TrO9xn1JMBI/AAAAAAAAAl4/_KN5TbL1OaE/s320/unbound-form.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Figure 4: The &lt;i&gt;Simple Calculator&lt;/i&gt; form &lt;br /&gt;described in the paragraph above.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;So lets take a look at how this is created. &amp;nbsp;We shall do so in two stages: first we shall create the form, then open the VBA Editor and enter the two blocks of code.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Creating the Form&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;Click the FORM DESIGN icon (located in the FORMS group of the CREATE ribbon).&lt;/li&gt;&lt;li&gt;Drag and drop three text boxes on the the form (if you need help, you might like to check out my tutorial on how to &lt;a href="http://ms-access-tips.blogspot.com/2009/11/creating-access-2007-form-from-scratch.html" target="_blank"&gt;Create an Access Form from Scratch&lt;/a&gt;).&lt;/li&gt;&lt;li&gt;Next drag and drop the two Command Buttons onto the design grid. &amp;nbsp;Make sure the USE COMMAND WIZARDS icon is not highlighted when you do this - otherwise just click the CANCEL button if the Command Button Wizard&amp;nbsp;opens.&lt;/li&gt;&lt;li&gt;Click on the label for the top text box and change the text to read "&lt;i&gt;First Number&lt;/i&gt;".&lt;/li&gt;&lt;li&gt;Repeat step 4 for the second and third labels, entering "&lt;i&gt;Second Number&lt;/i&gt;" and "&lt;i&gt;Result&lt;/i&gt;" respectively.&lt;/li&gt;&lt;li&gt;Then click on the top text button and change the text to "&lt;b&gt;C&lt;/b&gt;". This will be the Clear Button.&lt;/li&gt;&lt;li&gt;Do the same for the lower text button, changing the text to "=". &amp;nbsp;This will be the Equals Button.&lt;/li&gt;&lt;li&gt;Next click the PROPERTY SHEET icon (located in the TOOLS group of the DESIGN ribbon).&lt;/li&gt;&lt;li&gt;Set the NAME property (located at the top of the OTHER TAB of the PROPERTY SHEET)&amp;nbsp;for the first text box to&amp;nbsp;&lt;b&gt;txtFirstNumber.&amp;nbsp;&lt;/b&gt;&amp;nbsp;&lt;/li&gt;&lt;li&gt;Repeat step 9, calling the lower two text boxes&amp;nbsp;&lt;b&gt;txtSecondNumber &lt;/b&gt;and &lt;b&gt;txtResult, &lt;/b&gt;and calling the Command Buttons &lt;b&gt;ctlClear &lt;/b&gt;and &lt;b&gt;ctlAdd&lt;/b&gt;.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/li&gt;&lt;/ol&gt;NB&lt;b&gt; &lt;/b&gt;It is important to enter the NAME properties correctly. &amp;nbsp;Although we could have called them anything we wanted, our VBA code refers to these form controls via the NAME property. &amp;nbsp;As such we need to ensure that the names used on our form are going to match those to be used in the code. &amp;nbsp;This is an important principle to grasp as we use VBA alongside Access.&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Entering the VBA Code&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Next click on the &lt;b&gt;ctlAdd&lt;/b&gt;&lt;i&gt; &lt;/i&gt;(=)&amp;nbsp;Command Button whilst our form is still open in DESIGN VIEW.&lt;/li&gt;&lt;li&gt;Open the PROPERTIES SHEET (if it is not already open) and&amp;nbsp;click the EVENTS tab &lt;b&gt;ctlAdd&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Click the cell for the ON CLICK property. &amp;nbsp;Then click the three dots button (&lt;b&gt;...&lt;/b&gt;) at the right of the cell. &amp;nbsp;This opens the CHOOSE BUILDER dialog box.&lt;/li&gt;&lt;li&gt;Select CODE BUILDER from the menu items, and click OK. &amp;nbsp;This opens the VBA Editor in the exact location where we are going to enter the code which is triggered when the user clicks the button at runtime (the ON CLICK Event). &amp;nbsp;It even writes the first and last line of code which makes this a self contained block of code (a &lt;b&gt;Sub Procedure&lt;/b&gt;).&lt;/li&gt;&lt;li&gt;Enter the code (listed below) between the &lt;i&gt;Private Sub&lt;/i&gt; and&lt;i&gt; End Sub&lt;/i&gt; lines:&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Private Sub ctlAdd_Click()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Dim varFirstNumber As Double&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Dim varSecondNumber As Double&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Dim varResult As Double&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; If IsNull(Me!txtFirstNumber) = True Or IsNull(Me!txtSecondNumber) = True Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MsgBox "Please Enter Numbers in Both Textboxes", vbInformation, "Missing Number(s)"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Exit Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; End If&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; varFirstNumber = Me!txtFirstNumber&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; varSecondNumber = Me!txtSecondNumber&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; varResult = varFirstNumber + varSecondNumber&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Me!txtResult = varResult&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;Now repeat all of the last stage from 1 to 5, but this time for the &lt;b&gt;ctlClear &lt;/b&gt;Command Button. &amp;nbsp;Enter the following code in the same manner as above:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Private Sub ctlClear_Click()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Me!txtFirstNumber = Null&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Me!txtSecondNumber = Null&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; Me!txtResult = Null&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif; font-size: x-small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;When this is complete, you may save your code by clicking the SAVE icon, and close the VBA Editor. &amp;nbsp;To test the code simply open the form in FORM VIEW, enter the numbers to calculate, and click the &lt;b&gt;ctlAdd &lt;/b&gt;button. &amp;nbsp;The correct result should display in the third text box once this is done.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;How the Code Works&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;Please don't worry about being able to create this code yourself at this stage in the learning process. &amp;nbsp;The main purpose of this tutorial was to get you familiar with the programming environment, rather than how to construct the code. &amp;nbsp;I intend to do this in future tutorials. &amp;nbsp;However, we &lt;i&gt;will &lt;/i&gt;go through each line of the first sub procedure just to give you a general idea of how the programming code works.&lt;br /&gt;&lt;br /&gt;The code is triggered by the Command Button's ON CLICK event. &amp;nbsp;The user clicks the command button, Access 'raises' the ON CLICK event, and the block of code runs one line at a time.&lt;br /&gt;&lt;br /&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif; text-align: justify;"&gt;Private Sub ctlAdd_Click()&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;The first line, the SUB Statement, was created automatically by Access when we opened the VBA Editor from the property sheet. &amp;nbsp;It's purpose is to mark the beginning of this block of code or Sub Procedure. &amp;nbsp;The PRIVATE part of the statement relates to the concept of &lt;i&gt;Scope&lt;/i&gt;. &amp;nbsp;We won't worry too much about what this means at this stage, except to say it is concerned with where&amp;nbsp;the sub can be 'called' from. &amp;nbsp;&lt;i&gt;Private&lt;/i&gt; means just that - it is private to this particular form module, and can &lt;u&gt;not&lt;/u&gt; be called from a module elsewhere in the application. &amp;nbsp;The part which says &lt;b&gt;ctlAdd_Click&lt;/b&gt; is the &lt;i&gt;name &lt;/i&gt;of the sub procedure.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Dim varFirstNumber As Double&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Dim varSecondNumber As Double&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;Dim varResult As Double&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;The next three lines of code &lt;i&gt;declare&amp;nbsp;&lt;/i&gt;three separate &lt;i&gt;variables&lt;/i&gt;. &amp;nbsp;The purpose of variables are to enable values to be temporarily stored, processed, and retrieved. &amp;nbsp;More about this soon. At this stage we are just going to note that we have used the DIM Statement to define three variables called &lt;b&gt;varFirstNumber&lt;/b&gt;, &lt;b&gt;varSecondNumber &lt;/b&gt;and &lt;b&gt;varResult&lt;/b&gt;. &amp;nbsp;We have also included AS DOUBLE to tell Access that the variables are going to store values of the DOUBLE data type (so we can calculate decimal numbers).&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp;If IsNull(Me!txtFirstNumber) = True Or IsNull(Me!txtSecondNumber) = True Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;MsgBox "Please Enter Numbers in Both Textboxes", vbInformation, "Missing Number(s)"&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Exit Sub&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&amp;nbsp;End If&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;This next section of code is an IF Statement, and &amp;nbsp;forms a self contained block of code within the sub procedure itself. &amp;nbsp;It was something I added to ensure the user enters a number in each of the two text boxes. If it detects that there is a Null value it runs the nested code to display a message box, and then exits the sub.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;varFirstNumber = Me!txtFirstNumber&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;varSecondNumber = Me!txtSecondNumber&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;In this section of code, we are assigning each of the two variables with a value. &amp;nbsp;The equals sign assigns the variable name on the left of the sign with the value on the right. &amp;nbsp;In this case the top line is setting the value of the &lt;b&gt;varFirstNumber &lt;/b&gt;variable to the value entered by the user in the &lt;b&gt;txtFirstNumber &lt;/b&gt;text box control. &amp;nbsp;Note that the text box is referenced by means of the code:&amp;nbsp;&lt;b&gt;Me!txtFirstNumber&lt;/b&gt;. &amp;nbsp;The &lt;b&gt;Me!&lt;/b&gt; part of this is telling access that the text box belongs to the form to which this VBA module is attached ie &lt;b&gt;frmCalculator&lt;/b&gt;; and &lt;b&gt;txtFirstNumber &lt;/b&gt;is the name we gave to the top text box on the form we created earlier.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;varResult = varFirstNumber + varSecondNumber&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;This line is assigning the variable &lt;b&gt;varResult &lt;/b&gt;with a value. &amp;nbsp;In this case the value being assigned is the sum of the values stored in&amp;nbsp;&lt;b&gt;varFirstNumber &lt;/b&gt;and&amp;nbsp;&lt;b&gt;varSecondNumber&lt;/b&gt;. &amp;nbsp;Put another way, this line is performing the addition calculation and storing the result in the variable &lt;b&gt;varResult&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Me!txtResult = varResult&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;This line is using the value stored in the &lt;b&gt;varResult &lt;/b&gt;variable to set the value to be displayed in the lower text box of the form, &lt;b&gt;txtResult&lt;/b&gt;. &amp;nbsp;It references the text box in the manner already described above. &amp;nbsp;This time, however, the text box reference is on the right hand side of the equals sign, and the variable on the left. &amp;nbsp;This is because the value of the variable is being retrieved, and the value of the text box is being set.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;b style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;End Sub&lt;/b&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;This line was generated automatically just like the first in this block of code. &amp;nbsp;However, this time it is marking the end of the sub procedure.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit; font-size: large;"&gt;&lt;b&gt;Try this Yourself&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;If you are feeling adventurous, you might like to try creating more Command Buttons for the Calculator form. &amp;nbsp;Try creating a button to multiply or subtract the values stored in the top two text boxes. &amp;nbsp;You can follow the same procedure as before. &amp;nbsp;However, when you copy and paste the code, change the addition operator (+) in the appropriate line for multiply (*) and subtract (-) respectively.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-7099160789812716795?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ps20dWbppsJGX7NlNgg_QxjnxrE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ps20dWbppsJGX7NlNgg_QxjnxrE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ps20dWbppsJGX7NlNgg_QxjnxrE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ps20dWbppsJGX7NlNgg_QxjnxrE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/vyWh_6REkkA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/7099160789812716795/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/7099160789812716795" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/7099160789812716795" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/vyWh_6REkkA/learning-access-vba-beginners-guide.html" title="Learning Access VBA - A Beginners Guide" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-I5FPIu3ospA/TrLwDudpf7I/AAAAAAAAAlo/lflhJsG7Z-A/s72-c/visual-basic-icon.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/11/learning-access-vba-beginners-guide.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-6578847561128748955</id><published>2011-10-28T08:43:00.000-07:00</published><updated>2011-10-28T09:05:41.148-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="combo box" /><category scheme="http://www.blogger.com/atom/ns#" term="Conditional Formatting" /><category scheme="http://www.blogger.com/atom/ns#" term="text box" /><category scheme="http://www.blogger.com/atom/ns#" term="reports" /><title type="text">Using Conditional Formatting on an Exam Results Report</title><content type="html">&lt;br /&gt;&lt;i&gt;Conditional Formatting&lt;/i&gt; may be applied to&lt;i&gt;&amp;nbsp;Text Bo&lt;/i&gt;x and C&lt;i&gt;ombo Box&lt;/i&gt;&amp;nbsp;controls on Access&amp;nbsp;&lt;a href="http://www.dealing-with-data.net/create-access-form.html"&gt;Forms&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://www.dealing-with-data.net/create-access-report.html"&gt;Reports&lt;/a&gt;.&amp;nbsp;&amp;nbsp; It allows us to format the data contained in a particular Text or Combo Box, according to value of that same data. &amp;nbsp;For example we can create &lt;i&gt;Conditional Formatting&lt;/i&gt; for a text box to display a currency value, which when less than 0, will display that value in a red font, instead of the normal black.&lt;br /&gt;&lt;br /&gt;Moreover, as well as formatting the Text or Combo Box according to the value contained in that&amp;nbsp;&lt;i&gt;same control&lt;/i&gt;, we can also format the Text or Combo box according to the value contained in&amp;nbsp;&lt;i&gt;another&amp;nbsp;&lt;/i&gt;field of the same record. &amp;nbsp;So, for example, we can display a Text Box containing a&amp;nbsp;&lt;b&gt;CompanyName&lt;/b&gt;&amp;nbsp;in bold font if the value of its&amp;nbsp;&lt;b&gt;AnnualTurnover&lt;/b&gt;&amp;nbsp;field is greater than or equal to, say, &amp;nbsp;£100,000. &amp;nbsp;The great thing is, the data contained in the&amp;nbsp;&lt;b&gt;AnnualTurnover&amp;nbsp;&lt;/b&gt;field does not&amp;nbsp;&lt;i&gt;necessarily&amp;nbsp;&lt;/i&gt;have to be displayed on the form or report, as long as it is stored in the form or reports underlying&amp;nbsp;&lt;i&gt;Record Source&lt;/i&gt;. &amp;nbsp;In order to do this, we would enter an&amp;nbsp;&lt;i&gt;expression&amp;nbsp;&lt;/i&gt;for the condition.&lt;br /&gt;&lt;br /&gt;So let's take a look at how we go about applying &lt;i&gt;Conditional Formatting&lt;/i&gt; using the example of a&amp;nbsp;&lt;i&gt;Student Exam Results Report&lt;/i&gt;. &amp;nbsp;The report applies conditional formatting based on the students exam result. &amp;nbsp;Students records with a result above 74 % are displayed in green, and those below 40 %, in red. The formatting for those in between is set to blue by default. To enhance clarity, I have also applied a sort on the &lt;b&gt;Results &lt;/b&gt;field, thereby ordering the records from highest result to lowest. If you wish, you can download the complete solution by clicking the link below:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;a href="http://www.dealing-with-data.net/exercises/ConditionalFormatting.accdb"&gt;Student Exam Results&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Our example database contains a table,&amp;nbsp;&lt;b&gt;tblExamResults&lt;/b&gt;, and report,&amp;nbsp;&lt;b&gt;rptExamResults&lt;/b&gt;- the table&amp;nbsp;being the&amp;nbsp;&lt;i&gt;Record Source&lt;/i&gt;&amp;nbsp;for the report.&amp;nbsp; Our table contains a list of student names and their corresponding exam results:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--3aUqWb-s9k/Tqp0zt0SbsI/AAAAAAAAAks/aZvVc9IfBJQ/s1600/table.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/--3aUqWb-s9k/Tqp0zt0SbsI/AAAAAAAAAks/aZvVc9IfBJQ/s320/table.JPG" width="285" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="font-size: 13px; text-align: center;"&gt;&lt;b&gt;Figure 1: tblExamResults -&amp;nbsp;&lt;/b&gt;The Record Source for our Report.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;The&amp;nbsp;&lt;b&gt;rptExamResults&amp;nbsp;&lt;/b&gt;report is&amp;nbsp;based on this table. &amp;nbsp;I created it by clicking the REPORT icon (located in the REPORTS group of the CREATE ribbon) whilst&amp;nbsp;&lt;b&gt;tblExamResults&amp;nbsp;&lt;/b&gt;was highlighted in the NAVIGATION PANE. &amp;nbsp;I then just needed to tidy it up in DESIGN VIEW, and add the&amp;nbsp;&lt;i&gt;Conditional Formatting&amp;nbsp;&lt;/i&gt;(on each text box on the report)&amp;nbsp;in addition to a SORT on the&amp;nbsp;&lt;b&gt;Results&lt;/b&gt;&amp;nbsp;field. &amp;nbsp;This is the finished result:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-tiuY1cIHl6k/Tqp3VGXmUCI/AAAAAAAAAk8/LtYJzdDvres/s1600/report.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://4.bp.blogspot.com/-tiuY1cIHl6k/Tqp3VGXmUCI/AAAAAAAAAk8/LtYJzdDvres/s640/report.JPG" width="544" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Applying Conditional Formatting.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To begin with, lets look at how we apply Conditional Formatting to the &lt;b&gt;Result&lt;/b&gt; field of&amp;nbsp;&lt;b&gt;rptExamResults&lt;/b&gt;. &lt;br /&gt;&lt;ol&gt;&lt;li&gt;Open the report in DESIGN VIEW&lt;/li&gt;&lt;li&gt;Right click the&amp;nbsp;&lt;b&gt;Result &lt;/b&gt;Text Box.&lt;/li&gt;&lt;li&gt;Click CONDITIONAL FORMATTING from the drop down menu.&lt;/li&gt;&lt;li&gt;When the CONDITIONAL FORMATTING dialog form opens, set the conditions as described in the next stage of the process below.&lt;/li&gt;&lt;/ol&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-q2Cs95NnltE/Tqp-V8fAJ7I/AAAAAAAAAlE/kKX7YZbF6wQ/s1600/conditional-formatting.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-q2Cs95NnltE/Tqp-V8fAJ7I/AAAAAAAAAlE/kKX7YZbF6wQ/s1600/conditional-formatting.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="font-size: 13px; text-align: center;"&gt;&lt;b&gt;Figure 2:&amp;nbsp;&lt;/b&gt;The&amp;nbsp;&lt;b&gt;Conditional Formatting&amp;nbsp;&lt;/b&gt;dialog form. &amp;nbsp;It is possible to have a maximum of&lt;br /&gt;three different conditions plus the default formatting. &amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Setting Conditions based on FIELD VALUE IS&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The next stage is to set the actual&amp;nbsp;&lt;i&gt;conditions&amp;nbsp;&lt;/i&gt;for the&amp;nbsp;&lt;b&gt;Result&amp;nbsp;&lt;/b&gt;field of the report (see&amp;nbsp;&lt;b&gt;Figure 2&lt;/b&gt;&amp;nbsp;above). NB: when FIELD VALUE IS is selected, it refers to the value contained in the text box being formatted:&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;First set the DEFAULT FORMATTING section so it displays a BLUE FONT. &amp;nbsp;Do this by selecting BLUE from the FONT/FORE COLOR icon&lt;/li&gt;&lt;li&gt;Next set CONDITION 1 so that a BOLD GREEN FONT displays when the &amp;nbsp;FIELD VALUE IS GREATER THAN 74. &amp;nbsp;If necessary click the drop down list to select FIELD VALUE IS, and then do the same in the next combo box along to select GREATER THAN. &amp;nbsp;Then just enter the value&amp;nbsp;&lt;b&gt;74&lt;/b&gt;&amp;nbsp;in the third box along, and select the BOLD and RED icons. &amp;nbsp;You should see a preview in the box below when done.&lt;/li&gt;&lt;li&gt;Click the ADD &amp;gt;&amp;gt; button to show CONDITION 2.&lt;/li&gt;&lt;li&gt;Repeat the process of stage 2 so that a BOLD RED FONT displays when FIELD VALUE IS LESS THAN 40.&lt;/li&gt;&lt;li&gt;Click OK to close.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Setting Conditions based on EXPRESSION IS&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;The next stage is to set the conditions for the&amp;nbsp;&lt;b&gt;StudentId&amp;nbsp;&lt;/b&gt;field. &amp;nbsp;Since we are&amp;nbsp;&lt;u&gt;not&lt;/u&gt;&amp;nbsp;basing the condition on the value contained in the&amp;nbsp;&lt;b&gt;StudentId&amp;nbsp;&lt;/b&gt;field itself, we need to construct an&amp;nbsp;&lt;i&gt;expression&amp;nbsp;&lt;/i&gt;which&amp;nbsp;&lt;i&gt;refers&amp;nbsp;&lt;/i&gt;to the value contained in the&amp;nbsp;&lt;b&gt;Results&amp;nbsp;&lt;/b&gt;field. As such, we shall be selecting&amp;nbsp;&lt;b&gt;EXPRESSION IS&lt;/b&gt;&amp;nbsp;from the appropriate drop down lists, rather than FIELD VALUE IS.&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Again, set the DEFAULT FORMATTING section so it displays a BLUE FONT. &amp;nbsp;Do this by selecting BLUE from the FONT/FORE COLOR icon&lt;/li&gt;&lt;li&gt;Next set CONDITION 1 so that a BOLD GREEN FONT displays when the EXPRESSION IS&amp;nbsp;&lt;b&gt;[Results]&amp;gt;=75&lt;/b&gt;. &amp;nbsp;Do this by clicking the drop down list to select EXPRESSION IS, and then enter the expression in the elongated box (see&amp;nbsp;&lt;b&gt;Figure 3&lt;/b&gt;&amp;nbsp;below). &amp;nbsp;Then&amp;nbsp;select the BOLD and RED icons as before. &amp;nbsp;&lt;/li&gt;&lt;li&gt;Click the ADD &amp;gt;&amp;gt; button to show CONDITION 2.&lt;/li&gt;&lt;li&gt;Repeat the process of stage 2 so that a BOLD RED FONT displays when&amp;nbsp;EXPRESSION IS&amp;nbsp;&lt;b&gt;[Results]&amp;lt;40&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Click OK to close.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-bRP8cRVbZPU/TqqKj1ChOQI/AAAAAAAAAlM/-g6PKD-K_bs/s1600/expression-is.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-bRP8cRVbZPU/TqqKj1ChOQI/AAAAAAAAAlM/-g6PKD-K_bs/s1600/expression-is.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="font-size: 13px; text-align: center;"&gt;&lt;b&gt;Figure 3:&amp;nbsp;&lt;/b&gt;Condition based on EXPRESSION IS. &amp;nbsp;Note the elongated box where the expression is entered. &amp;nbsp;This appears when EXPRESSION IS is selected from the drop down list.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Finish the report by repeating this last stage for the &lt;b&gt;FirstName &lt;/b&gt;and &lt;b&gt;Surname &lt;/b&gt;fields using the EXPRESSION IS selection when creating the conditions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-6578847561128748955?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hog2in3JAk1jh9nS4IF9k-Z3S1M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hog2in3JAk1jh9nS4IF9k-Z3S1M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hog2in3JAk1jh9nS4IF9k-Z3S1M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hog2in3JAk1jh9nS4IF9k-Z3S1M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/ZcEgMaLAb8E" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/6578847561128748955/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/10/using-conditional-formatting-on-exam.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/6578847561128748955" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/6578847561128748955" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/ZcEgMaLAb8E/using-conditional-formatting-on-exam.html" title="Using Conditional Formatting on an Exam Results Report" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/--3aUqWb-s9k/Tqp0zt0SbsI/AAAAAAAAAks/aZvVc9IfBJQ/s72-c/table.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/10/using-conditional-formatting-on-exam.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4275474025151706987</id><published>2011-10-21T09:01:00.000-07:00</published><updated>2011-10-21T09:01:15.207-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Update Query" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="Action Query" /><title type="text">Creating an Update Query to Update a Salaries and Wages Database</title><content type="html">&lt;div style="text-align: justify;"&gt;Imagine you have responsibility for the management of a Company's Salaries and Wages database. &amp;nbsp;The company employs 200 colleagues, and it is your job to process the annual pay increase. The problem you face is that different groups of employees receive a different percentage rate increase; and each employee within a group may have a different salary level to start with. &amp;nbsp;So what is an efficient way to update each employee's salary without having to having to go through each record manually? &amp;nbsp;A good solution would be to use an &lt;i&gt;Update Query&lt;/i&gt;.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Update Queries are a type of Action Query, similar in nature to &lt;a href="http://ms-access-tips.blogspot.com/2011/09/removing-multiple-records-with-delete.html"&gt;Delete Queries&lt;/a&gt;, which I blogged about last month. &amp;nbsp;However, whereas a Delete Query will find a group of records matching a given criteria and &lt;i&gt;delete&lt;/i&gt; them from the table, the Update Query will find a group of records matching a given criteria and &lt;i&gt;update&lt;/i&gt; one or more fields in each of those records. &amp;nbsp;So for example, we can use an Update Query to update the salaries of all staff with the job title,&amp;nbsp;&lt;b&gt;Telesales Administrator&lt;/b&gt;.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The great thing about using an update query is that we can update a field to an absolute value or a value based on a calculation. &amp;nbsp;So in addition to being able to update all Telesales Administrator salaries to a fixed value such as, say, £15000, we could also update all existing Telesales Administrator salaries by, say, 5%. &amp;nbsp;So in a scenario where each Telesales Administrator is on a different salary level to begin with, it makes sense to do the latter to update each unique salary figure. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Please feel free to download the completed solution to the above scenario by clicking this link: &lt;a href="http://www.dealing-with-data.net/exercises/UpdateQuerySolution.accdb"&gt;Example Update Query&lt;/a&gt;. &amp;nbsp;I recommend you begin by opening &lt;b&gt;tblEmployees&lt;/b&gt;&amp;nbsp;and take a look at the 12 sample records and then see how the records for Telesales employees change after the &lt;b&gt;qryUpdateTelesalesSalaries &lt;/b&gt;Update Query is run. &amp;nbsp;You can also follow the instructions below to find out how to create this Update Query yourself.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-R_iiOh65NMc/TqFFCvUz0eI/AAAAAAAAAiY/xQBaJXt5HnI/s1600/table.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="216" src="http://2.bp.blogspot.com/-R_iiOh65NMc/TqFFCvUz0eI/AAAAAAAAAiY/xQBaJXt5HnI/s400/table.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Figure 1: &lt;b&gt;tblEmployees&lt;/b&gt;. &amp;nbsp;As you can see, there are 6 &amp;nbsp;Telesales Employees.&lt;br /&gt;Notice how their salaries change after the&lt;i&gt; Update Query&lt;/i&gt; is run. &amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Creating an Update Query&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span"&gt;So how do we create this Update Query? &amp;nbsp;It is easy. &amp;nbsp;We do it in two stages. &amp;nbsp;First of all we create a standard &lt;a href="http://www.dealing-with-data.net/create-access-query.html"&gt;Select Query&lt;/a&gt;&amp;nbsp;which uses a criteria to find the group of employee records who have Telesales as their job title. &amp;nbsp;Then we convert the query to an Update Query, and in the process, we enter the calculation which updates the existing salary level for each Telesales Administrator. &amp;nbsp;&amp;nbsp;Lets do this step by step:&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Stage One - Testing the Criteria with a Select Query&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;Click the QUERY DESIGN icon (located on the QUERIES group of the CREATE ribbon).&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Select the &lt;b&gt;tlbEmployees &lt;/b&gt;table from the SHOW TABLES dialog form.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Double click the &lt;b&gt;JobTitle &lt;/b&gt;and &lt;b&gt;Salary &lt;/b&gt;fields from the employees table, so they appear as columns on the Query Design Grid.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Enter&lt;b&gt; ="Telesales&lt;/b&gt;" in the criteria row of the &lt;b&gt;JobTitle &lt;/b&gt;column.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click the RUN icon to run the query.&lt;/li&gt;&lt;/ol&gt;&lt;div style="text-align: justify;"&gt;The results of the query are shown in the screenshot below:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-rxA40eEk8PM/TqFHXT8lW8I/AAAAAAAAAig/jKgRvBKd4NU/s1600/select-query.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-rxA40eEk8PM/TqFHXT8lW8I/AAAAAAAAAig/jKgRvBKd4NU/s1600/select-query.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;Results of the &lt;i&gt;Select Query&lt;/i&gt;&lt;br /&gt;in stage one.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;As you can see, the query has found all six records where the employee's job title is &lt;b&gt;Telesales&lt;/b&gt;. &amp;nbsp;We could have included their names and employee id's in the results, but this is not necessary. &amp;nbsp;Once we convert it to an Update Query and click run, we won't actually see the query results until we open the underlying table and note the updated fields in each of the records matching the criteria. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Stage Two - Converting to an Update Query&lt;/b&gt;&lt;/div&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;Re-open the Select Query in Design View. &amp;nbsp;If the Select Query is already open in DATASHEET VIEW, simply click the DESIGN VIEW icon from the VIEWS group of the HOME ribbon. &amp;nbsp;Otherwise you can highlight the Query name in the NAVIGATION PANE, right click the mouse, and then click the DESIGN VIEW icon from the drop down menu.&lt;/li&gt;&lt;li&gt;&lt;div style="text-align: justify;"&gt;Once the Query opens in DESIGN VIEW, click the UPDATE QUERY icon from the QUERY TYPE group of the DESIGN ribbon.&amp;nbsp;The Icon is then highlighted in orange.&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-ROdskKbYvO0/TqFqpVVueMI/AAAAAAAAAi4/19-1j2C5pno/s1600/update-query-icon.JPG" /&gt;You will also notice that the SHOW and SORT rows of the QUERY DESIGN GRID have disappeared, being replaced by a new row called UPDATE.&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div style="text-align: justify;"&gt;All we need to do now is enter the calculation into the UPDATE row of the &lt;b&gt;Salary &lt;/b&gt;column. &amp;nbsp;The calculation to enter is:&amp;nbsp;&lt;b&gt;[salary]*1.05&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-OZvg2hGcJqo/TqGW8k51vpI/AAAAAAAAAjg/E02FrNj7EI4/s1600/update-query-design-grid.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-OZvg2hGcJqo/TqGW8k51vpI/AAAAAAAAAjg/E02FrNj7EI4/s1600/update-query-design-grid.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&amp;nbsp;&lt;/b&gt;This is what the Query Design Grid should&lt;br /&gt;now look like for the&amp;nbsp;&lt;i&gt;Update Query&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click the RUN icon from the RESULTS group of the DESIGN ribbon. &amp;nbsp;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click YES when you &amp;nbsp;receive a warning message saying "&lt;i&gt;you are about to update 6 row(s)&lt;/i&gt;".&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;Once you have run the query and clicked YES to the warning message, you won't see the changes until you re-open (or refresh) the underlying &lt;b&gt;tblEmployees&lt;/b&gt; table. &amp;nbsp;When you do so, you will see that the Salaries for Telesales staff have been updated by 5% as expected (see figure 4 below).&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-A_5oenyspEg/TqFzKi9QPyI/AAAAAAAAAjQ/EZylJ-59WsA/s1600/updated-table.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="216" src="http://2.bp.blogspot.com/-A_5oenyspEg/TqFzKi9QPyI/AAAAAAAAAjQ/EZylJ-59WsA/s400/updated-table.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4:&lt;/b&gt; The Updated &lt;b&gt;tblEmployees&amp;nbsp;&lt;/b&gt;Table.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-4275474025151706987?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lFfeqOPn-iaxa6axklWicebjK6w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lFfeqOPn-iaxa6axklWicebjK6w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lFfeqOPn-iaxa6axklWicebjK6w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lFfeqOPn-iaxa6axklWicebjK6w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/dFkzhXdrKt8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/4275474025151706987/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/10/creating-update-query-to-update.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/4275474025151706987" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/4275474025151706987" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/dFkzhXdrKt8/creating-update-query-to-update.html" title="Creating an Update Query to Update a Salaries and Wages Database" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-R_iiOh65NMc/TqFFCvUz0eI/AAAAAAAAAiY/xQBaJXt5HnI/s72-c/table.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/10/creating-update-query-to-update.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-2239477184469881796</id><published>2011-10-14T10:59:00.000-07:00</published><updated>2011-10-14T11:07:00.613-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><category scheme="http://www.blogger.com/atom/ns#" term="design" /><category scheme="http://www.blogger.com/atom/ns#" term="Controls" /><title type="text">Using The Tab Control for Tidy Form Presentation</title><content type="html">The &lt;i&gt;Tab Control&lt;/i&gt; is a type of form control used to aid presentation and enhance user-friendliness. &amp;nbsp;It works much the same way as the Access Ribbon - the user clicks a tab to reveal a new strip. &amp;nbsp;However, instead of Ribbon icons, these strips contain our text boxes or other form control that we choose. &amp;nbsp;As such, it allows us to separate the fields on our forms, displaying one group at a time. Here is a screen shot of one I prepared earlier:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-GKB4HkpxIjU/TpgJY7z6ekI/AAAAAAAAAhY/6c2AEvmPPPM/s1600/tab-control.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="196" src="http://3.bp.blogspot.com/-GKB4HkpxIjU/TpgJY7z6ekI/AAAAAAAAAhY/6c2AEvmPPPM/s320/tab-control.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1a: The Tab Control: Tab 1 "Personal".&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ALY3y4axLHw/TpgKL5k4nLI/AAAAAAAAAho/-GCYWr2bgD0/s1600/tab-control2.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="195" src="http://4.bp.blogspot.com/-ALY3y4axLHw/TpgKL5k4nLI/AAAAAAAAAho/-GCYWr2bgD0/s320/tab-control2.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1b:&amp;nbsp;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;The Tab Control: Tab 2 "Address".&lt;/b&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-2wh2oYqlgu4/Tpgs3ysUqcI/AAAAAAAAAhw/iPQeAaaECKw/s1600/tab-control3.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="195" src="http://1.bp.blogspot.com/-2wh2oYqlgu4/Tpgs3ysUqcI/AAAAAAAAAhw/iPQeAaaECKw/s320/tab-control3.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1c:&amp;nbsp;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;The Tab Control: Tab 3 "Education".&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As you can see, the Employee Record Form in figure 1 above contains a Tab Control which is comprised of three separate &lt;i&gt;Tabs&lt;/i&gt;. &amp;nbsp;The first tab shown in figure 1a has been given the caption, "&lt;b&gt;Personal"&lt;/b&gt;, and displays fields relating to the Employee's &lt;i&gt;ID&lt;/i&gt;, &lt;i&gt;Name &lt;/i&gt;and &lt;i&gt;Date of Birth&lt;/i&gt;. The second tab in 1b relates to the employee's &lt;i&gt;Address&lt;/i&gt;, and the third in 1c relates to &lt;i&gt;Education&lt;/i&gt;. &amp;nbsp;As such, we see how the Tab Control has enabled us to organize the information into logical categories, in addition to presenting that information in a tidy and easy to access format. &amp;nbsp;In fact,we have condensed&amp;nbsp;11 fields to fit on a small &lt;a href="http://ms-access-tips.blogspot.com/2011/09/creating-dialogue-form.html"&gt;Dialog form&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Lets take a look at how the form from figure 1 was created.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Adding a Tab Control&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;To begin with I created a new form by clicking the FORM DESIGN icon. &amp;nbsp;This is located in the FORMS group of the CREATE ribbon.&lt;/li&gt;&lt;li&gt;I &lt;a href="http://ms-access-tips.blogspot.com/2009/11/creating-access-2007-form-from-scratch.html"&gt;set the RECORD SOURCE property&lt;/a&gt;&amp;nbsp;(via the&amp;nbsp;DATA tab of the&amp;nbsp;PROPERTY SHEET) to the appropriate table.&lt;/li&gt;&lt;li&gt;I clicked the TAB CONTROL icon &lt;img border="0" src="http://4.bp.blogspot.com/-_p7GebTHmRo/Tpg0dGDS9AI/AAAAAAAAAh4/g4CuGD9_eiw/s1600/tab-control-icon.JPG" /&gt;&amp;nbsp;(located in the CONTROLS group of the DESIGN ribbon), and clicked a position for it to go on the form design grid. A blank Tab Control with two pages appears on the grid.&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-OJ1nUwr8kQQ/Tpg2jBViWJI/AAAAAAAAAiA/Ej1GPuX65-w/s1600/blank-tab-control.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-OJ1nUwr8kQQ/Tpg2jBViWJI/AAAAAAAAAiA/Ej1GPuX65-w/s1600/blank-tab-control.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;A blank &lt;b&gt;Tab Control &lt;/b&gt;added to&amp;nbsp;the&lt;br /&gt;&amp;nbsp;Form Design Grid.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;/ol&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Customizing the Tab Control&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;The &amp;nbsp;process of customizing the Tab Control simply involved adding an extra tab page and giving each tab its own individual name - ie &lt;b&gt;Personal&lt;/b&gt;, &lt;b&gt;Address &lt;/b&gt;and &lt;b&gt;Education&lt;/b&gt;. &amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;I began by selecting the Tab Control by clicking its outer edge so that it was highlighted.&amp;nbsp;&lt;/li&gt;&lt;li&gt;Then I clicked the INSERT PAGE icon &lt;img border="0" src="http://3.bp.blogspot.com/-nbpwDhje8fo/TphYUzueTsI/AAAAAAAAAiI/vDzNEdBJ0xg/s1600/insert-page.JPG" /&gt;&amp;nbsp;(located in the CONTROLS group of the DESIGN ribbon). &amp;nbsp;This added a new blank page to the tab control, thereby giving us the three required tabs.&lt;/li&gt;&lt;li&gt;Next I clicked the part of the Tab Control which says PAGE1 to select this particular tab page.&amp;nbsp;&lt;/li&gt;&lt;li&gt;I then changed the CAPTION property for PAGE1 to "'&lt;b&gt;Personal&lt;/b&gt;". &amp;nbsp;This property is located on the FORMAT TAB of the PROPERTY SHEET.&lt;/li&gt;&lt;li&gt;I repeated the process for the other two tab pages - &amp;nbsp;so I had a tabs for &amp;nbsp;"&lt;b&gt;Personal&lt;/b&gt;",&amp;nbsp;"&lt;b&gt;Address&lt;/b&gt;" and "&lt;b&gt;Education&lt;/b&gt;" respectively.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Adding Text boxes to the Tab Control&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;The final stage involved adding the text boxes to the tab control. &amp;nbsp;The key thing to remember here is that it is important to select the required tab page before adding the text box to the tab control. &amp;nbsp;It is also worth mentioning that if you are moving an &lt;i&gt;existing &lt;/i&gt;form control to the tab control, you will need to &lt;i&gt;cut and paste&lt;/i&gt; rather than simply &lt;i&gt;drag and drop &lt;/i&gt;(otherwise it will sit on top of the tab control and not be a part of it).&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;I&amp;nbsp;began by&amp;nbsp;clicking the ADD EXISTING FIELDS icon (located in the TOOLS group of the DESIGN RIBBON). &amp;nbsp;This opened the FIELD LIST pane.&lt;/li&gt;&lt;li&gt;I then selected the &lt;b&gt;Personal &lt;/b&gt;Tab of the tab control (like I did in stage three of the customization process above). &amp;nbsp;&lt;/li&gt;&lt;li&gt;I then dragged the first four fields - &lt;b&gt;EmployeeId&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;- from the pane over to the tab control and positioned them in the required location. When you try this yourself, notice how the tab control goes black as you position the text box. This shows that it is being added to the Tab Control rather than the form Detail.&lt;/li&gt;&lt;li&gt;I repeated stages 2 and 3, adding the Address and Education related fields to the &lt;b&gt;Address &lt;/b&gt;and &lt;b&gt;Education &lt;/b&gt;tabs respectively. &amp;nbsp;&lt;/li&gt;&lt;li&gt;All I had to do then was align and resize the text boxes for a professional finish. &amp;nbsp;A good way of doing this is to click on the text box and manually enter the grid position on the FORMAT tab of the PROPERTY SHEET - the TOP property determines the &lt;i&gt;vertical &lt;/i&gt;grid position, the LEFT property the &lt;i&gt;horizontal&lt;/i&gt;, and the WIDTH is self explanatory. You can also position the text box label's separately using the same method.&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-UnrbaO-0QFU/TphfTBwItEI/AAAAAAAAAiQ/XHPfrm_fjtw/s1600/design-grid.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="143" src="http://2.bp.blogspot.com/-UnrbaO-0QFU/TphfTBwItEI/AAAAAAAAAiQ/XHPfrm_fjtw/s320/design-grid.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3: &lt;/b&gt;Adding fields to the Personal Tab Page.&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 class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-2239477184469881796?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jP-9HablzFKK1gWXJiaKmuG5W9M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jP-9HablzFKK1gWXJiaKmuG5W9M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jP-9HablzFKK1gWXJiaKmuG5W9M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jP-9HablzFKK1gWXJiaKmuG5W9M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/2QE5d-SWBXM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/2239477184469881796/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/10/using-tab-control-for-tidy-form.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/2239477184469881796" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/2239477184469881796" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/2QE5d-SWBXM/using-tab-control-for-tidy-form.html" title="Using The Tab Control for Tidy Form Presentation" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-GKB4HkpxIjU/TpgJY7z6ekI/AAAAAAAAAhY/6c2AEvmPPPM/s72-c/tab-control.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/10/using-tab-control-for-tidy-form.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-926252092928416848</id><published>2011-09-30T11:15:00.000-07:00</published><updated>2011-09-30T11:16:16.983-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="filters" /><category scheme="http://www.blogger.com/atom/ns#" term="properties" /><category scheme="http://www.blogger.com/atom/ns#" term="reports" /><title type="text">Filtering Report Results Using the Filter Property</title><content type="html">&lt;div style="text-align: justify;"&gt;In this tip we are going to filter the results of a Report to display records with order amounts above a given value. &amp;nbsp;In so doing we are going to pay special attention to two Report properties: these are FILTER, and FILTER ON LOAD.&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;Our solution works when the user opens a &lt;a href="http://ms-access-tips.blogspot.com/2011/09/creating-dialogue-form.html"&gt;Dialog Form&lt;/a&gt; containing a text box and command button. &amp;nbsp;The user enters an amount value in the text box, and clicks the command button. &amp;nbsp;The command button then runs a small amount of VBA code to open the report. &amp;nbsp;As the report loads, it applies a filter defined in the Report's Filter Property to produce the desired result.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-7fRyg_BAkAI/ToWMqRYqeHI/AAAAAAAAAg0/vP4dcivwv2I/s1600/amount-parameter.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="133" src="http://1.bp.blogspot.com/-7fRyg_BAkAI/ToWMqRYqeHI/AAAAAAAAAg0/vP4dcivwv2I/s320/amount-parameter.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1: Dialog Form &lt;/b&gt;to collect the&amp;nbsp;&lt;b&gt;Amount Parameter&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;So how does this work?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When the Report opens, Access checks the report's FILTER ON LOAD property (which we have set to YES). When it detects the property is set to YES, this tells Access to &lt;i&gt;apply&lt;/i&gt; the report's Filter (which we have entered into the report's FILTER property). Our filter then references the users parameter value from the Dialog Form text box, and filters all records with Order Amounts greater than or equal to that value.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;You can download the completed solution from here: &lt;a href="http://www.dealing-with-data.net/exercises/filter-property-tip.accdb"&gt;Filter Property Tip Database&lt;/a&gt;. You may also want to work your way through the instructions below.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Table&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;The solution contains a Table (&lt;b&gt;tblOrders&lt;/b&gt;), a Dialog Form (&lt;b&gt;frmParameter&lt;/b&gt;) and a Report (&lt;b&gt;rptOrders&lt;/b&gt;). &amp;nbsp;In the screenshot, below you will see the data&amp;nbsp;we shall be working with&amp;nbsp;in &lt;b&gt;tblOrders&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-TVWOUaHIFAA/ToW6KAcTICI/AAAAAAAAAg4/O27cwju4IOg/s1600/orders-table.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-TVWOUaHIFAA/ToW6KAcTICI/AAAAAAAAAg4/O27cwju4IOg/s400/orders-table.JPG" width="362" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: tblOrders&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;As you can see the table is made up of four fields: &lt;b&gt;OrderId &lt;/b&gt;(AutoNumber), &lt;b&gt;OrderDate &lt;/b&gt;(Date/Time), &lt;b&gt;Customer &lt;/b&gt;(Text), and &lt;b&gt;Total &lt;/b&gt;(Currency). &amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Dialog Form&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;We then create the dialog form shown in Figure 1 above (there is more information about &lt;a href="http://ms-access-tips.blogspot.com/2011/09/creating-dialogue-form.html"&gt;Dialog Forms in my last post&lt;/a&gt;). &amp;nbsp;I have referred to the textbox as &lt;b&gt;txtAmount&lt;/b&gt;, the control button as &lt;b&gt;cmdOpenReport&lt;/b&gt;, and the form itself as &lt;b&gt;frmParameter&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;As I have already mentioned, the command button runs a small amount of VBA Code when clicked by the user. &amp;nbsp;To add this code:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;Select the command button on the form design grid, and click the PROPERTY SHEET icon (located in the TOOLS group of the DESIGN ribbon). &amp;nbsp;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;When the PROPERTY SHEET opens, click the EVENT TAB. &amp;nbsp;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Then select the ON CLICK event by clicking into that particular cell of the grid. &amp;nbsp;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;A three dot &amp;nbsp;symbol appears at the right edge of the cell. Click it and select CODE BUILDER from the CHOOSE BUILDER dialog box which has opened. &amp;nbsp;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Then click the OK button and the VBA editor opens.&lt;/li&gt;&lt;/ol&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-A_yCFVCIzwI/ToXqvFuxeXI/AAAAAAAAAhI/V35ebaL6x9M/s1600/onclick-event.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="110" src="http://4.bp.blogspot.com/-A_yCFVCIzwI/ToXqvFuxeXI/AAAAAAAAAhI/V35ebaL6x9M/s320/onclick-event.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3: &lt;/b&gt;The &lt;i&gt;On Click&lt;/i&gt; Event on &lt;br /&gt;the PROPERTIES SHEET.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;You can can copy the code below and paste it onto the editor. &amp;nbsp;The top and bottom lines that begin &lt;b&gt;Private Sub... &lt;/b&gt;and &lt;b&gt;End Sub &lt;/b&gt;respectively&amp;nbsp;should have appeared already, so you just need to copy the middle section in between:&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;hr style="text-align: justify;" /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;Private Sub cmdOpenReport_Click()&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;On Error GoTo MyError&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.OpenReport "rptOrdersFiltered", acViewReport&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp; &amp;nbsp; DoCmd.Close acForm, Me.Name&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;Leave:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp; &amp;nbsp; Exit Sub&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;MyError:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp; &amp;nbsp; MsgBox "Error " &amp;amp; &amp;nbsp;Err.Number &amp;amp; &amp;nbsp;": " &amp;amp; &amp;nbsp;Error$&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp; &amp;nbsp; Resume Leave&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;End Sub&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;hr style="text-align: justify;" /&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;The two important lines in this section of code begin with &lt;b&gt;DoCmd &lt;/b&gt;(meaning &lt;i&gt;do command&lt;/i&gt;). &amp;nbsp;The first of these is the command to open the form in Report View. &amp;nbsp;The second closes the Dialog form once the report has opened. &amp;nbsp;NB it is very important the report opens &lt;i&gt;before &lt;/i&gt;&amp;nbsp;the Dialog Form closes, because it needs to reference the value contained in the Dialog Form's Textbox as the it loads. &amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;The Report&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;The quickest way to create the Report is to base it on our table.&lt;/div&gt;&lt;br /&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;Select&amp;nbsp;&lt;b&gt;tblOrders &lt;/b&gt;in the Navigation Pane. &amp;nbsp;It will highlight in orange.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Then select &amp;nbsp;the CREATE ribbon , and click the REPORT icon (located in the REPORTS GROUP).&amp;nbsp;&lt;/li&gt;&lt;/ol&gt;&lt;div style="text-align: justify;"&gt;This creates a basic report which we can then then modify in DESIGN VIEW as required.&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-_jFxFmUqXx8/ToW9b681BMI/AAAAAAAAAhA/lDH-ePwpd_M/s1600/report-design.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="272" src="http://4.bp.blogspot.com/-_jFxFmUqXx8/ToW9b681BMI/AAAAAAAAAhA/lDH-ePwpd_M/s640/report-design.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4:&lt;/b&gt; Report Design.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Setting the Filter Properties&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Next we turn our attention to setting the Report's Filter Properties accessed via its Property sheet.&lt;/div&gt;&lt;br /&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;Click the Square Box in the top right hand corner of the Report Design Grid. &amp;nbsp;This ensures we are going to be working the properties of the actual Form (rather than one of its controls).&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click on the PROPERTY SHEET icon (located in the TOOLS group of the DESIGN ribbon) whilst the Report is open in Design View.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click the DATA TAB of the pane.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Make sure the SELECTION TYPE is set to REPORT. &amp;nbsp;This should be the case if you carried out step 1 successfully. &amp;nbsp;Otherwise just change the selection to &lt;b&gt;Form &lt;/b&gt;in the drop down list.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Enter the following into the FILTER property cell:&amp;nbsp;&lt;b style="color: #20124d;"&gt;Total &amp;gt;= forms![frmParameter]![txtAmount] &lt;/b&gt;. &amp;nbsp;This has the effect of filtering out report records where the amount value in the &lt;b&gt;Total &lt;/b&gt;field is greater or equal to that entered by the user in the Dialog Form's textbox.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Then set the FILTER ON LOAD PROPERTY to &lt;b&gt;YES&lt;/b&gt;. &amp;nbsp;This ensures the filter is applied when the forms loads.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Save the Report as &lt;b&gt;rptOrdersFiltered&lt;/b&gt;.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Close the Report&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-D--arjqu7L4/ToXkAQw-5II/AAAAAAAAAhE/BKuWjVoaXJY/s1600/filter-property.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="202" src="http://4.bp.blogspot.com/-D--arjqu7L4/ToXkAQw-5II/AAAAAAAAAhE/BKuWjVoaXJY/s640/filter-property.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 5: &lt;/b&gt;The Form's Filter Properties. &amp;nbsp;Note the reference to the textbox&lt;br /&gt;on our Dialog Form in the FILTER property cell.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;The solution should now be ready to run. &amp;nbsp;Just click the &lt;b&gt;frmParameter &lt;/b&gt;form in the Navigation Pane to begin. &amp;nbsp;The screenshot below shows what the report results look like when £50,000 is entered by the user as the amount parameter:&amp;nbsp;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Zt2XMvcUk8Y/ToXserjfb5I/AAAAAAAAAhU/J9ywiAo2b4Y/s1600/filtered-report.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="356" src="http://4.bp.blogspot.com/-Zt2XMvcUk8Y/ToXserjfb5I/AAAAAAAAAhU/J9ywiAo2b4Y/s640/filtered-report.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 6:&lt;/b&gt; Report Results filtered for amounts greater than or equal to £50,000.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-926252092928416848?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UI5g0LSOFai7z7AmmYd9zM5AAPc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UI5g0LSOFai7z7AmmYd9zM5AAPc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UI5g0LSOFai7z7AmmYd9zM5AAPc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UI5g0LSOFai7z7AmmYd9zM5AAPc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/fz1Xg-lSYeY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/926252092928416848/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/09/filtering-report-results-using-filter.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/926252092928416848" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/926252092928416848" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/fz1Xg-lSYeY/filtering-report-results-using-filter.html" title="Filtering Report Results Using the Filter Property" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-7fRyg_BAkAI/ToWMqRYqeHI/AAAAAAAAAg0/vP4dcivwv2I/s72-c/amount-parameter.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/09/filtering-report-results-using-filter.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-412541826793488815</id><published>2011-09-23T11:37:00.000-07:00</published><updated>2011-09-24T02:13:57.803-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><category scheme="http://www.blogger.com/atom/ns#" term="dialog" /><title type="text">Creating a Dialog Form</title><content type="html">&lt;i&gt;Dialog Forms&lt;/i&gt; are an integral part of most customized Access Database Applications. &amp;nbsp;As developers, we set them up to enable our applications to communicate and interact with users. &amp;nbsp;The simplest sort of dialog box is one which displays a message. &amp;nbsp;These may be created using VBA's MsgBox Function or the MsgBox Macro Action. &amp;nbsp; Others involve a greater degree of customization, especially when the application requires the user to provide information such as parameters for a query. &amp;nbsp;One way to do is to create a standard Access form and modify it's properties to make it into a &lt;i&gt;Dialog Form&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-B0AQcjYVWTE/TnyhlU7a0eI/AAAAAAAAAgs/jCQRa9ZTuAk/s1600/dialogue-form.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="242" src="http://3.bp.blogspot.com/-B0AQcjYVWTE/TnyhlU7a0eI/AAAAAAAAAgs/jCQRa9ZTuAk/s400/dialogue-form.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt;&amp;nbsp;This&amp;nbsp;&lt;i&gt;&lt;b&gt;Dialog Form&lt;/b&gt;&lt;/i&gt;&amp;nbsp;obtains date parameters&amp;nbsp;used to restrict the&lt;br /&gt;records displayed in a report. &amp;nbsp;You may remember this was NorAzri's&amp;nbsp;chosen&lt;br /&gt;method&amp;nbsp;for filtering report results mentioned in my last post.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;To create a Dialog Form such as that displayed in figure one, we begin by creating an &lt;i&gt;unbound&lt;/i&gt; form. &amp;nbsp;This is done by clicking the FORM DESIGN icon from the FORMS group of the CREATE ribbon. &amp;nbsp;The term &lt;i&gt;unbound&lt;/i&gt;&amp;nbsp;means that the form is not bound to a particular &lt;i&gt;Table &lt;/i&gt;as with conventional forms. &amp;nbsp;The information it is designed to collect is temporary, and does not need to be stored.&lt;br /&gt;&lt;br /&gt;When a new form opens in design view, the screen will show a blank grid in the main window, and a variety of &amp;nbsp;&lt;i&gt;form controls &lt;/i&gt;in the CONTROLS group of the DESIGN ribbon. &amp;nbsp;The Dialog Form in figure 1 uses four &lt;i&gt;Combo Box&lt;/i&gt; Controls and a &lt;i&gt;Command Button&lt;/i&gt;. &amp;nbsp;The values displayed in the Combo Boxes are defined in the Row Source Property. &amp;nbsp;I recently blogged about &lt;a href="http://ms-access-tips.blogspot.com/2011/07/customizing-access-combo-box.html"&gt;Customizing an Access Combo Box&lt;/a&gt;. &amp;nbsp;If you are interested, I recommend you check it out by following the link above (just remember that the combo boxes in this example do not need a &lt;i&gt;Control Source&lt;/i&gt; because we do not need to store it's data in a table).&lt;br /&gt;&lt;br /&gt;However in this post we are mainly interested in the process of changing the appearance and action of an ordinary form to that of a Dialog Form. &amp;nbsp;So how is this done? &amp;nbsp;The answer to this lies in a number of key form properties. &amp;nbsp;The two most important properties to understand are the POP UP and MODAL properties. &lt;br /&gt;&lt;br /&gt;The POP UP property ensures that when the dialog form is opened, it appears as a &lt;i&gt;pop up&lt;/i&gt; box rather than a full size form. Otherwise it would just appear as an ordinary form rather than dialog form. &amp;nbsp;As such this property should always be set to YES. &amp;nbsp;Setting the MODAL property to YES ensures the user cannot ignore the dialog form by clicking on a ribbon icon or form control, for example. &amp;nbsp;The idea here is that your application is waiting for a user response. Access will not do anything until that response is given, and/or the dialog form is closed. &amp;nbsp;These properties are located on the OTHER TAB of the PROPERTY SHEET.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Si1_mV3al50/TnymVjN03uI/AAAAAAAAAgw/jnIYat0y32M/s1600/form-properties.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="128" src="http://3.bp.blogspot.com/-Si1_mV3al50/TnymVjN03uI/AAAAAAAAAgw/jnIYat0y32M/s400/form-properties.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;Set the &lt;b&gt;POP UP&lt;/b&gt;&amp;nbsp;and &lt;b&gt;MODAL &lt;/b&gt;properties to &lt;b&gt;YES&lt;/b&gt;. &amp;nbsp;This is done&lt;br /&gt;&amp;nbsp;from the&amp;nbsp;OTHER TAB of the PROPERTY SHEET. &amp;nbsp;The property &lt;br /&gt;sheet is&amp;nbsp;accessed by clicking the PROPERTY SHEET icon &lt;br /&gt;on the TOOLS group of the DESIGN ribbon.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;NB When you change these properties make sure the SELECTION TYPE of the PROPERTY SHEET is set to FORM. &amp;nbsp;If it is not, just click the drop down list at the top of the sheet and change it. Alternatively click the square box at the top left hand corner of the DESIGN GRID.&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;If you look again at the dialog form in figure1&lt;i&gt;&amp;nbsp;&lt;/i&gt;you will notice there are no &lt;i&gt;navigation buttons&lt;/i&gt; or &lt;i&gt;record selectors&lt;/i&gt; which forms normally have by default. &amp;nbsp;To remove these just go to the FORMAT TAB of the PROPERTY SHEET and change the NAVIGATION BUTTONS and RECORD SELECTORS properties to NO. &lt;br /&gt;&lt;br /&gt;You may also notice that our dialog form has a border style specific to dialog forms. &amp;nbsp;One of its features is that the user cannot resize it, thereby diminishing its impact! &amp;nbsp;This is attained by changing the BORDER STYLE property to DIALOG. &lt;br /&gt;&lt;br /&gt;One of the more subtle properties that you might want to change is that of the SCROLL BARS property. &amp;nbsp;I recommend you set this to NEITHER. &amp;nbsp;Apart from the fact you should not need to scroll a dialog form, Access also leaves a thick white line at the bottom of the form if this is not changed. &amp;nbsp;This looks particularly bad if you choose a different &lt;i&gt;Back Color&lt;/i&gt; for your form.&lt;br /&gt;&lt;br /&gt;One last property alteration that I recommend, is the addition of a form &lt;i&gt;Caption&lt;/i&gt;. &amp;nbsp;This appears in the top border of the dialog form. &amp;nbsp;In figure 1 I have set this to "Please Enter a Date Range". &amp;nbsp;The caption does not have to be a question, generally it is just a form title. &amp;nbsp;Either way you will need to choose your own caption and enter it in the CAPTION property, the first property on the FORMAT TAB.&lt;br /&gt;&lt;br /&gt;As far as the actual &lt;i&gt;function &lt;/i&gt;of the dialog form is concerned, this particular example runs a VBA sub when the command button is clicked. &amp;nbsp;The code creates an &lt;a href="http://ms-access-tips.blogspot.com/2011/05/gentle-introduction-to-access-sql.html"&gt;SQL &lt;/a&gt;WHERE statement based on information obtained from data entered by the user on the dialog form. &amp;nbsp;This is part of the code that I used:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;varYearFrom = Me!cboYearFrom&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;varYearTo = Me!cboYearTo&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;varMonthFrom = Me!cboMonthFrom&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;varMonthTo = Me!cboMonthTo&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;strSQL = "(Year between " &amp;amp; varYearFrom &amp;amp; " AND " &amp;amp; varYearTo &amp;amp; ") AND (Month between " &amp;amp; varMonthFrom &amp;amp; " AND " &amp;amp; varMonthTo &amp;amp; ")"&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;As you can see, each combo box value is stored in a variable in the first four lines of code. &amp;nbsp;These variables are then integrated into the string containing the SQL Statement. Once we have the SQL Statement stored in the string &lt;b&gt;strSQL&lt;/b&gt;, this can be passed as the WHERE parameter of the DoCmd.OpenReport Method like this:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;DoCmd.OpenReport varForm, acViewReport, , &lt;b&gt;strSQL&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;Then, when our report opens, only records falling within the criteria set in the SQL WHERE statement are displayed. In this case these are all the records between January and December 2011 (see figure 1 above).&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-412541826793488815?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/e_fsUVxC4Dyypblgu6tcXKm8WNU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e_fsUVxC4Dyypblgu6tcXKm8WNU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/e_fsUVxC4Dyypblgu6tcXKm8WNU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e_fsUVxC4Dyypblgu6tcXKm8WNU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/p3osjdGMwu8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/412541826793488815/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/09/creating-dialogue-form.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/412541826793488815" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/412541826793488815" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/p3osjdGMwu8/creating-dialogue-form.html" title="Creating a Dialog Form" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-B0AQcjYVWTE/TnyhlU7a0eI/AAAAAAAAAgs/jCQRa9ZTuAk/s72-c/dialogue-form.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/09/creating-dialogue-form.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-8545030763927191290</id><published>2011-09-16T11:10:00.000-07:00</published><updated>2011-09-16T11:11:31.393-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="DatePart" /><category scheme="http://www.blogger.com/atom/ns#" term="functions" /><title type="text">Manipulating Dates Using the DatePart Function</title><content type="html">I was recently asked a question on my &lt;a href="http://www.facebook.com/pages/Access-2007-Tutorial/201397826545638?sk=wall&amp;amp;filter=1"&gt;Access 2007 Tutorial&amp;nbsp;Facebook Page&lt;/a&gt; which involved the manipulation of dates. &amp;nbsp;In my answer to this question, I suggested a solution that made use of the &lt;i&gt;DatePart&lt;/i&gt; Function. &amp;nbsp;If you are interested, I was replying to&amp;nbsp;NorAzri's&amp;nbsp;&lt;i&gt;comment&amp;nbsp;&lt;/i&gt;on his post of the&amp;nbsp;&lt;b&gt;5th Sep 2011&lt;/b&gt;. &amp;nbsp;However, manipulating dates in this way is quite an interesting area, so I thought I would use this blog to write a bit more about the function.&lt;br /&gt;&lt;br /&gt;So what does &lt;i&gt;DatePart&lt;/i&gt;&amp;nbsp;actually do? &amp;nbsp;Put simply, the DatePart Function allows us to isolate &lt;i&gt;part &lt;/i&gt;of a given date. &amp;nbsp;In so doing we may then go on to group or retrieve records according to the date interval set . We use the function by passing an &lt;i&gt;interval &lt;/i&gt;parameter telling Access which part of the date we are interested in, and a second parameter which is the date itself. &amp;nbsp;The syntax for the function is constructed as follows:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif; font-size: large;"&gt;&lt;b&gt;DatePart("Interval", DateValue)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;The interval parameter is comprised of the same values as that used in the related &lt;a href="http://ms-access-tips.blogspot.com/2011/08/calculating-date-difference-using.html"&gt;DateDiff Function&lt;/a&gt; - a function I blogged about in August. &amp;nbsp;These intervals may pertain to the Year ("yyyy"), the Quarter ("q"), or the month ("m") to name but three. There are ten possible interval types in total (going right down to hours, minutes, and seconds).&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;However, NorAzri was interested in filtering his records by &lt;i&gt;month&lt;/i&gt;. &amp;nbsp;So in order to do this we passed &lt;b&gt;"m"&lt;/b&gt; for the interval parameter, and &lt;b&gt;fldDate &lt;/b&gt;(a field value&lt;b&gt;&amp;nbsp;&lt;/b&gt;from the table) for the date parameter. &amp;nbsp;The syntax for this was written as follows:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif; font-size: large;"&gt;&lt;b&gt;DatePart("m", [fldDate])&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The result of the function gave us a numeric month value based on the full date. &amp;nbsp;For example, if the date in &lt;b&gt;fldDate &lt;/b&gt;had been &lt;b&gt;16/09/2011&lt;/b&gt;, the function would have returned the value&lt;b&gt; 9&lt;/b&gt;. This is useful when we have a list of dates, such as that in Figure 1 below, which we want to group by month value in a query or report.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GLbK0owoS0k/TnMgkxUtq3I/AAAAAAAAAgQ/LD78gkMdhLs/s1600/tblOrders.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-GLbK0owoS0k/TnMgkxUtq3I/AAAAAAAAAgQ/LD78gkMdhLs/s320/tblOrders.JPG" width="282" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; &amp;nbsp;List of Orders with dates.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;So lets take a look at how we would use the DatePart Function in a &lt;i&gt;query &lt;/i&gt;to group these order records by month:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-0x9G7xbrlMQ/TnNpEkMuyJI/AAAAAAAAAgU/hc6556-1WVg/s1600/datepart-in-query.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="263" src="http://3.bp.blogspot.com/-0x9G7xbrlMQ/TnNpEkMuyJI/AAAAAAAAAgU/hc6556-1WVg/s320/datepart-in-query.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;As you can see in Figure 2 above, we have created a calculated field called &lt;b&gt;TheMonth &lt;/b&gt;using the DatePart Function. &amp;nbsp;The interval,&amp;nbsp;&lt;b&gt;"m",&lt;/b&gt; has been passed in the first parameter, and the second parameter references the &lt;b&gt;OrderDate &lt;/b&gt;field from &lt;b&gt;tblOrders&lt;/b&gt;. &amp;nbsp;We have also clicked the TOTALS icon from the SHOW/HIDE group of the DESIGN ribbon, setting &lt;b&gt;TheMonth&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;b&gt;Total &lt;/b&gt;fields&lt;b&gt;&amp;nbsp;&lt;/b&gt;to GROUP BY and&amp;nbsp;SUM respectively. &lt;br /&gt;&lt;br /&gt;When we run the Query, any month containing an order will be represented in the results as its own individual row. &amp;nbsp;The first column then displays the Month value derived from the DatePart function in &lt;b&gt;TheMonth&lt;/b&gt;, and the second contains the &lt;i&gt;sum &lt;/i&gt;of order totals for the particular month in question. &amp;nbsp;Figure 3 below shows the query result for our sample data:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-BwY8knoWQ2k/TnNtc5oeeKI/AAAAAAAAAgY/yzLbTppDy9U/s1600/datepart-query-result.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-BwY8knoWQ2k/TnNtc5oeeKI/AAAAAAAAAgY/yzLbTppDy9U/s1600/datepart-query-result.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; Results of Query with Calculated&lt;br /&gt;Field using the&amp;nbsp;&lt;i&gt;DatePart &lt;/i&gt;Function. &amp;nbsp;&lt;b&gt;SumOfTotal&lt;/b&gt;&lt;br /&gt;gives us the total for each group of order records&lt;br /&gt;falling within each Month.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;Another excellent use of &lt;i&gt;DatePart &lt;/i&gt;would be to filter a group of records using a criteria based on this function. &amp;nbsp;For example, if we wanted to show each individual record for all orders falling within the month of May, we would construct our Query as follows:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-b8V6GUK_EWY/TnNx6rzoGNI/AAAAAAAAAgc/HFzxHRvSHGo/s1600/may-sales.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="257" src="http://4.bp.blogspot.com/-b8V6GUK_EWY/TnNx6rzoGNI/AAAAAAAAAgc/HFzxHRvSHGo/s640/may-sales.JPG" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;As you can see, we have kept our calculated field called &lt;b&gt;TheMonth&lt;/b&gt;. &amp;nbsp;However, instead of &lt;i&gt;grouping &lt;/i&gt;all the records from &lt;b&gt;tblOrders &lt;/b&gt;by month, we have added the month value&lt;b&gt; =5&lt;/b&gt;&amp;nbsp;as a criteria for this column. &amp;nbsp;When we run the query, all Orders from May will be displayed.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-n8hwrMjEuZ4/TnN0S9D9ngI/AAAAAAAAAgk/z0cYnKMPFE8/s1600/query-results-for-may.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="110" src="http://4.bp.blogspot.com/-n8hwrMjEuZ4/TnN0S9D9ngI/AAAAAAAAAgk/z0cYnKMPFE8/s400/query-results-for-may.JPG" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 5:&lt;/b&gt;&amp;nbsp;The result of the second Query filters &lt;br /&gt;out all orders from May.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;If we wanted, we could convert this to a parameter query, and use it as the data source for a report. &amp;nbsp;This was something I recommended to NorAzri who wanted to select the Month from a Combo Box on an unbound form, and then produce a report which would filter out records falling within the month in question. &amp;nbsp;If you are interested in seeing the solution I suggested, just follow the link at the top of this post and look down the stream.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-8545030763927191290?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LKX-ql43Od9TPAFypWTiqLkxoH8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LKX-ql43Od9TPAFypWTiqLkxoH8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LKX-ql43Od9TPAFypWTiqLkxoH8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LKX-ql43Od9TPAFypWTiqLkxoH8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/XrOo93u_PnM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/8545030763927191290/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/09/manipulating-dates-using-datepart.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/8545030763927191290" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/8545030763927191290" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/XrOo93u_PnM/manipulating-dates-using-datepart.html" title="Manipulating Dates Using the DatePart Function" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-GLbK0owoS0k/TnMgkxUtq3I/AAAAAAAAAgQ/LD78gkMdhLs/s72-c/tblOrders.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/09/manipulating-dates-using-datepart.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-107960534252919235</id><published>2011-09-09T11:07:00.000-07:00</published><updated>2011-09-09T11:07:03.939-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="forms" /><category scheme="http://www.blogger.com/atom/ns#" term="Access Options" /><category scheme="http://www.blogger.com/atom/ns#" term="Quick Tip" /><title type="text">How to Display a Form Automatically when your Application Opens</title><content type="html">This is a quick tip on how to&amp;nbsp;automatically&amp;nbsp;display a form when the user opens your Access Application. &amp;nbsp;In addition to improving User Friendliness, your database design will also appear much more professional. &amp;nbsp;The step by step instructions below will display the Switchboard form in &lt;i&gt;figure 1&lt;/i&gt; immediately upon the application opening. &amp;nbsp;This will give them a good start point from which to navigate your system.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-jrEdE2lmRKA/Tmo3h-KQKnI/AAAAAAAAAf8/MaoPgC4709E/s1600/switchboard.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="239" src="http://4.bp.blogspot.com/-jrEdE2lmRKA/Tmo3h-KQKnI/AAAAAAAAAf8/MaoPgC4709E/s320/switchboard.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; Switchboard Form opens Automatically&lt;br /&gt;when the Application Opens.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;ol&gt;&lt;li&gt;Open the Database and create a Switchboard Form similar to that in &lt;i&gt;figure 1 &lt;/i&gt;above. &amp;nbsp;Call the form &lt;b&gt;frmSwitchboard&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Click the MICROSOFT OFFICE button in the top right hand corner of the Access Screen. &amp;nbsp;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-KQx3j1-yC2s/TmpCm0PxYFI/AAAAAAAAAgM/A6UeEx_sheM/s1600/Microsoft+Office+Button.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-KQx3j1-yC2s/TmpCm0PxYFI/AAAAAAAAAgM/A6UeEx_sheM/s1600/Microsoft+Office+Button.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;Click the ACCESS OPTIONS button at the bottom of the open pane. &amp;nbsp;This opens the ACCESS &amp;nbsp;OPTIONS dialogue form.&lt;/li&gt;&lt;li&gt;Select CURRENT DATABASE from the menu on the left side of the dialogue form. &amp;nbsp;This displays the &lt;i&gt;Options for the Current Database&lt;/i&gt; (see figure 2 below).&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-HF96O3odpBQ/Tmo6xZ5XaOI/AAAAAAAAAgA/-6pTxkjHjtE/s1600/Access+Options.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-HF96O3odpBQ/Tmo6xZ5XaOI/AAAAAAAAAgA/-6pTxkjHjtE/s1600/Access+Options.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; Options for the Current Database.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;li&gt;The fourth option down from the top is DISPLAY FORM. &amp;nbsp;Click the Combo Box arrow and select &lt;b&gt;frmSwitchboard &lt;/b&gt;from its drop down list,&amp;nbsp;&lt;/li&gt;&lt;li&gt;Click OK to close the ACCESS OPTIONS form.&lt;/li&gt;&lt;li&gt;Close the database.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;The next time you open your application, the Swichboard is displayed automatically without the user needing to select it from the Navigation Pane.&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&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-107960534252919235?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/93n0lDy-FchkUrAq4clEnbSDj6g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/93n0lDy-FchkUrAq4clEnbSDj6g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/93n0lDy-FchkUrAq4clEnbSDj6g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/93n0lDy-FchkUrAq4clEnbSDj6g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/16UMES5Gw3w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/107960534252919235/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/09/how-to-display-form-automatically-when.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/107960534252919235" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/107960534252919235" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/16UMES5Gw3w/how-to-display-form-automatically-when.html" title="How to Display a Form Automatically when your Application Opens" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-jrEdE2lmRKA/Tmo3h-KQKnI/AAAAAAAAAf8/MaoPgC4709E/s72-c/switchboard.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/09/how-to-display-form-automatically-when.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-978855510030521540</id><published>2011-09-02T11:14:00.000-07:00</published><updated>2011-09-02T11:14:18.586-07:00</updated><title type="text">Removing Multiple Records with a Delete Query</title><content type="html">&lt;div style="text-align: justify;"&gt;Imagine you have a contact database containing a list of suppliers. &amp;nbsp;One of those suppliers proved themselves unreliable once to often, so your company decides not to use them any more. &amp;nbsp;It is your job to delete any names from this list that belong to this particular supplier. The only problem is, the contact database contains hundreds of names, a number of which are from the suppliers company. This is where an Access &lt;i&gt;Delete Query&lt;/i&gt; is going to prove very useful.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;i&gt;Delete Queries&lt;/i&gt; are a type of &lt;i&gt;Action Query&lt;/i&gt;&amp;nbsp;ie a Query which performs some sort of &lt;i&gt;action &lt;/i&gt;on our database. &amp;nbsp;In the case of a Delete Query, Access will find a group of records matching a given criteria and delete them from the database table. &amp;nbsp;As such, we can make good use of a Delete Query in the scenario outlined above. &amp;nbsp;By means of a Delete Query, we can find all the records of staff who work for the ex-supplier and delete them from the contact list. &amp;nbsp;Lets take a look at the contact list we are going to working with (shortened for the purpose of this exercise):&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-I9-wT-7LBWY/Tl-yg7MI3hI/AAAAAAAAAfU/xokstDoEcD8/s1600/contact-list.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="320" src="http://4.bp.blogspot.com/-I9-wT-7LBWY/Tl-yg7MI3hI/AAAAAAAAAfU/xokstDoEcD8/s320/contact-list.JPG" width="305" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; The Contact List upon which &lt;br /&gt;we shall&amp;nbsp;run our &lt;i&gt;&lt;b&gt;Delete Query&lt;/b&gt;&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;Lets say the name of our ex-supplier is &lt;b&gt;Company 5&lt;/b&gt;. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So how do we create a Delete Query?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;It's quite simple really. &amp;nbsp;The first stage is to create an initial select query that would give us a list of all the names of staff working for &lt;b&gt;Company 5&lt;/b&gt;. &amp;nbsp;This involves entering &lt;b&gt;"Company 5"&lt;/b&gt; as the query criteria. Once we have run the query and checked its results, we just need to change it to a Delete Query and click RUN again. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;How to Create a Delete Query&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Stage 1 - Creating the initial Select Query&lt;/b&gt;&lt;/div&gt;&lt;ol&gt;&lt;li style="text-align: justify;"&gt;Select the CREATE TAB of the Access Ribbon.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click the QUERY DESIGN icon. &amp;nbsp;It is located in the OTHER group of the CREATE ribbon.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Select &lt;b&gt;tblContacts &lt;/b&gt;from the SHOW TABLE dialogue box.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Drag the asterix (*) from &lt;b&gt;tblContacts &lt;/b&gt;down to the first column of the DESIGN GRID. &amp;nbsp;This is a way of getting the query results to display all fields from the table without having to select each one individually.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Then Drag the &lt;b&gt;Company &lt;/b&gt;field from &lt;b&gt;tblContacts &lt;/b&gt;down to the second column of the grid. &amp;nbsp;We have added this field separately because we are going to enter a criteria in this column.&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click on the CRITERIA row of the &lt;b&gt;Company &lt;/b&gt;column, and add the criteria: &lt;b&gt;"Company 5"&lt;/b&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;The Select Query has now been created. &amp;nbsp;It should look like this:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-v6Ig7ED5AP0/Tl_OVKqsQuI/AAAAAAAAAfY/8u3nV4ILvVo/s1600/query-criteria.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="286" src="http://4.bp.blogspot.com/-v6Ig7ED5AP0/Tl_OVKqsQuI/AAAAAAAAAfY/8u3nV4ILvVo/s320/query-criteria.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; The Select Query created in the&lt;br /&gt;first stage of the &lt;i&gt;&lt;b&gt;Delete Query&lt;/b&gt;&lt;/i&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;It is advisable to run the query at this point and check the results are correct. &amp;nbsp;They should look like this:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-n5SCeu2k86A/Tl_Pj-E49YI/AAAAAAAAAfc/FiR3At9XxzU/s1600/select-query-results.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="87" src="http://3.bp.blogspot.com/-n5SCeu2k86A/Tl_Pj-E49YI/AAAAAAAAAfc/FiR3At9XxzU/s320/select-query-results.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2: &lt;/b&gt;The results from the Select Query.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;As you can see, our select query has found four records from &lt;b&gt;tblContacts &lt;/b&gt;matching the criteria of&amp;nbsp;&lt;b&gt;Company 5&lt;/b&gt;". &amp;nbsp;Since this is the correct result for the dataset we are working with, &amp;nbsp;we can move onto the second stage of the process: converting the&lt;i&gt; Select Query&lt;/i&gt; to a &lt;i&gt;Delete Query&lt;/i&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Stage 2 - Converting the Initial Select Query to a Delete Query&lt;/b&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;&lt;div style="text-align: justify;"&gt;If you look at the QUERY TYPE group of the DESIGN ribbon, you will notice that the SELECT QUERY icon is highlighted orange. &amp;nbsp;We need to change this to DELETE QUERY. &amp;nbsp;To do this just click the DELETE QUERY icon further along the group. &amp;nbsp;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-xj2UjuGficg/TmD6DOOJFBI/AAAAAAAAAfs/dppRNP3VXN0/s1600/query-type-group.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="93" src="http://4.bp.blogspot.com/-xj2UjuGficg/TmD6DOOJFBI/AAAAAAAAAfs/dppRNP3VXN0/s320/query-type-group.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3: &lt;/b&gt;The &lt;b&gt;QUERY TYPE&lt;/b&gt; group of the &lt;b&gt;DESIGN &lt;/b&gt;ribbon.&lt;br /&gt;The &lt;b&gt;DELETE QUERY&lt;/b&gt; icon is highlighted orange.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div style="text-align: justify;"&gt;After the clicking the DELETE icon, you will notice that the row of SHOW tick boxes disappears from the DESIGN GRID, along with the row for SORT. A new row entitled &lt;b&gt;DELETE &lt;/b&gt;has taken their place. &amp;nbsp;Access has filled in the values of FROM and WHERE in the first and second columns respectively. &amp;nbsp;These are &lt;a href="http://ms-access-tips.blogspot.com/2011/05/gentle-introduction-to-access-sql.html"&gt;SQL Keywords&lt;/a&gt;: the FROM keyword indicates the first column contains fields &lt;i&gt;from &lt;/i&gt;&lt;b&gt;tblContacts&lt;/b&gt;, and WHERE indicates the &lt;b&gt;Company &lt;/b&gt;column contains a criteria against the data stored in this field.&amp;nbsp;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-cmraercP0V8/TmCD-3X4IgI/AAAAAAAAAfg/zuuj9awEkR8/s1600/delete-query-design.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="276" src="http://4.bp.blogspot.com/-cmraercP0V8/TmCD-3X4IgI/AAAAAAAAAfg/zuuj9awEkR8/s320/delete-query-design.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: &lt;/b&gt;The QUERY DESIGN GRID for our&lt;br /&gt;&lt;b&gt;DELETE&lt;/b&gt; Query. &amp;nbsp;Notice the new row for DELETE&lt;br /&gt;containing the SQL &lt;b&gt;FROM&lt;/b&gt; and &lt;b&gt;WHERE&lt;/b&gt;&lt;br /&gt;Keywords.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click RUN from the QUERY RESULTS group. &amp;nbsp;&lt;/li&gt;&lt;li style="text-align: justify;"&gt;Click YES when prompted whether we want to delete the number of rows matching our query criteria. &amp;nbsp;This will be four rows for the dataset we have been working with.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;We can now go back and open the &lt;b&gt;tblContacts &lt;/b&gt;table. &amp;nbsp;As you can see from Figure 5 below, all &lt;b&gt;Company 5&lt;/b&gt;&amp;nbsp;contacts have been removed by our DELETE QUERY.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-S6dGLBD45Tg/TmEDFSGabQI/AAAAAAAAAfw/Cl-1aryMYDk/s1600/records-deleted.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="262" src="http://4.bp.blogspot.com/-S6dGLBD45Tg/TmEDFSGabQI/AAAAAAAAAfw/Cl-1aryMYDk/s320/records-deleted.JPG" width="320" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 5: &lt;/b&gt;The &lt;b&gt;tblContacts &lt;/b&gt;table after&amp;nbsp;&lt;b&gt;Company 5&lt;/b&gt;&lt;br /&gt;contacts&amp;nbsp;have been removed.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-978855510030521540?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TQSkuD0j8DOE3R5fmErWvA9tJuc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TQSkuD0j8DOE3R5fmErWvA9tJuc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TQSkuD0j8DOE3R5fmErWvA9tJuc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TQSkuD0j8DOE3R5fmErWvA9tJuc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/yNqrqVEhxBE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/978855510030521540/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/09/removing-multiple-records-with-delete.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/978855510030521540" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/978855510030521540" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/yNqrqVEhxBE/removing-multiple-records-with-delete.html" title="Removing Multiple Records with a Delete Query" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-I9-wT-7LBWY/Tl-yg7MI3hI/AAAAAAAAAfU/xokstDoEcD8/s72-c/contact-list.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/09/removing-multiple-records-with-delete.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-4397119509196665052</id><published>2011-08-26T11:32:00.000-07:00</published><updated>2011-08-26T11:34:36.500-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="Crosstab Query" /><title type="text">Using a Crosstab Query to Present Summary Data</title><content type="html">In this post we shall use the power of an Access &lt;i&gt;Crosstab Query&lt;/i&gt;&amp;nbsp;to summarize and restructure our data into a clear and concise format. &amp;nbsp;We shall illustrate how to do this with sales made by employees of a&amp;nbsp;Real Estate Company (who are referred to as Estate Agents in the UK).&lt;br /&gt;&lt;br /&gt;So in what way does a &lt;i&gt;Crosstab Query&lt;/i&gt; improve the presentation of summary data? &amp;nbsp;Well lets imagine our Real Estate Company asks us to summarize a list of sales made by each of its employees, for each quarter, over the period of a year. &amp;nbsp;This list has fields for &lt;b&gt;Employee&lt;/b&gt;, &lt;b&gt;Quarter &lt;/b&gt;and &lt;b&gt;SaleValue.&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ww9xblMjsAk/TldcL_P3o0I/AAAAAAAAAfE/pm8zcm1NRoQ/s1600/estate-agency-sales.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-ww9xblMjsAk/TldcL_P3o0I/AAAAAAAAAfE/pm8zcm1NRoQ/s400/estate-agency-sales.JPG" width="303" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; This is the raw data that will form &lt;br /&gt;the basis of our &lt;b&gt;Crosstab Query&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;As you can see in Figure 1 above, this raw data provides us with all the necessary information, but is difficult to digest in its present form. &amp;nbsp;What we are interested in, is the total &lt;b&gt;SalesValue&lt;/b&gt;, for each &lt;b&gt;Employee&lt;/b&gt;,&lt;b&gt;&amp;nbsp;&lt;/b&gt;for each &lt;b&gt;Quarter&lt;/b&gt;. &amp;nbsp;With the help of a &lt;i&gt;Crosstab Query&lt;/i&gt;, we can restructure this information so that each &lt;i&gt;Employee Name&lt;/i&gt; becomes a single &lt;i&gt;Row Heading&lt;/i&gt; on the left side of the table, and each &lt;i&gt;Quarter Value&lt;/i&gt; is grouped together to form &lt;i&gt;Column Heading's&lt;/i&gt; across the top of the table. &amp;nbsp;Since there are three employees, and four quarters in our data, this will give us a table with three rows and four columns. &amp;nbsp;The Sum of the Sales value then appears where each Employee Row intersects with each Quarter Column. &amp;nbsp;This is how our&amp;nbsp;Crosstab Query&amp;nbsp;will be structured:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;|&lt;b&gt;Quarter 1&lt;/b&gt;|&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Quarter 2&lt;/b&gt;|&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Quarter 3&lt;/b&gt;|&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;b&gt;Quarter 4&lt;/b&gt;|&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Employee 1&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;|&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale&lt;/i&gt;|&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Employee 2&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;|&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale&lt;/i&gt;|&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Employee 3&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;td&gt;|&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale|&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;Sum of SaleVale&lt;/i&gt;|&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;b&gt;Creating a Crosstab Query&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;So how do we create a &lt;i&gt;Crosstab Query&lt;/i&gt;?&lt;br /&gt;&lt;br /&gt;Well, there are two main ways: the first with the &lt;i&gt;Crosstab Query Wizard&lt;/i&gt;, and the second using the &lt;i&gt;Query Design Grid&lt;/i&gt;. &amp;nbsp;We are going to focus on the second method which involves creating the Crosstab Query from Scratch. &amp;nbsp;However if you do wish to use the Crosstab Query Wizard, you can select the CREATE TAB, click the QUERY WIZARD ICON from the OTHER group, highlight CROSSTAB QUERY from the list in the dialogue box, and then click OK. &amp;nbsp;When the Wizard starts, follow the instructions to select the Table/Query, the field to be used as &lt;i&gt;Row Headings&lt;/i&gt; (&lt;b&gt;SalesPerson&lt;/b&gt;), the field to be used as &lt;i&gt;Column Headings&lt;/i&gt; (&lt;b&gt;Quarter&lt;/b&gt;), and the aggregate function to be used to summarize the &lt;b&gt;SaleValue &lt;/b&gt;(&lt;i&gt;Sum&lt;/i&gt;). &lt;br /&gt;&lt;br /&gt;However, here is the method to create a &lt;i&gt;Crosstab Query&lt;/i&gt; from Scratch using the &lt;i&gt;Query Design Grid&lt;/i&gt;:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Select the CREATE TAB of the Access Ribbon.&lt;/li&gt;
&lt;li&gt;Click the QUERY DESIGN icon. &amp;nbsp;It is located in the OTHER group.&lt;/li&gt;
&lt;li&gt;Select the table or query to be used from the SHOW TABLE dialogue box. &amp;nbsp;The one I have used is called &lt;b&gt;qrySales&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Click the CROSSTAB icon. &amp;nbsp;This is located in the QUERY TYPE group of the DESIGN ribbon. &amp;nbsp;Notice how two new rows, &lt;b&gt;Crosstab &lt;/b&gt;and &lt;b&gt;Totals&lt;/b&gt;, appear in the query design grid.&lt;/li&gt;
&lt;li&gt;Drag the three field names from &lt;b&gt;qrySales &lt;/b&gt;down onto the grid.&lt;/li&gt;
&lt;li&gt;Go to the &lt;i&gt;Crosstab &lt;/i&gt;row of the &amp;nbsp;&lt;b&gt;SalesPerson &lt;/b&gt;column on the QUERY DESIGN GRID. Then select &lt;i&gt;Row Heading&lt;/i&gt; from the drop down box in that cell.&lt;/li&gt;
&lt;li&gt;Next go to the &lt;i&gt;Crosstab &lt;/i&gt;row of the &lt;b&gt;Quarter &lt;/b&gt;column. &amp;nbsp;Then select &lt;i&gt;Column Heading &lt;/i&gt;from the drop down list.&lt;/li&gt;
&lt;li&gt;As you may recall, the sum of&amp;nbsp;&lt;b&gt;SaleValue&amp;nbsp;&lt;/b&gt;is going to provide the summary data in our table. &amp;nbsp;To do this, go to the &lt;i&gt;Totals &lt;/i&gt;row of the &lt;b&gt;SaleValue &lt;/b&gt;column. &amp;nbsp;Then select &lt;i&gt;Sum &lt;/i&gt;from the drop down list. &amp;nbsp;Then&amp;nbsp;move down to the &lt;i&gt;Crosstab&lt;/i&gt;&amp;nbsp;row of the &lt;b&gt;SaleValue &lt;/b&gt;column, and then select &lt;i&gt;Value &lt;/i&gt;from the drop down list.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;The QUERY DESIGN GRID should &amp;nbsp;now look like this:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-RjYL5CSt1YY/TlfIYWEm9WI/AAAAAAAAAfI/vJ9XgIoKtu8/s1600/crosstab-query.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-RjYL5CSt1YY/TlfIYWEm9WI/AAAAAAAAAfI/vJ9XgIoKtu8/s1600/crosstab-query.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; The QUERY DESIGN GRID for our &lt;b&gt;Crosstab Query&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&amp;nbsp;When you run the Crosstab Query our results should appear like this:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--oLl2PcISlA/TlfJvK0PSMI/AAAAAAAAAfM/IpEXVL3xBOc/s1600/Crosstab-Sales-Query.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/--oLl2PcISlA/TlfJvK0PSMI/AAAAAAAAAfM/IpEXVL3xBOc/s1600/Crosstab-Sales-Query.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; Results of our &lt;b&gt;Crosstab Sales Query&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;Its worth pointing out that we can add another row heading containing a &lt;i&gt;Total&lt;/i&gt; &lt;b&gt;SalesValue &lt;/b&gt;for each &lt;b&gt;SalesPerson &lt;/b&gt;across the four quarters. &amp;nbsp;To do this just go back to the grid and add an additional column for &lt;b&gt;SalesValue&lt;/b&gt;&amp;nbsp;(you might want to give the column the alias of&amp;nbsp;&lt;b&gt;Total&lt;/b&gt;). &amp;nbsp; Then select &lt;i&gt;Row Heading &lt;/i&gt;from the &lt;i&gt;Crosstab Row &lt;/i&gt;on the grid. When run, it should look like this:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-R2inNFKlT98/TlfNI7bQfCI/AAAAAAAAAfQ/EVsgLkqZFi0/s1600/Crosstab-with-Totals.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-R2inNFKlT98/TlfNI7bQfCI/AAAAAAAAAfQ/EVsgLkqZFi0/s1600/Crosstab-with-Totals.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 4: Crosstab Query&lt;/b&gt; with additional Row Heading comprised of the row &lt;b&gt;Total&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-4397119509196665052?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lZp0l-vVr9B830wZmggm069DxaI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lZp0l-vVr9B830wZmggm069DxaI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lZp0l-vVr9B830wZmggm069DxaI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lZp0l-vVr9B830wZmggm069DxaI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/NBAGcvEMf_Y" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/4397119509196665052/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/08/using-crosstab-query-to-present-summary.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/4397119509196665052" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/4397119509196665052" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/NBAGcvEMf_Y/using-crosstab-query-to-present-summary.html" title="Using a Crosstab Query to Present Summary Data" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-ww9xblMjsAk/TldcL_P3o0I/AAAAAAAAAfE/pm8zcm1NRoQ/s72-c/estate-agency-sales.JPG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/08/using-crosstab-query-to-present-summary.html</feedburner:origLink></entry><entry><id>tag:blogger.com,1999:blog-777975398841809391.post-642783923764707973</id><published>2011-08-19T05:46:00.000-07:00</published><updated>2011-10-23T02:19:48.970-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="IIf" /><category scheme="http://www.blogger.com/atom/ns#" term="query" /><category scheme="http://www.blogger.com/atom/ns#" term="functions" /><title type="text">Handling the Conditional: Using the IIf Function</title><content type="html">&lt;div style="text-align: justify;"&gt;Let's imagine we have an Access table containing a list of academic exam results. &amp;nbsp;There is a field for &lt;b&gt;Subject &lt;/b&gt;and a field for the percentage &lt;b&gt;Result &lt;/b&gt;, but we do not have one telling us whether each percentage result is deemed a &lt;i&gt;Pass &lt;/i&gt;or &lt;i&gt;Fail&lt;/i&gt;. &amp;nbsp;So what is the best way to 'store' this missing information?&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-d-8ZQUkDU8c/Tk4igWNn-_I/AAAAAAAAAe4/JJRO4p18pRM/s1600/ExamResultsTable.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-d-8ZQUkDU8c/Tk4igWNn-_I/AAAAAAAAAe4/JJRO4p18pRM/s1600/ExamResultsTable.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt; An Access Table containing&lt;br /&gt;&lt;b&gt;Subject &lt;/b&gt;and &lt;b&gt;Result &lt;/b&gt;fields.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;We might be tempted create such a Pass/Fail field, but this is generally considered bad database design practice: since it is possible to calculate whether the student passed or failed on the basis of the percentage result,&amp;nbsp;we would be storing redundant data. &amp;nbsp;Creating a &lt;i&gt;Query &lt;/i&gt;would be a much better option. &amp;nbsp;However, we need to display whether the result is a Pass &lt;i&gt;or&lt;/i&gt; a Fail, so simply entering a criteria to filter out all results above or below a certain percentage is not going to do the job: this would only provide us with a list of Passes or a separate list of Fails. &amp;nbsp;We just want one column stating&amp;nbsp;&lt;b&gt;Pass &lt;/b&gt;or &lt;b&gt;Fail&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;A great way of doing this task would be to use the &lt;b&gt;IIf &lt;/b&gt;function as a new calculated column within the Query. &amp;nbsp;This will enable us to display a value indicating whether the exam has been &lt;i&gt;passed &lt;/i&gt;or &lt;i&gt;failed&lt;/i&gt;. &amp;nbsp;The &lt;b&gt;IIf&lt;/b&gt;&amp;nbsp;function allows us to specify a &lt;i&gt;conditional &lt;/i&gt;expression (in a similar way to a query criteria), but then to go on and specify a value to be displayed based on whether the result of the expression happens to be true or false. &amp;nbsp;In our case we want the expression to determine whether the value contained in a percentage result field is, say, &amp;nbsp;greater than 50%, and if it is, display "PASS", or else display "FAIL".&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;The &lt;b&gt;IIf &lt;/b&gt;function is constructed as follows:&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif; font-size: large;"&gt;IIf(Conditional Expression,  True_Condition, False_Condition)&lt;/span&gt;&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The first parameter we pass for this function is the conditional expression. &amp;nbsp;In our case this would be &lt;b&gt;Result &amp;gt; 50&lt;/b&gt;. &amp;nbsp;The Second parameter we pass is the string value which appears if the condition is true (for us this would be "&lt;b&gt;PASS&lt;/b&gt;"); and the third parameter is the string value which appears if the condition is false (for us this would be "&lt;b&gt;FAIL&lt;/b&gt;"). &amp;nbsp;As such we would construct our own particular &lt;b&gt;IIf&lt;/b&gt; function like this:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #20124d; font-family: Times, 'Times New Roman', serif; font-size: large;"&gt;IIf([Result] &amp;gt; 50,  "Pass", "Fail")&lt;/span&gt;&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;We shall enter the this expression into our query as follows:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-j-ufgOE06bs/Tk4kKUyEwoI/AAAAAAAAAe8/BNw0Fa8AIcY/s1600/iif-function-query.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-j-ufgOE06bs/Tk4kKUyEwoI/AAAAAAAAAe8/BNw0Fa8AIcY/s1600/iif-function-query.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt; The &lt;b&gt;IIf &lt;/b&gt;Function has been entered into the third column using the alias &lt;b&gt;Pass&lt;/b&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As you can see we have entered our &lt;b&gt;IIf &lt;/b&gt;function in the last column on the right. &amp;nbsp;We have used the alias "Pass" to describe the data to be displayed in this column. &amp;nbsp;(For more information about alias's and using functions in Access Queries, please see &lt;a href="http://ms-access-tips.blogspot.com/2011/08/calculating-date-difference-using.html"&gt;this explanation in relation to the DateDiff Function&lt;/a&gt;). &amp;nbsp;Just remember to separate the alias name from the function with a colon as shown in &lt;i&gt;Figure 2&lt;/i&gt; above.&lt;br /&gt;&lt;br /&gt;Now lets run the query and see what we get:&lt;br /&gt;&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Y087SU7cEBg/Tk5P1GEypbI/AAAAAAAAAfA/yPfLHcxIF2g/s1600/exam-results-query.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-Y087SU7cEBg/Tk5P1GEypbI/AAAAAAAAAfA/yPfLHcxIF2g/s1600/exam-results-query.JPG" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt; the results of our query to calculate whether&lt;br /&gt;a student has passed or failed an exam.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;As you can see, the &lt;b&gt;IIf &lt;/b&gt;function has correctly assigned a &lt;i&gt;Pass &lt;/i&gt;or &lt;i&gt;Fail &lt;/i&gt;based on the percentage &lt;b&gt;Result &lt;/b&gt;attained.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/777975398841809391-642783923764707973?l=ms-access-tips.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zkVmMWkBXb5wlgptbvhSL0LQ8Ac/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zkVmMWkBXb5wlgptbvhSL0LQ8Ac/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zkVmMWkBXb5wlgptbvhSL0LQ8Ac/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zkVmMWkBXb5wlgptbvhSL0LQ8Ac/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MicrosoftAccessTips/~4/AEfXjTlmIUQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://ms-access-tips.blogspot.com/feeds/642783923764707973/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://ms-access-tips.blogspot.com/2011/08/handling-conditional-using-iif-function.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/642783923764707973" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/777975398841809391/posts/default/642783923764707973" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MicrosoftAccessTips/~3/AEfXjTlmIUQ/handling-conditional-using-iif-function.html" title="Handling the Conditional: Using the IIf Function" /><author><name>justin-farrell</name><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_fkXFuzTmNBE/SVpY9fQNrhI/AAAAAAAAAC8/3xUt0tQKhkY/S220/DSCF0120.JPG" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-d-8ZQUkDU8c/Tk4igWNn-_I/AAAAAAAAAe4/JJRO4p18pRM/s72-c/ExamResultsTable.JPG" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://ms-access-tips.blogspot.com/2011/08/handling-conditional-using-iif-function.html</feedburner:origLink></entry></feed>

