<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LEARN MS-ACCESS TIPS AND TRICKS</title>
	<atom:link href="http://msaccesstips.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://msaccesstips.com</link>
	<description>Free MS-Access downloads</description>
	<lastBuildDate>Tue, 31 Jan 2012 13:08:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to Use Form Filter on Report</title>
		<link>http://msaccesstips.com/2012/01/how-to-use-form-filter-on-report/</link>
		<comments>http://msaccesstips.com/2012/01/how-to-use-form-filter-on-report/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 13:08:24 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Reports]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/?p=2245</guid>
		<description><![CDATA[Normally we use a Query or processed data table as Report Source for printing selected data items, like Customer Invoices or Customer Ledger Statement etc. How do we take a print out of the current record on the Form? Let us try this simple method to start with, before using the Form Filter on Report.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Normally we use a <a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Query</a> or processed data table as <a href="http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/">Report</a> Source for printing selected data items, like Customer Invoices or Customer Ledger Statement etc.</p>
<p>How do we take a print out of the current record on the Form?</p>
<p>Let us try this simple method to start with, before using the <a href="http://msaccesstips.com/2011/10/updating-sub-form-recordset-from-main-form/">Form</a> Filter on Report.&#160; We need some sample data, a Form and a Report to try this out.</p>
<ol>
<li>Import the <strong>Order details</strong> and <strong>Products</strong> Tables from the Northwind.accdb sample database. </li>
<li>Use the <a href="http://www.msaccesstips.com/2008/12/custom-report-wizard/">Report Wizard</a> and design a Report using the <strong>Order Details</strong> Table as Record Source (sample report view is given below) and save the Report with the name <strong>Rpt_OrderDetails</strong>. <!-- Uploaded_images-->
<p><a href="http://www.msaccesstips.com/uploaded_images/filter-report.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Report Preview" border="0" alt="Report Preview" src="http://www.msaccesstips.com/uploaded_images/filter-report_thumb.jpg" width="403" height="235" /></a></p>
<p> <!-- Uploaded_images--></li>
<li>Use the <a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard/">Form Wizard</a> and design a multiple items (continuous) Form using the <strong>Order Details</strong> Table (sample data view image is given below) and save it with the name Frm_OrderDetails. <!-- Uploaded_images-->
<p><a href="http://www.msaccesstips.com/uploaded_images/filter-form.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Filter Form View" border="0" alt="Filter Form View" src="http://www.msaccesstips.com/uploaded_images/filter-form_thumb.jpg" width="366" height="253" /></a></p>
<p> <!-- Uploaded_images--></li>
<li>Open the Form Frm_OrderDetails in design view. </li>
<li>Select the Command Button Tool from the <strong>Toolbox</strong> and draw a Command Button on the Header Section of the Form. </li>
<li>While the Command Button is still in selected state display the Property Sheet (<strong>Design</strong> &#8211; - &gt;<strong>Tools</strong> &#8211; - &gt; <strong>Property Sheet</strong> or use <strong>F4</strong>) and select <strong>All </strong>Tab on the <a href="http://www.msaccesstips.com/2009/11/creating-using-form-custom-property/">Property</a> Sheet. </li>
<li>Change the <strong>Name</strong> Property Value to <strong>cmdRpt</strong> and change the <strong>Caption</strong> Property Value to <strong>Run Report </strong>(see the Form image above). </li>
<li>Select the <strong>Event</strong> Tab of the Property Sheet. </li>
<li>Select <strong>[Event Procedure] </strong>from the drop-down list of the <strong>On Click</strong> event property and&#160; click on the Build (<strong>. . .</strong>) button at the right edge of the property to open the VBA window with the skeleton of the <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> Click Event Procedure. </li>
<li>Copy and paste the middle line of Code between the existing header and footer lines of the <a title="Double Action Command Button" href="http://www.msaccesstips.com/2008/03/double-action-command-button/" target="_blank">Command Button</a> Click event procedure:
<pre class="alt2">


Private Sub cmdRpt_Click()

   DoCmd.OpenReport &quot;Rpt_OrderDetails&quot;, acViewPreview, , &quot;[order id] = &quot; &amp; Me![order id]

End Sub
</pre>
<p>Check the middle line of the above code. The last parameter to the DoCmd.OpenReport command is a <a title="Find or Filter Data on Form" href="http://www.msaccesstips.com/2007/12/find-or-filter-data-on-form/" target="_blank">Filter</a> condition to select the current record’s <strong>Order ID</strong> number to filter all records with the same Order ID number. We have inserted one extra comma between the printing option and the filter condition to skip the choice of using the name of a <a href="http://www.msaccesstips.com/2008/03/filtering-data-for-different-users/" target="_blank">Query</a> as Report Source Data.</p>
<p>The filter condition <strong>&quot;[Order Id] = &quot; &amp; Me![Order Id]</strong> states that take all the records with the current record <strong>Order ID</strong> Number as source data for the Report.</p>
</p>
</li>
<li>Save the form <strong>Frm_OrderDetails</strong> and open it in normal view </li>
<li>Click on any record with the same <strong>Order ID</strong> in more than one record or any record you like. </li>
<li>Click on the <strong>Run Report</strong> <a href="http://www.msaccesstips.com/2009/01/command-button-animation-2/" target="_blank">Command Button</a> to open the <strong>Rpt_OrderDetails</strong> with the selected record. </li>
<li>Close the Report and you may try it again after selecting some other record on the Form. </li>
</ol>
<p>The above example uses only a single record or several records with the same Order ID to print on the Report.&#160; </p>
<p>Next, we will do it with more flexibility after setting the <strong>Filter</strong> Property Value of the Form. This can be done after selecting one or more Order IDs for filtering the data on the <a href="http://www.msaccesstips.com/2009/01/drill-down-inquiry-screen-2/" target="_blank">Form</a>, before we open the <a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3/" target="_blank">Report</a> for printing the data on the Form.&#160; We must set a reference to the <strong>Filter</strong> Property of the Form replacing the criteria setting we have used earlier: <strong>&quot;[order id] = &quot; &amp; Me![order id], </strong>on the <strong>DoCmd.OpenReport</strong> command.<strong>&#160;</strong>&#160;</p>
<p>With this change the user can filter data based on any column value on the Form (like <strong>Order Id</strong> or <strong>Quantity</strong> or <strong>UnitPrice</strong> etc.) and use the result set to print the Report.</p>
<ol>
<li>Make a copy of the form <strong>Frm_OrderDetails </strong>and paste it with the name <strong>Frm_Orderdetails2</strong>. </li>
<li>Open the form <strong>Frm_Orderdetails2 </strong>in design view. </li>
<li>Click on the Command Button to select and display it’s property sheet (F4). </li>
<li>Select&#160; the <strong>Event</strong> Tab and select the <strong>On Click</strong> property. </li>
<li>Click on the Build (. . .) button to open the VBA window. </li>
<li>Copy the following Code and paste replacing the existing lines of code on the Form Module:
<pre class="alt2">Private Sub cmdRpt_Click()
    If Me.Filter = &quot;&quot; Then
        MsgBox &quot;Apply a filter to the Form first.&quot;
    Else
        DoCmd.OpenReport &quot;Rpt_OrderDetails&quot;, acViewPreview, , Me.Filter
    End If
End Sub</pre>
</li>
<li>Check the last parameter setting in the DoCmd.OpenReport statement. We are asking the Report to use whatever criteria setting is available in the current Form’s (<strong>Me</strong>) <strong>Filter </strong>Property Value (like <strong>([Order Details].[Order ID] In (30,31,32))</strong>) to pick records for the Report<strong>. </strong>Save the Form and open it in normal view. </li>
<li>Click on the Command Button to open the <a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3/" target="_blank">Report</a>.
<p>You will be greeted with a message asking to &#8216;<em>Apply a filter to the Form first</em>&#8216;. When you click on the <a href="http://www.msaccesstips.com/2006/09/command-button-animation/" target="_blank">Command Button</a> the program checks whether the Form&#8217;s <strong>Filter</strong> Property is set with a Filter condition or not, like the text we have used in the first example above, or like the sample shown in <strong>Step-7</strong> above.</p>
<p><strong>Note:</strong> Remember, once you apply a filter on the form the text of the last filter condition remains saved on the Filter Property.&#160; The Filter action is supported with another property value setting: <strong>FilterOn</strong> <strong>= True/False</strong>. When you <strong>Toggle</strong> the filter action on the Form the <strong>FilterOn </strong>property value changes but the Filter property value criteria text is not removed. You will be greeted with the above message only when the <strong>Filter</strong> Property Value is empty.</p>
</li>
<li>Click on the <strong>Order ID</strong> column on any record. </li>
<li>Click on the Filter Toolbar button (see the image below)to display the Filter selection control. <!-- Uploaded_images-->
<p><a href="http://www.msaccesstips.com/uploaded_images/filter-button-click.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Filter Button Action" border="0" alt="Filter Button Action" src="http://www.msaccesstips.com/uploaded_images/filter-button-click_thumb.jpg" width="367" height="267" /></a></p>
<p><!-- Uploaded_images--></p>
<p>A list of the selected field values (Order ID numbers) are displayed and shows all the values are check marked, indicating that all the values are in selected state.</p>
</li>
<li>Click on the <strong>Select All </strong>Option to de-select all the items. </li>
<li>Now, put check marks on the Order ID Numbers 30, 31 &amp; 32 and Click <strong>OK </strong>to close the Filter Control.
<p>The form now shows only records of Order ID numbers 30, 31 &amp; 32.</p>
</li>
<li>Click on the <strong>Run Report</strong> Command Button on the Header of the Form to open the Report in Print Preview with the records filtered on the Form. </li>
<li>Close the Report. </li>
<li>Place the cursor on the <strong>Quantity</strong> Field on any record on the Form. </li>
<li>Click on the <strong>Filter</strong> Toolbar Button to display the Filter Control. </li>
<li>Select the items with the Quantity values <strong>100,200 &amp; 300</strong> and click <strong>OK</strong> button to close the control and filter the records you have selected. </li>
<li>Open the Report by clicking on the Run Report Command Button and check the report contents. </li>
<li>Close the Report. </li>
<li>Click on the <strong>Toggle Filter </strong>Toolbar button<strong>.&#160; </strong>The Filter action is reversed and all the records are back on the Form (or the <strong>FilterOn </strong>Property Value is set as <strong>False </strong>now). </li>
<li>Now, Click on the <strong>Run Report </strong>Command Button to preview the Report.&#160; </li>
</ol>
<p>The <a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals/" target="_blank">Report</a> shows the last filtered records only, rather than all the records from the Form.&#160; When we toggle the filter Microsoft Access sets the <strong>FilterOn </strong>Property Value to <strong>False</strong> nullifying the effect of the filter action on the form, without removing the filter condition string inserted in the <strong>Filter </strong>Property, because the User may click the <strong>Toggle Filter</strong> button again to bring back data filtered by the last set filter condition. Our program keep using it because the Filter Property value is not empty and we are not checking the status of the <strong>FilterOn </strong>Property setting.</p>
<p>But, we can solve this issue with few changes in our program as follows:</p>
<pre class="alt3">

Private Sub cmdRpt_Click()
    If Me.FilterOn Then
        DoCmd.OpenReport &quot;Rpt_OrderDetails&quot;, acViewPreview, , Me.Filter
    Else
        DoCmd.OpenReport &quot;Rpt_OrderDetails&quot;, acViewPreview
    End If
End Sub
</pre>
<p>Change the program as shown above and try the effect of the Filter and Toggle Filter action on the Form as well as on the <a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report/" target="_blank">Report</a>.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6fe31042-1830-48b8-a5df-67648a231bab" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Reports" rel="tag">Reports</a>,<a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/08/apply-filter-to-table-directly/">Apply Filter to Table directly</a> </li>
<li><a href="http://msaccesstips.com/2011/07/dynamic-dlookup-in-query-column/">Dynamic Lookup in Query Column</a> </li>
<li><a href="http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/">Creating Water-mark on Ms-Access Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/07/iseries-date-in-exported-data/">iSeries Date in exported Data</a> </li>
<li><a href="http://msaccesstips.com/2011/06/change-query-top-values-property-with-vba/">Change Query Top Values property with VBA</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2012/01/how-to-use-form-filter-on-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving Report Pages as separate PDF Files</title>
		<link>http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/</link>
		<comments>http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 06:47:05 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/?p=2242</guid>
		<description><![CDATA[You are printing several Customer Invoices as a single Report, running into several pages.&#160; You have problems with this kind of Reports in segregating the Invoices and physically mailing them to the customers.&#160; If all Invoices can be saved on disk in separate PDF Files then it is easy to send them through emails to [...]]]></description>
			<content:encoded><![CDATA[<p>You are printing several Customer Invoices as a single Report, running into several pages.&#160; You have problems with this kind of <a href="http://msaccesstips.com/2011/05/continued-on-page-2-on-report/">Reports</a> in segregating the Invoices and physically mailing them to the customers.&#160; </p>
<p>If all Invoices can be saved on disk in separate PDF Files then it is easy to send them through emails to the customers.&#160; This will not only save the cost of stationery but also delivers the invoices to the customers’ mailbox instantly without delay.&#160; Besides that customers can easily view the Invoices on their machines or take printouts at their end, if that become necessary.&#160; In short, part of our tasks are passed on to the customers, saving our time and money.&#160; I don’t think I can stretch it any more.</p>
<p>Let us try this with one or two Tables from the Northwind.mdb sample database.</p>
<ol>
<li>Import the following Tables from the Northwind.mdb (or Access2007 Northwind.accdb) sample <a href="http://www.msaccesstips.com/2008/08/database-connection-string-properties/">database</a>:
<ul>
<li>Order Details </li>
<li>Products&#160; </li>
</ul>
<p>NB: I will be using Tables from the Northwind.mdb database. But, the queries, Report and Code will be running under Access2007. The <strong>Products</strong> Table is not used directly in our <a href="http://www.msaccesstips.com/2010/01/auto-numbering-in-query-column/">Query</a> or Report but the ProductID <a href="http://www.msaccesstips.com/2009/01/combo-box-column-values/">combobox</a> in the <strong>Order Details</strong> table references this table for product description.</p>
</li>
<li>Open a new <a href="http://www.msaccesstips.com/2009/12/filter-with-buildcriteria-function/">Query</a> in SQL View without selecting any Table/Query from the displayed list. </li>
<li>Copy and Paste the following SQL string into the new Query’s SQL editing window and save the Query with the name <strong>Invoice_Orders_0:</strong>
<pre class="alt3">SELECT [Order Details].OrderID,
 [Order Details].ProductID,
 [Order Details].Quantity,
 [Order Details].UnitPrice,
 [Order Details].Discount,
 [Quantity]*((1-[Discount])*[UnitPrice]) AS TotalValue
FROM [Order Details];</pre>
</li>
<li>After saving and closing the above Query create another Query, using <strong>Invoice_Orders_0</strong> as source, with the following SQL:
<pre class="alt2">SELECT Invoice_Orders_0.*
FROM Invoice_Orders_0
WHERE (((Invoice_Orders_0.OrderID)=10258));</pre>
</li>
<li>Save the new Query with the name <strong>Invoice_Orders_1</strong>. </li>
<li>Design a Report to print Sales Invoice using <strong>Invoice_Orders_1</strong> Query as Record Source.
<p>Sample Report Design Image is given below:</p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/invoice-design.jpg"><img style="display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Invoice Design View" border="0" alt="Invoice Design View" src="http://www.msaccesstips.com/uploaded_images/invoice-design_thumb.jpg" width="394" height="251" /></a></p>
<p><!-- Uploaded_images--></p>
<p>Sample Report Preview Image is the next one:</p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/invoice-preview.jpg"><img style="display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Invoice Preview" border="0" alt="Invoice Preview" src="http://www.msaccesstips.com/uploaded_images/invoice-preview_thumb.jpg" width="461" height="249" /></a></p>
<p><!-- Uploaded_images--></li>
<li>Copy and paste the following <a href="http://www.msaccesstips.com/2008/06/repairing-compacting-database-with-vba/">VBA</a> Code into a Standard <a href="http://msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/">Module</a> and save it:<!--INFOLINKS_OFF-->
<pre>Public Function Create_PDF(ByVal OrderStart As Integer, ByVal OrderEnd As Integer, ByVal strPath As String)
'--------------------------------------------------------------------------------
'Author : a.p.r. pillai
'Date   : January 2012
'Rights : All Rights(c) Reserved by www.msaccesstips.com
'--------------------------------------------------------------------------------
'Function Parameters:
' 1. - OrderID Start Number
' 2. - OrderID End Number
' 3. - Target Folder Address, sample: C:\My Documents
'--------------------------------------------------------------------------------
Dim strsql_1 As String, strsql As String, criteria As String
Dim db As Database, rst As Recordset, QryDef As QueryDef
Dim int_Order As Integer, outFile As String, T As Date
Dim SQLParam As String, i As Integer, msg As String

'Invoice Query Definition, Order Number must be added at the end as criteria
strsql_1 = &quot;SELECT Invoice_Orders_0.*  FROM Invoice_Orders_0 &quot;
strsql_1 = strsql_1 &amp; &quot; WHERE (((Invoice_Orders_0.OrderID)=&quot;

'Query definition for Order Numbers between OrderStart and OrderEnd numbers
SQLParam = &quot;SELECT DISTINCT [Order Details].OrderID FROM [Order Details] &quot;
SQLParam = SQLParam &amp; &quot;WHERE ((([Order Details].OrderID) Between &quot; &amp; <strong>OrderStart</strong> &amp; &quot; And &quot; &amp; <strong>OrderEnd</strong> &amp; &quot;)) &quot;
SQLParam = SQLParam &amp; &quot; ORDER BY [Order Details].OrderID;&quot;

Set db = CurrentDb
'open the OrderIDs parameter list to process one by one
Set rst = db.OpenRecordset(SQLParam, dbOpenDynaset)
'open the Report Query definition to incorporate OrderID criteria
Set QryDef = db.QueryDefs(&quot;Invoice_Orders_1&quot;)

i = 0 'take a count of invoices printed
Do While Not rst.EOF 'cycle through the parameter list
  'get the order number
  int_Order = Nz(rst!OrderID, 0)
  If int_Order &gt; 0 Then 'if any blank record ignore
     i = i + 1
     'create the criteria part for the Invoice Query
     criteria = int_Order &amp; &quot;));&quot;
     'complete the Invoice SQL by adding the criteria.
     strsql = strsql_1 &amp; criteria
     'Redefine the Invoice Query to print the Invoice
     QryDef.sql = strsql
     db.QueryDefs.Refresh

     'PDF file's target path and Order Number is the file name.
     outFile = strPath &amp; &quot;\&quot; &amp; int_Order &amp; &quot;.PDF&quot;

     'Save the report as pdf file.
     DoCmd.OutputTo acOutputReport, &quot;Rpt_Invoice&quot;, &quot;PDFFormat(*.pdf)&quot;, outFile, False, &quot;&quot;, 0, acExportQualityPrint

  '2 seconds delay loop to give enough time for Access to create the file on disk.
  T = Timer
  Do While Timer &lt; T + 2
    DoEvents
  Loop
 End If
  rst.MoveNext
Loop
rst.Close

msg = &quot;Order Start Number: &quot; &amp; OrderStart &amp; vbCr &amp; vbCr
msg = msg &amp; &quot;Order End Number: &quot; &amp; OrderEnd &amp; vbCr &amp; vbCr
msg = msg &amp; &quot;Invoices Printed: &quot; &amp; i &amp; vbCr &amp; vbCr
msg = msg &amp; &quot;Target Folder: &quot; &amp; strPath

MsgBox msg, , &quot;Create_PDF()&quot;

Set rst = Nothing
Set db = Nothing
Set QryDef = Nothing

End Function</pre>
</li>
</ol>
<p><!--INFOLINKS_ON--></p>
<p>Now, let us take a look at what preparations we have made so far:</p>
<p>The first Query (<strong>Invoice_Orders_0</strong>) selects the required fields from <strong>Order Details</strong> Table for the Customer Invoice Report. Besides that it calculates the <strong>Total Value</strong> after Discount of each record in the Query. But, in this Query we have not set any criteria to select any specific <strong>OrderID</strong>&#160; or Range of OrderIDs for printing the Invoices. </p>
<p>We are setting criteria to select specific OrderID in the second Query (<strong>Invoice_Orders_1</strong>),&#160; created using the earlier Query (<strong>Invoice_Orders_0</strong>) as Source. The two step query simplifies the SQL and we must take the SQL into the VBA Code to redefine the Query, with changing OrderIDs, so that each OrderId level Invoice is saved in separate PDF file on Disk.&#160; </p>
<p>We have one more Query (the third Query saved in SQLParam String Variable is used directly in the <font class="colrgreen">Set rst = db.OpenRecordset(SQLParam, dbOpenDynaset)</font> statement) that is totally confined into the <strong>Create_PDF()</strong> Function.&#160; When the Create_PDF() Function is called you must give the <strong>Order Start Number,</strong>&#160;<strong>Order End Number</strong> and <strong>Target Folder Address</strong>, where the PDF Files are to be saved, as function parameters. The third Query extracts all the Order Numbers within the Start Number and End Number range.&#160; These will be taken one by one to print Invoices in individual files.</p>
<p><em><strong>NB</strong>:&#160; To make this sample exercise simple we are using only the transaction file to print the Invoices.&#160; As you can see from the Report specimen shown above it doesn’t have any Customer Address printed on it.&#160; If this is required then we must consider setting relationships with the Customer Address Table in the Report Query and include the address fields also. The main idea behind this whole exercise is to save the report of individual Invoices in separate pdf files, rather than going into its’ details or refinement. </em></p>
<p>Keeping that in focus let us continue to review what we are doing in the <a href="http://www.msaccesstips.com/2008/06/working-with-chart-object-in-vba/">VBA</a> Code lines.&#160; You must call the Function using the following</p>
<p>Syntax:</p>
<p><font class="colrgreen">Create_PDF&#160; StartNumber,&#160; EndNumber, ”PDF Files Target Folder”)</font></p>
<p>Example-1:</p>
<pre class="alt1">

Create_PDF 10248,10265,”C:\My Documents”

&#160;

Example-2:

&#160;

x = Create_PDF(10248,10265,”C:\My Documents”)

&#160;
</pre>
<p>You may call the function from a <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> Click Event Procedure, after setting the Parameter values in <a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins/">Text Boxes</a> on the <a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars/">Form</a></p>
<pre class="alt1">

Example-3:

Create_PDF Me![txtSNumber], Me![txtENumber], Me![txtPathName]</pre>
<p>With the <strong>Start Number</strong> and <strong>End Number </strong>values the Parameter Query is redefined to extract all the Order Numbers between those two numbers from the Order Details Table so that they can be used for extracting Order-wise items for printing individual Invoices.&#160; The SELECT DISTINCT clause suppresses duplicates from the parameter list.</p>
<p>The data source of <strong>Rpt_Invoice </strong>Report is <strong>Invoice_Orders_1 </strong>Query<strong>. </strong>This<strong> </strong>is redefined for each <strong>OrderId</strong> as criteria for printing the <strong>Rpt_Invoice</strong> in PDF format.&#160; The PDF files are saved in the location specified as third parameter <strong>C:\My Documents.</strong></p>
<p>Each line in the <a href="http://www.msaccesstips.com/2008/09/link-external-tables-with-vba/">VBA</a> Code is commented to indicate what it does in each step, please go through them to understand the code better.</p>
<p>Key Words:<a ref="http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/#">PDF Files, </a><a ref="http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/#">Invoice, </a><a ref="http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/#">Report, </a><a ref="http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/#">Access2007</a> </p>
<ul>
<li><a href="http://msaccesstips.com/2011/07/dynamic-dlookup-in-query-column/">Dynamic Lookup in Query Column</a> </li>
<li><a href="http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/">Creating Water-mark on Ms-Access Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/07/iseries-date-in-exported-data/">iSeries Date in exported Data</a> </li>
<li><a href="http://msaccesstips.com/2011/06/change-query-top-values-property-with-vba/">Change Query Top Values property with VBA</a> </li>
<li><a href="http://msaccesstips.com/2011/06/creating-animated-command-button-with-vba/">Creating Animated Command Buttons</a>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1b4dd8b8-1383-4f91-973a-4372c9f102bd" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Utility" rel="tag">Utility</a></div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2012/01/saving-report-pages-as-separate-pdf-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoNumber with Date and Sequence Number</title>
		<link>http://msaccesstips.com/2012/01/autonumber-with-date-and-sequence-number/</link>
		<comments>http://msaccesstips.com/2012/01/autonumber-with-date-and-sequence-number/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 13:16:22 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Auto-Number]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/?p=2238</guid>
		<description><![CDATA[We always make use the Autonumber feature in tables to create a unique ID field for the table. It is easy to define and always starts the auto-number with 1 and increments by 1 for each record, unless you set the New Values property to Random rather than the default value Increment. What is the [...]]]></description>
			<content:encoded><![CDATA[<p>We always make use the <a href="http://www.msaccesstips.com/2010/01/auto-numbering-in-query-column/">Autonumber</a> feature in tables to create a unique ID field for the table. It is easy to define and always starts the auto-number with 1 and increments by 1 for each record, unless you set the <strong>New Values</strong> property to <strong>Random</strong> rather than the default value <strong>Increment.</strong></p>
<p>What is the solution if we need different sequence numbers for the records that we create on each day?</p>
<p>For example, assume we are working on a Hospital Project and patients getting registered in the hospital on a particular day should have a unique <strong>Registration Card Number</strong> consisting of current date and a three digit sequence number in the format: yyyymmdd000. The sequence number must reset to 001 when the date changes.</p>
<p>If the Hospital maintains history records of the patients in physical files, organized by Date, Month and Year-wise order it is easy for them to locate any file with the Registraion Card Number.</p>
<p>We can generate this number automatically with a Function.&#160; Let us try it with a sample Table and <a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents/">Form</a>.</p>
<p>Before that copy and paste the following Function Code into a Standard VBA Module and save it:</p>
<p> <!--INFOLINKS_OFF-->
<pre>Public Function Autonum(ByVal strField As String, ByVal strTable As String) As String
Dim dmval As String, dt1 As String, dt2 As String, Seq As Integer, dv As String

'get the highest existing value from the table
dmval = Nz(DMax(strField, strTable), 0)

'if returned value is 0 then the table is new and empty
'create autonumber with current date and sequence 001
If Val(dmval) = 0 Then
   dv = Format(Now(), &quot;yyyymmdd&quot;) * 1000 + 1
   Autonum = dv
   Exit Function
End If

'format the number as an 11 digit number
dv = Format(dmval, &quot;00000000000&quot;)
'take the 3 digit sequence number separately
Seq = Val(Right(dv, 3))
'take the date value separately
dt1 = Left(dv, 8)
'get today's date
dt2 = Format(Now(), &quot;yyyymmdd&quot;)
'compare the latest date taken from the table
'with today's date
If dt1 = dt2 Then 'if both dates are same
   Seq = Seq + 1 'increment the sequence number
   'add the sequence number to the date and return
   Autonum = Format(Val(dt1) * 1000 + Seq)
   Exit Function
Else 'the dates are different
   'take today's date and start the sequence with 1
   Autonum = Format(Val(dt2) * 1000 + 1)
End If

End Function</pre>
<p><!--INFOLINKS_ON--></p>
<ol>
<li>Create a sample Table with the following Structure, as shown in the image given below:
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/autonum-struct.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Sample Table Structure" border="0" alt="Sample Table Structure" src="http://www.msaccesstips.com/uploaded_images/autonum-struct_thumb.jpg" width="239" height="218" /></a></p>
<p><!-- Uploaded_images--></p>
</li>
<li>The <strong>CardNo</strong> Field is a text type with 11 characters in length.&#160; Both second and third fields are also text fields with sizes 10 and 50 characters respectively. </li>
<li>Save the Table with the name <strong>Patients</strong>. </li>
<li>Use the <a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard/">Form Wizard</a> to design a <a href="http://www.msaccesstips.com/2008/11/event-trapping-summary-on-datasheet/">Datasheet Form</a> for the Patients Table and name the Form as <strong>frm_Patients</strong>. </li>
<li>Open the Form in Design View. </li>
<li>Click on the <strong>CardNo </strong>Field to select it. </li>
<li>Display the Property Sheet (<strong>F4</strong>). If you are using Access2007 then you can select CardNo from the Selection Type drop-down list. </li>
<li>Select the <strong>Data</strong> Tab and set the following <a href="http://www.msaccesstips.com/2008/09/source-connect-str-property-and-odbc/">Property</a> Values as shown below:
<ul>
<li>Enabled = Yes </li>
<li>Locked = Yes </li>
</ul>
</li>
<li>Access2007 users select <strong>Form</strong> from the <strong>Selection Type</strong> drop-down control<strong>.</strong> Earlier version users click on the top left corer of the Form (in the intersection where a black rectangle is shown) to ensure that the <a href="http://www.msaccesstips.com/2009/11/creating-using-form-custom-property/">Property Sheet</a> belongs to the Form and not of any other control on the Form. </li>
<li>Select the <strong>Event </strong>Tab on the Property Sheet. </li>
<li>Select the <strong>Before Insert</strong>&#160; event property and select <strong>Event Procedure</strong> from the drop-down list. </li>
<li>Click on the Build (. . .) button to open the VBA Module of the Form. </li>
<li>Copy the middle line of the following procedure and paste it in the middle of the empty <strong>Form_BeforeInsert()</strong> lines of Code in the Form <a href="http://msaccesstips.com/2011/11/vba-module-object-and-methods/">module</a>. <!--INFOLINKS_OFF-->
<pre class="alt1">Private Sub Form_BeforeInsert(Cancel As Integer)
  Me![CARDNO] = Autonum(&quot;CardNo&quot;, &quot;Patients&quot;)
End Sub</pre>
<p><!--INFOLINKS_ON--></li>
<li>Save the Form <strong>frm_Patients </strong>with the changes made. </li>
<li>Open the form in normal view and type <strong>Mr.</strong> in the <strong>Title</strong> Field and type some name in the <strong>Patient Name</strong> field.&#160; You can see that the first field is filled with current date in yyyymmdd format and the sequence number <strong>001</strong> as suffix. </li>
<li>Type few more records.&#160; Since, we have locked the <strong>CardNo </strong>field Users cannot edit this field’s contents. Sample image is given below: </li>
</ol>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/autonum-in-action.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Autonum Data Entry" border="0" alt="Autonum Data Entry" src="http://www.msaccesstips.com/uploaded_images/autonum-in-action_thumb.jpg" width="375" height="147" /></a></p>
<p><!-- Uploaded_images--></p>
<ol>
<li>Now, we will test whether the sequence number resets to 001 or not when the date changes. To do that first close the <strong>frm_Patients</strong> Form. </li>
<li>Open the Patients Table directly in Datasheet View. </li>
<li>Change the 7th and 8th digit from left (the dd digits of the date) to previous date in all the records that you have entered so far.&#160; </li>
<li><strong>For example</strong>: if the date displayed is 201201<strong>09</strong>001<strong> </strong>then change it to previous day like: 201201<strong>08</strong>001. </li>
<li>When you have completed changing all the records close the Table. </li>
<li>Open the Form <strong>frm_Patients</strong> in normal view and try adding few more records on the Form.&#160; </li>
</ol>
<p><em>Tip:&#160; If you prefer to test it on different dates on next few days you may do so rather than changing the dates and trying it now itself.</em></p>
<p>You can see that the Sequence number at the end of the CardNo resets to <strong>001</strong> with current date and subsequent records’ last three digits gets incremented automatically.&#160; </p>
<p>The user cannot change the CardNo manually because we have set the <strong>Locked</strong> Property Value of the field to <strong>Yes.&#160; </strong>Since, the <strong>Enabled</strong> Property Value also set to <strong>Yes </strong>the <a href="http://msaccesstips.com/2011/04/user-level-access-security-and-access2007/">User</a> can select this field and search for a specific CardNo, if needed.</p>
<p>If you would like to display the sequence number part separate from the date with a dash, (like: 20120109-005) we can do that by changing the <strong>Input Mask</strong> Property of the field, without affecting how it is recorded on the table.</p>
<ol>
<li>Open the <strong>frm_Patients</strong> in Design View. </li>
<li>Click on the CardNo field to select it. </li>
<li>Display the Property Sheet (<strong>F4</strong>) of the Field. </li>
<li>Type <strong>99999999-999;;_</strong> in the <strong>Input Mask</strong> Property.&#160;
<p><em>Tip: When you set the input mask this way the dash character between the date and sequence number is never stored in the table, it is used for display purposes only.&#160; But, if you enter a <strong>0</strong> between the two semi-colons like 99999999-999;0;_ then the dash character also will be stored in the CardNo field on the table.&#160; It is better if we don’t do that.</em></p>
</li>
<li>Save the Form and open it in normal view.&#160; Now you can distinguish the date and sequence number very easily. </li>
</ol>
<p>Assume that a Patient approaches the registration desk with her Registration Card, the staff member at the desk should search for the patient’s record with the CardNo to retrieve her history record, to know the location of her personal file, to know which doctor the patient attended last etc.&#160; You have two search options when the search control is displayed.&#160; </p>
<p>Try the following:</p>
<ol>
<li>Click on the CardNo field to select it. </li>
<li>Press <strong>Ctrl+F</strong> to display the search control (search control image is given below). </li>
</ol>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/CardNo-Search.jpg"><img style="display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Autonum Data Search" border="0" alt="Autonum Data Search" src="http://www.msaccesstips.com/uploaded_images/CardNo-Search_thumb.jpg" width="286" height="210" /></a></p>
<p><!-- Uploaded_images--></p>
<p>As shown on the image above you can search for the CardNo without the dash if you remove the check mark from the search option <strong>Search Field as Formatted.&#160; </strong>Put the check-mark on when searched with the dash separating date and sequence number.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:2156e8da-af14-4714-bb92-97571cec90bd" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Autonumber" rel="tag">Autonumber</a>,<a href="http://technorati.com/tags/Forms" rel="tag">Forms</a>,<a href="http://technorati.com/tags/Property" rel="tag">Property</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/">Creating Water- mark on Ms-Access Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/07/iseries-date-in-exported-data/">iSeries Date in exported Data</a> </li>
<li><a href="http://msaccesstips.com/2011/06/change-query-top-values-property-with-vba/">Change Query Top Values property with VBA</a> </li>
<li><a href="http://msaccesstips.com/2011/06/creating-animated-command-button-with-vba/">Creating Animated Command Buttons</a> </li>
<li><a href="http://msaccesstips.com/2011/05/data-change-monitoring/">Data Change Monitoring</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2012/01/autonumber-with-date-and-sequence-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assigning Module Level Error Trap Routines</title>
		<link>http://msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/</link>
		<comments>http://msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 11:42:13 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/?p=2226</guid>
		<description><![CDATA[Last week I have introduced a Function to insert Error Handling lines into a VBA Function or Sub-Routine automatically.&#160; Readers commented saying that it is a good utility but its usage is somewhat cumbersome.&#160; Before running that function the user has to spot some text to search for and then run the function with that [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I have introduced a <a href="http://www.msaccesstips.com/2007/09/useful-report-functions/">Function</a> to insert Error Handling lines into a VBA Function or Sub-Routine automatically.&#160; Readers commented saying that it is a good utility but its usage is somewhat cumbersome.&#160; </p>
<p>Before running that function the user has to spot some text to search for and then run the function with that search text as parameter. The utility function searches for the text, with <strong>.Find()</strong> method of the Module Object, to find the search text and select that line within the target Function/Sub-Routine.&#160; Based on the selected line we can read other details of the function/sub-routine, like total number of lines within that function/sub-routine, function header line number and function ending line number.&#160; These <a href="http://www.msaccesstips.com/2009/12/save-user-specific-parameter-values/">parameters</a> must be available to insert the error handling lines in appropriate locations within the procedure.</p>
<p>If there are several functions or sub-routines to insert error handling lines then this method takes some time to cover all of them, one by one.</p>
<p>Here, we will look at a different version of the same function that scans through the entire Module and inserts error handling lines in all of the Functions/Sub-Routines at one go.</p>
<p>Before that,</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b2592e4c-cf13-4b8e-95b7-fa5da9ee0d83" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Utility" rel="tag">Utility</a></div>
<p> Links to the earlier Articles are given below, just in case if you would like to take a look at the simple methods of the Module Object we have tried earlier:</p>
<p><a href="http://msaccesstips.com/2011/11/writing-vba-code-with-vba/">Write VBA Code with VBA</a></p>
<p><a href="http://msaccesstips.com/2011/11/vba-module-object-and-methods/">VBA Module Object and Methods</a></p>
<p><a href="http://msaccesstips.com/2011/12/prepare-a-list-of-procedure-names-from-a-module/">Prepare a list of Procedure Names from a Module</a></p>
<p><a href="http://msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/">Utility for inserting VBA Error Handler Code</a></p>
<p>The new function is much simpler to use.&#160; Copy and paste the following Code into a new Standard Module and save it:</p>
<pre>Public Function ErrorTrap(ByVal str_ModuleName As String)
On Error GoTo ErrorTrap_Error
'--------------------------------------------------------------
'Program : Inserting Error Handler Lines automatically
'        : in a VBA Module
'Author  : a.p.r. pillai
'Date    : December, 2011
'Remarks : All Rights Reserved by www.msaccesstips.com
'--------------------------------------------------------------
'Parameter List:
'1. strModuleName - Standard Module or Form/Report Module Name
'--------------------------------------------------------------

Dim objMdl As Module, x As Boolean, h As Long, i As Integer
Dim w As Boolean, lngR As Long, intJ As Integer, intK As Integer
Dim linesCount As Long, DeclLines As Long, lngK As Long
Dim str_ProcNames(), strProcName As String, strMsg As String
Dim start_line As Long, end_line As Long, strline As String
Dim lng_StartLine As Long, lng_StartCol As Long
Dim lng_EndLine As Long, lng_EndCol As Long, procEnd As String
Dim ErrHandler As String, lngProcLineCount As Long
Dim ErrTrapStartLine As String, lngProcBodyLine As Long

Set objMdl = Modules(str_ModuleName)

linesCount = objMdl.CountOfLines
DeclLines = objMdl.CountOfDeclarationLines
lngR = 1
strProcName = objMdl.ProcOfLine(DeclLines + 1, lngR)
If strProcName = &quot;&quot; Then
   strMsg = str_ModuleName &amp; &quot; Module is Empty.&quot; &amp; vbCr &amp; vbCr &amp; &quot;Program Aborted!&quot;
   MsgBox strMsg, , &quot;ErrorTrap()&quot;
   Exit Function
End If
strMsg = strProcName
intJ = 0

'Determine procedure Name for each line after declaraction lines
For lngK = DeclLines + 1 To linesCount

  'compare procedure name with ProcOfLine property
  If strProcName &lt;&gt; objMdl.ProcOfLine(lngK, lngR) Then
     'increment by one
     intJ = intJ + 1
     'get the procedure name of the current program line
     strProcName = objMdl.ProcOfLine(lngK, lngR)
  End If
Next lngK

ReDim str_ProcNames(intJ)

strProcName = strMsg: intJ = 0
str_ProcNames(intJ) = strProcName
For lngK = DeclLines + 1 To linesCount
  'compare procedure name with ProcOfLine property

  If strProcName &lt;&gt; objMdl.ProcOfLine(lngK, lngR) Then
     'increment array index by one
     intJ = intJ + 1
     'get the procedure name of the current program line
     strProcName = objMdl.ProcOfLine(lngK, lngR)
     str_ProcNames(intJ) = strProcName

  End If
Next

For intK = 0 To intJ
    ErrHandler = &quot;&quot;
    ErrTrapStartLine = &quot;&quot;
    'Take the total count of lines in the module including blank lines
    linesCount = objMdl.CountOfLines

    strProcName = str_ProcNames(intK) 'copy procedure name
    'calculate the body line number of procedure
    lng_StartLine = objMdl.ProcBodyLine(strProcName, vbext_pk_Proc)
    'calculate procedure end line number including blank lines after End Sub
    lng_EndLine = lng_StartLine + objMdl.ProcCountLines(strProcName, vbext_pk_Proc) + 1

    lng_StartCol = 0: lng_EndCol = 150
    start_line = lng_StartLine: end_line = lng_EndLine

    'Check for existing Error Handling lines in the current procedure
    x = objMdl.Find(&quot;On Error&quot;, lng_StartLine, lng_StartCol, lng_EndLine, lng_EndCol)
    If x Then
         GoTo NxtProc
    Else
     'Create Error Trap start line
         ErrTrapStartLine = &quot;On Error goto &quot; &amp; strProcName &amp; &quot;_Error&quot; &amp; vbCr
    End If

    ErrHandler = vbCr &amp; strProcName &amp; &quot;_Exit:&quot; &amp; vbCr

    lngProcBodyLine = objMdl.ProcBodyLine(strProcName, vbext_pk_Proc)

    'Set procedure start line number to Procedure Body Line Number
    lng_StartLine = lngProcBodyLine
    'calculate procedure end line to startline + procedure line count + 1
    lng_EndLine = lng_StartLine + objMdl.ProcCountLines(strProcName, vbext_pk_Proc) + 1

    'Save end line number for later use
    'here lng_endline may include blank lines after End Sub line
    lngProcLineCount = lng_EndLine

    'Instead of For...Next loop we could have used the .Find() method
    'but some how it fails to detect End Sub/End Function text
    For h = lng_StartLine To lng_EndLine
      strline = objMdl.Lines(h, 1)
      i = InStr(1, strline, &quot;End Sub&quot;)
      If i &gt; 0 Then
          'Format Exit Sub line
          ErrHandler = ErrHandler &amp; &quot;Exit Sub&quot; &amp; vbCr &amp; vbCr
          lngProcLineCount = h 'take the correct end line of End Sub
          h = lng_EndLine + 1
          GoTo xit
      Else
         i = InStr(1, strline, &quot;End Function&quot;)
         If i &gt; 0 Then
          'Format Exit Function line
          ErrHandler = ErrHandler &amp; &quot;Exit Function&quot; &amp; vbCr &amp; vbCr
          lngProcLineCount = h 'or take the correct endline of End Function
          h = lng_EndLine + 1
          GoTo xit
        End If
      End If
xit:
    Next

   'create Error Handler lines
   ErrHandler = ErrHandler &amp; strProcName &amp; &quot;_Error:&quot; &amp; vbCr
   ErrHandler = ErrHandler &amp; &quot;MsgBox Err &amp; &quot; &amp; Chr$(34) &amp; &quot; : &quot; &amp; Chr$(34) &amp; &quot; &amp; &quot;
   ErrHandler = ErrHandler &amp; &quot;Err.Description,,&quot; &amp; Chr$(34) &amp; strProcName &amp; &quot;()&quot; &amp; Chr$(34) &amp; vbCr
   ErrHandler = ErrHandler &amp; &quot;Resume &quot; &amp; strProcName &amp; &quot;_exit&quot;

  'Insert the Error catch start line immediately below the procedure header line
   objMdl.InsertLines lngProcBodyLine + 1, ErrTrapStartLine

 'Insert the Error Handler lines at the bottom of the Procedure
 'immediately above the 'End Function' or 'End Sub' line
   objMdl.InsertLines lngProcLineCount + 2, ErrHandler

NxtProc:
Next

strMsg = &quot;Process Complete.&quot; &amp; vbCr &amp; &quot;List of Procedures:&quot; &amp; vbCr
For intK = 0 To intJ
  strMsg = strMsg &amp; &quot;  *  &quot; &amp; str_ProcNames(intK) &amp; &quot;()&quot; &amp; vbCr
Next
MsgBox strMsg, , &quot;ErrorTrap()&quot;

ErrorTrap_Exit:
Exit Function

ErrorTrap_Error:
MsgBox Err &amp; &quot; : &quot; &amp; Err.Description, , &quot;ErrorTrap()&quot;
Resume ErrorTrap_Exit
End Function</pre>
<p>You can run this function from the Debug Window or from a <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> Click Event Procedure.&#160; Sample run Syntax on Standard Module:</p>
<p>ErrorTrap “Module Name”</p>
<p>Example-1:</p>
<p><font class="colrgreen">ErrorTrap &quot;Module3&quot;</font></p>
<p>Module3 will be scanned for Procedure Names and each procedure is checked for the presence of existing Error Handling lines.&#160; If ‘On Error Goto’ statement is encountered anywhere within a procedure then that procedure is skipped and goes to the next one to check.</p>
<p>To run on <a href="http://www.msaccesstips.com/2009/08/microsoft-excel-power-in-ms-access/">Form</a> or <a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals/">Report</a> Module use the following Syntax:</p>
<p>ErrorTrap &quot;Form_FormName&quot;</p>
<p>Example-2:</p>
<p><font class="colrgreen">ErrorTrap &quot;Form_Employees&quot;</font></p>
<p>Example-3:</p>
<p><font class="colrgreen">ErrorTrap &quot;Report_Orders&quot;</font></p>
<p>When the ErrorTrap() function completes working with a module it displays the list of procedures found in that Module. Sample run image is given below:</p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/errortrap05.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Error Trap run result" border="0" alt="Error Trap run result" src="http://www.msaccesstips.com/uploaded_images/errortrap05_thumb.jpg" width="166" height="268" /></a></p>
<p><!-- Uploaded_images--></p>
<p>If you run the ErrorTrap() Program on a <a href="http://www.msaccesstips.com/2010/05/label-animation-zoom-out-fade/">Form</a>/<a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3/">Report</a> that doesn’t have a VBA Module ( or its <strong>Has Module</strong> Property value is set to <strong>No</strong>) then a <strong><em>Subscript out of Range</em></strong> message is displayed and the program will be aborted.</p>
<p>It is better if you save this Program in your Library Database and link the Library <a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log/">Database</a> to your Project.&#160; Visit the Link: <a href="http://www.msaccesstips.com/2006/09/command-button-animation/">Command Button Animation</a> for details on how to use a database as a Library Database with your own Custom Functions.</p>
<p>I tried to take the ErrorTrap() Function one step further to scan through the entire database Modules and insert error trap routines in all of them, saving each module immediately after changes.&#160; But, Access2007 keep crashing every time and finally I have discarded the idea.&#160; Besides, the above function gives the User more control to review the module subjected to this function for any kind of side effects.</p>
<p>I have test run this function several times and found ok, but field testing may be required under different environment to detect logical errors.&#160; If you find any such errors please give me a feed back through the comment section of this page.&#160; Review each module immediately after running this function for accuracy and use it at your own risk.&#160; </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9409deac-978f-4d8f-a26f-2dde1c7236f7" class="wlWriterSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Utility" rel="tag">Utility</a>,<a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
</p>
<div><font style="font-family: arial; color: black; size: 10 pt">Key Words: </font><font style="font-family: arial; color: blue; font-weight: bold"><a href="http://www.msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/#">Error, </a><a href="http://www.msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/#">Function, </a><a href="http://www.msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/#">Sub-Routine, </a><a href="http://www.msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/#">Form, </a><a href="http://www.msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/#">Module </a></font></div>
</p>
<ul>
<li><a href="http://msaccesstips.com/2011/07/iseries-date-in-exported-data/">iSeries Date in exported Data</a> </li>
<li><a href="http://msaccesstips.com/2011/06/change-query-top-values-property-with-vba/">Change Query Top Values property with VBA</a> </li>
<li><a href="http://msaccesstips.com/2011/06/creating-animated-command-button-with-vba/">Creating Animated Command Buttons</a> </li>
<li><a href="http://msaccesstips.com/2011/05/data-change-monitoring/">Data Change Monitoring</a> </li>
<li><a href="http://msaccesstips.com/2011/05/continued-on-page-2-on-report/">Continued on Page-2 on Report</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/12/assigning-module-level-error-trap-routines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Technorati Verification Page</title>
		<link>http://msaccesstips.com/2011/12/technorati-verification-page/</link>
		<comments>http://msaccesstips.com/2011/12/technorati-verification-page/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 14:04:46 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/?p=2224</guid>
		<description><![CDATA[This page is published specifically for verifying Technorati MVBS6AUTXJRZ verification code. After which this will be removed.]]></description>
			<content:encoded><![CDATA[<p>This page is published specifically for verifying Technorati MVBS6AUTXJRZ verification code.  After which this will be removed.</p>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/12/technorati-verification-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merry Christmas and Happy New Year</title>
		<link>http://msaccesstips.com/2011/12/merry-christmas-and-happy-new-year/</link>
		<comments>http://msaccesstips.com/2011/12/merry-christmas-and-happy-new-year/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 18:49:44 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/?p=2217</guid>
		<description><![CDATA[Flash Card Courtesy: www.123greetings.com History of Christmas On December 25, Christians traditionally celebrate the birth of Christ. The origins of the holiday are uncertain, however by the year 336, the Christian church in Rome observed the Feast of the Nativity (birth) on December 25. Christmas also coincided with the winter solstice and the Roman Festival [...]]]></description>
			<content:encoded><![CDATA[<p><object height="440" width="550" type="application/x-shockwave-flash" id="swf_cardswf" name="swf_cardswf" data="http://i.123g.us/flash/studio_shell.swf"><param name="menu" value="false" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="flashvars" value="&amp;ldrName=http://c.123g.us/flash/branded_loader.swf&amp;crdName=http://i.123g.us/c/edec_c_spirit/card/304573.swf" /></object> </p>
<p>Flash Card Courtesy: <a href="http://www.123greetings.com">www.123greetings.com</a></p>
<p><font color="Red" font-size="2.0em"><b>History of Christmas</b></font></p>
<p>On December 25, Christians traditionally celebrate the birth of Christ. The origins of the holiday are uncertain, however by the year 336, the Christian church in Rome observed the Feast of the Nativity (birth) on December 25. Christmas also coincided with the winter solstice and the Roman Festival of Saturnalia.</p>
<p><font color="Red" font-size="2.0em"><b>Christmas Tinsel</b></font></p>
<p><a href="http://msaccesstips.com/images/christmas.jpg"><img src="http://msaccesstips.com/images/christmas.jpg" /></a></p>
<p>Around 1610, tinsel was first invented in Germany made from genuine silver. Machines were invented that shredded silver into thin tinsel-sized strips. Silver tinsel tarnishes and loses its shine with time, eventually, artificial replacements were invented. The original inventor of tinsel remains unknown.</p>
<p><font color="Red" font-size="2.0em">Candy Canes</font></p>
<p><a href="http://msaccesstips.com/images/christmas2.gif"><img src="http://msaccesstips.com/images/christmas2.gif" /></a></p>
<p><b>Candy Canes</b>: The origin of the candy cane goes back over 350 years, when candy-makers both professional and amateur were making hard sugar sticks. The original candy was straight and completely white in color.</p>
<p><font color="Red" size="2">Artificial Christmas Trees</font></p>
<p>Towards the end of the 1800&#8242;s, another variation of the traditional Christmas tree appeared: the artificial Christmas tree. Artificial trees originated in Germany. Metal wire trees were covered with goose, turkey, ostrich or swan feathers. The feathers were often died green to imitate pine needles.</p>
<p>In the 1930&#8242;s, the Addis Brush Company created the first artificial-brush trees, using the same machinery that made their toilet brushes! The Addis &#8216;Silver Pine&#8217; tree was patented in 1950. The Christmas tree was designed to have a revolving light source under it, colored gels allowed the light to shine in different shades as it revolved under the tree.</p>
<p><font color="Red" font-size="2">Christmas Cards</font>  </p>
<p>Englishman, John Calcott Horsley popularize the tradition of sending Christmas greeting cards, in the 1830s.</p>
<p>Source &#8211; Hallmark Archives: <a href="http://www.hallmark.com/online/">www.hallmark.com/online/</a></p>
</p>
<p>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:bb9fc671-7bc5-4ffb-a185-cf7798197896" style="float:none; display:inline; margin:0px; padding:0px 0px 0px 0px;">Technorati Tags: <a href="http://technorati.com/tags/Christmas" rel="tag">Christmas</a></div></p>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/12/merry-christmas-and-happy-new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utility for inserting VBA Error Handler Code</title>
		<link>http://msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/</link>
		<comments>http://msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 14:29:45 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/</guid>
		<description><![CDATA[We have tried few examples on working with VBA Module Object Properties and Methods. We have learned how to insert a Sub-Routine into a Form Module with expression.InsertLines() method of Module Object with Program. We have also seen how to upload VBA Programs from a Text File into a Form Module with expression.AddFromFile() method of [...]]]></description>
			<content:encoded><![CDATA[<p>We have tried few examples on working with VBA Module Object <strong>Properties</strong> and <strong>Methods.</strong> We have learned how to insert a Sub-Routine into a Form Module with <a href="http://www.msaccesstips.com/2011/11/writing-vba-code-with-vba/">expression.InsertLines()</a> method of Module Object with Program. We have also seen how to upload VBA Programs from a Text File into a Form Module with <a href="http://www.msaccesstips.com/2011/11/vba-module-object-and-methods/">expression.AddFromFile()</a> method of Module Object. We have prepared a <a href="http://www.msaccesstips.com/2011/12/prepare-a-list-of-procedure-names-from-a-module/">list of Functions and Sub-routines</a> from a particular Module through program.</p>
<p>Now, we are going to write a very useful Utility Program for inserting general Error Handler Code Lines into VBA Functions or Sub-Routines automatically. Let us take a look at the Error Trap Routine that we normally write in a Sub-Routine to take care of unexpected errors and to exit the program gracefully, without stopping the code and giving trouble to the User in the middle of normal operations.</p>
<pre>Private Sub cmdRunReport_Click()
<font style="color: blue">On Error Goto cmdRunReport_Click_Error</font>
.
.
.
.
<font style="color: blue">cmdRunReport_Click_Exit:
Exit Sub

cmdRunReport_Click_Error:
MsgBox Err &amp; &quot; : &quot; &amp; Err.Description,,&quot;cmdRunReport_Click()&quot;
Resume cmdRunReport_Click_Exit</font>

End Sub</pre>
<p>The blue colored lines are the Error Handler Lines and the dotted area will hold the actual program.&#160; Normally, we concentrate on writing code for the actual action we intended to execute within the procedure (the dotted line area) and the Error Handler part can wait for later finishing touches stage.&#160; File handling programs or areas where validation checks are performed gets more attention in setting up error trap routines.</p>
<p>Our idea is to insert the Error Handler lines at the beginning and end of the program automatically.&#160; Any serious program that you will write needs these lines of code and writing them manually everywhere will take some of your valuable time in a busy schedule.&#160; If you left out some of your programs without adding the Error Handler lines earlier, you can add them now very easily with the Utility Program that we are going to write.</p>
<p>As you can see in the above code that the lines suffixed with <strong>_Exit</strong>:, <strong>_Error</strong>: etc. have the program name attached to them like <strong>cmdRunReport_Click_Exit: </strong>and these values are taken from the Sub-Routine or Function Names.&#160; The first line of the error handler will be inserted immediately after the Program Name and other lines at the end of the Program.&#160; So we must know few details about the program before we are able to insert the Error Trap Lines into appropriate locations in the program.&#160; For that we must address few Property Values of any line of code located within the Function or Sub-Routine and get the property values from the Module Object.</p>
<p>To make it more clear let us draw out a plan for our program as below:</p>
<ol>
<li>First, search for some unique text within the VBA Module, located within our target Function or Sub-Routine.&#160; For this we can use the <strong>.Find()</strong> method of the Module Object. </li>
<li>Once the search stops on the target line within the Function or Sub-Routine we can read several details of the program we are in now.&#160; The .Find() method not only finds the target line of our program with the search text but also the program line number within the Module (all the lines within a Module is sequentially numbered including blank lines), the Column Number at which the search text starts, which column the search text ends etc.&#160; The Find() method Syntax is as given below: </li>
</ol>
<pre class="alt1">Modules(ModuleName).Find strSearchText, lngStart_Line, lngStart_Column, lngEnd_line, lngEnd_Column, [[WholeWord], [MatchCase], [PatternSearch]]</pre>
<p>Sample Code: </p>
<pre class="alt2">Set mdl = Modules(&quot;Form_Employees&quot;)

With mdl
  .Find “myReport”, lngStart_Line, lngStart_Column, lngEnd_line, lngEnd_Column, False
End With</pre>
<ul>
<li>The first parameter is the search text to find. </li>
<li>The next four parameters tells from where to start and where to stop looking for the search text.&#160; For example, you want to search for the second occurrence of the text “myReport” located somewhere beyond line number 25 then you will set <strong>lngStart_Line=25.&#160; </strong>If “myReport” is in Docmd.OpenReport “myReport” then the lngStart_Column value can be about 10 or leave it as 0 to start searching from beginning of the line.&#160; Once the search text is located by the Find() method all four variables will be loaded with the search text related values as below:
<ul>
<li><strong>lngStart_Line</strong> = line number on which the search text is located. </li>
<li><strong>lngStart_Column</strong> = Column Number (or first character of the search text starts on which character position from left) </li>
<li><strong>lngEnd_Line</strong> = Line on which the Search Text found and search stoped. </li>
<li><strong>lngEnd_Column</strong> = Column on which the search text ends. </li>
</ul>
</li>
<li>Once the search text is located on a line the <strong>lngStart_Line</strong> and <strong>lngEnd_line</strong> will refer to the same program line on which the search text is located.&#160; The start and end column values will be loaded into<strong> lngStart_Column</strong> and<strong> lngEnd_Column</strong> variables. </li>
<li>When the search operation is successful we can extract several information related to that program line to use for working within that particular Function or Sub-Routine. We will read the following information of a particular program to insert the Error Handler lines of Code at appropriate locations in the Program:
<ul>
<li>Get the Program Name from the <strong>.ProcOfLine</strong> Property (or in expanded form <strong>Proc</strong>edure name <strong>Of </strong>the<strong> Line</strong> we found through search) of the program line. </li>
<li>Get the Procedure Body Line Number from the <strong>.ProcBodyLine</strong> Property. The line number on which the program <strong>Private Sub cmdRunReport_Click() </strong>starts. This line number + 1 is the location where we can insert the first line (On Error Goto <a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins/" rel="nofollow" target="_blank">label</a> statement) of Error Handler. </li>
<li>Get the Number of Lines in this particular procedure we are in, from <strong>.ProcCountLines</strong> Property.&#160; Even though this is a useful information this has some draw backs.&#160; If there are blank lines above the procedure Name or below the End Sub or End Function line (if it is the last procedure in a Module then it can have blank lines at the end) they are also included in the count.&#160; So we must take corrective action or take alternative measures to take correct values. </li>
<li></li>
</ul>
</li>
<li>Once the above information is available we can write the Error Handler lines into String Variables and use the <strong>.InsertLines()</strong> method of the Module Object to place them in the beginning and end of the procedure. </li>
</ul>
<ol>
<li>Open the VBA Editing Window (ALT+F11). </li>
<li>Insert a new Standard Module. </li>
<li>Copy and Paste the following VBA Code into the Module and Save it: </li>
</ol>
<pre>Public Function ErrorHandler(ByVal strModuleName As String, _
                                ByVal strSearchText As String, _
                                Optional ByVal lng_StartLine As Long = 1)
On Error GoTo ErrorHandler_Error
'--------------------------------------------------------------------------------
'Program : Inserting Error Handler Lines automatically
'        : in VBA Functions or Sub-Routines
'Author  : a.p.r. pillai
'Date    : December, 2011
'Remarks : All Rights Reserved by www.msaccesstips.com
'--------------------------------------------------------------------------------
'Parameter List:
'1. strModuleName - Standard Module or Form/Report Module Name
'2. strSearchText - Text to search for within a
'   Function or Sub-Routine
'3. lng_StartLine - Text Search Start line Number, default=1
‘Remarks: Standard/Form/Report Module must be kept open before running this Code
'--------------------------------------------------------------------------------
Dim mdl As Module, lng_startCol As Long
Dim lng_endLine As Long, lng_endCol As Long, x As Boolean, w As Boolean
Dim ProcName As String, lngProcLastLine As Long
Dim ErrTrapStartLine As String, ErrHandler As String
Dim sline As Long, scol As Long, eline As Long, ecol As Long
Dim lngProcBodyLine As Long, lngProcLineCount As Long
Dim lngProcStartLine As Long, start_line As Long, end_line As Long

Set mdl = Modules(strModuleName)
lng_startCol = 1
lng_endLine = mdl.CountOfLines
lng_endCol = 255

With mdl
    .Find strSearchText, lng_StartLine, lng_startCol, lng_endLine, lng_endCol, False
End With

'lng_StartLine - line number where the text is found
'lng_StartCol  -  starting column where the text starts
'lng_EndCol    - is where the search text ends
'lng_EndLine   - end line where the text search to stop
'if search-text is found then lng_StartLine and lng_EndLine will
'point to the same line where the search-text is found
'otherwise both will be zero

If lng_StartLine &gt; 1 Then
  'Get Procedure Name.
  'The vbext_pk_Proc system constant
  'dictates to look within a Function or Sub Routine
  'Not to consider Property-Let/Get etc.
   ProcName = mdl.ProcOfLine(lng_endLine, vbext_pk_Proc)

   'Get Procedure Body Line Number
   lngProcBodyLine = mdl.ProcBodyLine(ProcName, vbext_pk_Proc)

   'Look for existing Error trap routine, if any
   'if found abort the program
   sline = lngProcBodyLine: scol = 1: ecol = 100: eline = lng_endLine
   x = mdl.Find(&quot;On Error&quot;, sline, scol, eline, ecol)
   If x Then
      MsgBox &quot;Error Handler already assigned, program aborted&quot;
      Exit Function
   End If

 'Get Line Count of the Procedure, including
 ' blank lines immediately above the procedure name
 'and below, if the procedure is the last one in the Module
   lngProcLineCount = mdl.ProcCountLines(ProcName, vbext_pk_Proc)

 'Create Error Trap start line
   ErrTrapStartLine = &quot;On Error goto &quot; &amp; ProcName &amp; &quot;_Error&quot; &amp; vbCr
 'Compose Error Handler lines
   ErrHandler = vbCr &amp; ProcName &amp; &quot;_Exit:&quot; &amp; vbCr

'determine whether it is a Function procedure or a Sub-Routine
'lng_StartLine = lng_endLine:
lng_startCol = 1: lng_endCol = 100: lng_endLine = lngProcBodyLine + lngProcLineCount
'save the startline and lng_EndLine values
start_line = lng_StartLine: end_line = lng_endLine

'Check whether it is a Function Procedure or a Sub-Routine
w = mdl.Find(&quot;End Function&quot;, lng_StartLine, lng_startCol, lng_endLine, lng_endCol, False)

If w Then 'Function Procedure
   'Take correct procedure line count excluding
   'blank lines below End Sub or End Function line
   lngProcLineCount = lng_StartLine
   ErrHandler = ErrHandler &amp; &quot;Exit Function&quot; &amp; vbCr &amp; vbCr
Else
   lng_StartLine = start_line: lng_endLine = end_line: lng_startCol = 1: lng_endCol = 100
   w = mdl.Find(&quot;End Sub&quot;, lng_StartLine, lng_startCol, lng_endLine, lng_endCol, False)
   If w Then 'Sub-Routine
     lngProcLineCount = lng_StartLine
     ErrHandler = ErrHandler &amp; &quot;Exit Sub&quot; &amp; vbCr &amp; vbCr
   End If
End If
   'create Error Handler lines
   ErrHandler = ErrHandler &amp; ProcName &amp; &quot;_Error:&quot; &amp; vbCr
   ErrHandler = ErrHandler &amp; &quot;MsgBox Err &amp; &quot; &amp; Chr$(34) &amp; &quot; : &quot; &amp; Chr$(34) &amp; &quot; &amp; &quot;
   ErrHandler = ErrHandler &amp; &quot;Err.Description,,&quot; &amp; Chr$(34) &amp; ProcName &amp; &quot;()&quot; &amp; Chr$(34) &amp; vbCr
   ErrHandler = ErrHandler &amp; &quot;Resume &quot; &amp; ProcName &amp; &quot;_exit&quot;

  'Insert the Error catch start line immediately below the header line
   mdl.InsertLines lngProcBodyLine + 1, ErrTrapStartLine

 'Insert the Error Handler lines at the bottom of the Procedure
 'immediately above the 'End Function' or 'End Sub' line
   mdl.InsertLines lngProcLineCount + 2, ErrHandler

End If

ErrorHandler_Exit:
Exit Function

ErrorHandler_Error:
MsgBox Err &amp; &quot; : &quot; &amp; Err.Description, , &quot;ErrorHandler()&quot;
Resume ErrorHandler_Exit

End Function</pre>
<p>Since, this program itself is a Coding aide you must keep the target Module (Standard/<a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form/">Form</a>/<a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3/">Report</a>) open before running this program to insert the Error Handling code segment into the target Function/Sub-Routine.</p>
<p>You may call the <strong>ErrorHandler()</strong> Function from the <strong>Debug Window</strong> or from a <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> Click Event Procedure as shown below:</p>
<pre class="alt1">'The third parameter is optional, you may omit it
ErrorHandler &quot;Form_Employees&quot;,&quot;myReport&quot;,1</pre>
<p>This will start searching for the text <strong>myReport</strong> from the beginning of the Employees Form Module, stops within the program where the search finds a text match and inserts the Error Handling Code lines at the beginning and end of the program.</p>
<p>If the text &#8216;myReport&#8217; appears in more than one Function/Sub-Routine in the Module then you must give the third parameter (Search start line number) to start searching for the text beyond the area wherever exclusion is required. Example: </p>
<pre class="alt1">'Look for text 'myReport' from line 20 onwards only
ErrorHandler &quot;Form_Employees&quot;,&quot;myReport&quot;,20</pre>
<p>When the ErrorHandler() Function is run, first it will look for the presence of existing error handling lines starting with &#8216;On Error&#8217; and if found assumes that the error handling lines are already present in the Function/Sub-Routine and stops the program after displaying the following message: </p>
<blockquote><p>‘Error Handler already assigned, program aborted.&#8217; </p></blockquote>
<p>Comment lines are added for clarity above the program lines explaining what happens next.&#160; </p>
<p>If you find any logical error in the program please give me feed back through the comment section of this page. To protect from spam we insist on joining the site before you are able to post comments.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9409deac-978f-4d8f-a26f-2dde1c7236f7" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Utility" rel="tag">Utility</a>,<a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
<p></p>
<div><font style="font-family: arial; color: black; size: 10 pt">Key Words: </font><font style="font-family: arial; color: blue; font-weight: bold"><a href="http://www.msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/#">Error, </a><a href="http://www.msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/#">Function, </a><a href="http://www.msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/#">Sub-Routine, </a><a href="http://www.msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/#">Form, </a><a href="http://www.msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/#">Module </a></font></div>
<p></p>
<ul>
<li><a href="http://msaccesstips.com/2011/06/change-query-top-values-property-with-vba/">Change Query Top Values property with VBA</a> </li>
</ul>
<li><a href="http://msaccesstips.com/2011/06/creating-animated-command-button-with-vba/">Creating Animated Command Buttons</a> </li>
<li><a href="http://msaccesstips.com/2011/05/data-change-monitoring/">Data Change Monitoring</a> </li>
<li><a href="http://msaccesstips.com/2011/05/continued-on-page-2-on-report/">Continued on Page-2 on Report</a> </li>
<li><a href="http://msaccesstips.com/2011/05/product-group-sequence-with-auto-numbers/">Product Group Sequence with Autonumbers</a>
</p>
</li>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/12/utility-for-inserting-vba-error-handler-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Prepare a List of Procedure Names from a Module</title>
		<link>http://msaccesstips.com/2011/12/prepare-a-list-of-procedure-names-from-a-module/</link>
		<comments>http://msaccesstips.com/2011/12/prepare-a-list-of-procedure-names-from-a-module/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 18:10:16 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/12/prepare-a-list-of-procedure-names-from-a-module/</guid>
		<description><![CDATA[How to prepare a list of Procedure Names (Function or Sub-Routine Names) from a Standard Module or Class Module? Earlier Articles: Writing Code with VBA. Uploading Code from external Text File into a Module. We have seen how to insert a cmdButton_Click() Event Procedure into a Form Module using the .InsertLines() method of the Module [...]]]></description>
			<content:encoded><![CDATA[<p>How to prepare a list of Procedure Names (Function or Sub-Routine Names) from a Standard Module or Class Module?</p>
<p>Earlier Articles: </p>
<ol>
<li><a href="http://msaccesstips.com/2011/11/writing-vba-code-with-vba/">Writing Code with VBA.</a> </li>
<li><a href="http://msaccesstips.com/2011/11/vba-module-object-and-methods/">Uploading Code from external Text File into a Module.</a> </li>
</ol>
<p>We have seen how to insert a cmdButton_Click() Event Procedure into a Form Module using the .InsertLines() method of the Module Object in the first Articlle and how to upload the same program from a Text File with the .AddFromFile() method of the Module Object in the second Article.</p>
<p>In this example, we will try to prepare a list of Procedures from a Standard Module and from a Class Module.&#160; Here, we will learn the usage of the following Properties of the Module Object:</p>
<pre class="alt2"> With Modules(strModuleName):
   lng_BodyLines = <strong>.CountOfLines</strong> ‘ Total Number of lines of Code in the Module
   lng_LinesAtGobalArea = <strong>.CountOfDeclarationLines</strong> ‘Takes a count of lines in the Global declaration area
   str_ProcedureName = <strong>.ProcOfLine(LineNumber, NumberOfLines)</strong> ‘indexed list of Code lines with their Procedure names
 End with </pre>
<p>The <strong>.ProcOfLine</strong> (stands for Procedure Name of the current line of VBA Code) is an indexed list and we must provide the index number of the Code line under process to check which procedure that the code line belongs to.&#160; The second index value is normally one, if you are inspecting a line by line basis. If you prefer to check two or more lines together then change this number accordingly.</p>
<p>The Pseudo Code of the VBA Program we are going to write is given below.</p>
<blockquote>
<ol>
<li>Take <strong>Count of Code Lines</strong> of the Module, Standard Module or Class Module. </li>
<li>Take <strong>Count of Global Declaration Lines</strong>. </li>
<li>First Procedure Name&#160; =&#160; Count of Global declaration Lines + 1 </li>
<li>Array(0) = First Procedure Name. Saves the Function/Sub-Routine name into an Array. </li>
<li>Scan through the remaining lines of code: </li>
</ol>
<p>&#160;&#160;&#160;&#160; A)&#160;&#160; Check the <strong>.ProcOfLine</strong> property value for the Procedure Name of the current line of Code.</p>
<p>&#160;&#160;&#160;&#160; B)&#160; If the Procedure Name of the current line is same as of previous line then go to <strong>C)</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Else save the current Code line’s Procedure Name in the next element of Array().</p>
<p>&#160;&#160;&#160;&#160; C)&#160; Move to the next Code line and if End-of-lines reached then go to <strong>D)</strong> else repeat from <strong>A)</strong></p>
<p>&#160;&#160;&#160;&#160; D)&#160; Create a string with the Procedure Names from the saved Array.</p>
<p>&#160;&#160;&#160;&#160; E)&#160; Display the list of Procedures in a Message Box.</p>
<p>&#160;&#160;&#160;&#160; F)&#160; End of Program.</p>
<p>Now let us write our VBA Code for the above program.</p>
</blockquote>
<pre>Public Function ListOfProcs(ByVal strModuleName As String)
<font class="colrgreen">'------------------------------------------------------
'Courtesy : Microsoft Access
'------------------------------------------------------</font>
Dim mdl As Module
Dim linesCount As Long, DeclLines As Long
Dim strProcName As String, lngR As Long, intJ As Integer
Dim str_ProcNames() As String, lngK As Long
Dim strMsg As String

Set mdl = Modules(strModuleName)
<font class="colrgreen">'Total Count of lines in the Module</font>
linesCount = mdl.CountOfLines

<font class="colrgreen">'Take the count of Global declaration lines</font>
DeclLines = mdl.CountOfDeclarationLines
lngR = 1

<font class="colrgreen">'The first line below the declaration lines
'is the first procedure name in the Module</font>
strProcName = mdl.ProcOfLine(<strong>DeclLines + 1</strong>, lngR)
<font class="colrgreen">'Re-dimension the str_ProcNames() Array for a single element
'and save the procedure name in the Array.</font>
intJ = 0
ReDim Preserve str_ProcNames(intJ)
str_ProcNames(intJ) = strProcName
<font class="colrgreen">'Determine procedure Name for each line after declaraction lines</font>
For lngK = DeclLines + 1 To linesCount
<font class="colrgreen">'compare current Code-line’s procedure name with earlier line’s name
 ‘if not matching then we have encountered a new procedure name</font>
 If strProcName &lt;&gt; mdl.ProcOfLine(lngK, lngR) Then
 <font class="colrgreen">'increment array index by one</font>
 intJ = intJ + 1
 <font class="colrgreen">'get the procedure name of the current program line</font>
 strProcName = mdl.ProcOfLine(lngK, lngR)
 <font class="colrgreen">'Redimension the array for a new element by
 'preserving the data of earlier elements</font>
 ReDim Preserve str_ProcNames(intJ)
 <font class="colrgreen">'Save the procedure name in the array</font>
str_ProcNames(intJ) = strProcName
 End If
Next lngK
 <font class="colrgreen">'create the list of Procedure Names from Array to display</font>
strMsg = &quot;Procedures in the Module: &quot; &amp; strModuleName &amp; vbCr
For intJ = 0 To UBound(str_ProcNames)
 strMsg = strMsg &amp; str_ProcNames(intJ) &amp; vbCr
Next
 MsgBox strMsg
End Function </pre>
<p>Copy and paste the above program into a Standard Module and save it.</p>
<p>To display a list of procedures from a Standard Module, display the Debug Window (Ctrl+G) and type the following command with a standard Module name as parameter like the sample given below and press Enter Key:</p>
<p><font class="colrgreen">ListOfProcs &quot;Utility_Local&quot;</font></p>
<p>Sample run display of Procedure Names in a MsgBox is shown below:</p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/Global-Module-Procs.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Functions in Global Module" border="0" alt="Functions in Global Module" src="http://www.msaccesstips.com/uploaded_images/Global-Module-Procs_thumb.jpg" width="225" height="215" /></a></p>
<p><!-- Uploaded_images--></p>
<p>To take listing of procedures from a Form or Report Module use the following Syntax:</p>
<p><font class="colrgreen">ListOfProcs &quot;Form_myFormName&quot;</font></p>
<p>or</p>
<p><font class="colrgreen">ListOfProcs &quot;Report_myReportName&quot;</font></p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/Form-Module-Proc-List.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Sub-Routines &#13;&#13;&#10;in Form&#39;s Class Module" border="0" alt="Sub-Routines in Form&#39;s Class Module" src="http://www.msaccesstips.com/uploaded_images/Form-Module-Proc-List_thumb.jpg" width="218" height="254" /></a></p>
<p><!-- Uploaded_images--></p>
<p>Sample run output from a Form Module.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3f950441-8f27-4576-94b1-61d1c85f1b4f" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a>,<a href="http://technorati.com/tags/VBA" rel="tag">VBA</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/06/creating-animated-command-button-with-vba/">Creating Animated Command Buttons</a> </li>
<li><a href="http://msaccesstips.com/2011/05/data-change-monitoring/">Data Change Monitoring</a> </li>
<li><a href="http://msaccesstips.com/2011/05/continued-on-page-2-on-report/">Continued on Page-2 on Report</a> </li>
<li><a href="http://msaccesstips.com/2011/05/product-group-sequence-with-auto-numbers/">Product Group Sequence with Autonumbers</a> </li>
<li><a href="http://msaccesstips.com/2011/04/invoke-word-mail-merge-from-access2007/">Invoke Word Mail-Merge from Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/12/prepare-a-list-of-procedure-names-from-a-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA Module Object and Methods</title>
		<link>http://msaccesstips.com/2011/11/vba-module-object-and-methods/</link>
		<comments>http://msaccesstips.com/2011/11/vba-module-object-and-methods/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 17:59:40 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/11/vba-module-object-and-methods/</guid>
		<description><![CDATA[VBA Module Object have several interesting methods and properties.&#160; Last week we have seen how to insert a Click Event Procedure in a Form Module with a Function. You can find this blog post here. I don’t say that the frm.Module.CreateEventProc() method, that we have tried, was an easy approach to write a one line [...]]]></description>
			<content:encoded><![CDATA[<p>VBA Module Object have several interesting methods and properties.&#160; Last week we have seen how to insert a Click Event Procedure in a Form Module with a Function. You can find this blog post <a href="http://msaccesstips.com/2011/11/writing-vba-code-with-vba/">here</a>.</p>
<p>I don’t say that the <strong>frm.Module.CreateEventProc()</strong> method, that we have tried, was an easy approach to write a one line statement in a <a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars/">Form</a> Module.&#160; But, trying something different is always exciting in programming like exploring the unknown.&#160; After all, it is there as part of the Application to explore and learn.&#160; </p>
<p>Today we will try an alternative and simple method for the same example we have tried last week.&#160; That is to write all the program lines in a text file and load that program directly into the Form Module.</p>
<p>If you have tried last week’s example we can use the same ‘Sample’ Form for today’s trial run,&#160; or do the following to get prepared:</p>
<ol>
<li>Open a new Form in Design View. </li>
<li>Create a <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> on the Detail Section of the Form. </li>
<li>While the Command Button is in selected state display it’s <a href="http://www.msaccesstips.com/2009/02/controltip-text-and-time-delay/">Property</a> Sheet (<strong>F4</strong> or <strong>ALT+Enter</strong>). </li>
<li>Change the <strong>Name </strong>Property Value to<strong> cmdRun </strong>and the<strong> Caption </strong>Property Value to<strong> Run Report.</strong> </li>
<li>Save the Form with the name <strong>Sample</strong>. </li>
<li>If you have last week’s <strong>Sample</strong> form then open it in Design View. </li>
<li>Display the <a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard/">Form</a> Module, remove the existing program lines and save the Form. </li>
<li>Open Notepad, copy and paste the following program lines into Notepad and save it as <font class="colrgreen">c:\windows\temp\vbaprg.txt</font>:
<pre class="alt1">Private Sub cmdRun_Click()
    DoCmd.OpenReport &quot;myReport&quot;, acViewPreview
End Sub</pre>
</li>
<li>Replace the report name &quot;myReport&quot; with one of your own <a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally/">Report</a> Name from the database. </li>
<li>Open a Standard VBA Module, copy and paste the following main program into the Standard Module:
<pre>Public Function LoadFromTextFile()
Dim frm As Form, frmName As String, ctrlName As String

frmName = &quot;Sample&quot;
'ctrlName = &quot;cmdRun&quot;

'Open the form in design view
DoCmd.OpenForm frmName, acDesign

'define the form object
Set frm = Forms(frmName)

'call the form's Module Object's AddFromFile() method
'to read the program from the text file
'and insert them into the Form Module
frm.Module.AddFromFile &quot;c:\windows\temp\vbaprg.txt&quot;

'Save and close the form with the code
DoCmd.Close acForm, frmName, acSaveYes

'Open the form in Normal view
DoCmd.OpenForm frmName, acNormal

End Function</pre>
</li>
<li>Place the cursor in the middle of the Code and press <strong>F5</strong> to run the Code. </li>
<li>Press ALT+F11 to display the Database window with the <strong>Sample</strong> <a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form/">Form</a> open. </li>
<li>Click on the <a href="http://www.msaccesstips.com/2008/04/transparent-command-button/">Command Button</a> to open the Report in print preview. </li>
<li>Close the Report. </li>
<li>Change the <strong>Sample</strong> Form in Design View. </li>
<li>Open the form module and check for the program lines we have loaded from the <strong>vbaprg.txt</strong> file. </li>
</ol>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9557bb72-5c3a-4651-b535-390f5c9ed8d3" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Form" rel="tag">Form</a>,<a href="http://technorati.com/tags/Module" rel="tag">Module</a>,<a href="http://technorati.com/tags/Text+File" rel="tag">Text File</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/05/data-change-monitoring/">Data Change Monitoring</a> </li>
<li><a href="http://msaccesstips.com/2011/05/continued-on-page-2-on-report/">Continued on Page-2 on Report</a> </li>
<li><a href="http://msaccesstips.com/2011/05/product-group-sequence-with-auto-numbers/">Product Group Sequence with Autonumbers</a> </li>
<li><a href="http://msaccesstips.com/2011/04/invoke-word-mail-merge-from-access2007/">Invoke Word Mail-Merge from Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/copy-paste-data-from-excel-to-access2007/">Copy Paste Data from Excel to Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/11/vba-module-object-and-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing VBA-Code with VBA</title>
		<link>http://msaccesstips.com/2011/11/writing-vba-code-with-vba/</link>
		<comments>http://msaccesstips.com/2011/11/writing-vba-code-with-vba/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 18:32:41 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[automatically]]></category>
		<category><![CDATA[vba code]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/11/writing-vba-code-with-vba/</guid>
		<description><![CDATA[To insert an Event Procedure in a Form or Report we will open the VBA Module and write the code manually.&#160; If we open the Class Module through the Event Property on the Property Sheet of a Control or Form (after setting “[Event Procedure]” value in the Event property) then the procedure’s opening and closing [...]]]></description>
			<content:encoded><![CDATA[<p>To insert an Event Procedure in a <a href="http://msaccesstips.com/2010/10/lively-controls-on-form/">Form</a> or <a href="http://www.msaccesstips.com/2010/02/form-and-report-open-arguments/">Report</a> we will open the VBA Module and write the code manually.&#160; If we open the Class Module through the Event Property on the Property Sheet of a Control or Form (after setting “[Event Procedure]” value in the Event property) then the procedure’s opening and closing statements (see the example given below) will be inserted by Microsoft Access automatically. After that we insert necessary body lines of the procedure manually between those opening and closing statements.</p>
<p>Sample opening and closing statements of Form_Current() Event Procedure is shown below:</p>
<pre class="alt1">Private Sub Form_Current()

End Sub</pre>
<p>Let us do it differently this time by programming a <a href="http://www.msaccesstips.com/2008/04/transparent-command-button/">Command Button</a> Click event procedure automatically through VBA. We are going to insert a Command Button Click Event Procedure in a Form Module with the help of a Function Write_Code().&#160; We learned something similar through an earlier Article on the topic: <a href="http://msaccesstips.com/2011/06/creating-animated-command-button-with-vba/">Creating Animated Command Button with VBA</a>.&#160; </p>
<p>In this trick, the Command Button is programmed automatically to open a <a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup/">Report</a> in Print Preview.&#160; Following are the lines of VBA Code we are going to insert into the Form Module automatically:</p>
<pre class="alt1">Private Sub cmdRun_Click()
    DoCmd.OpenReport &quot;myReport&quot;, acViewPreview

End Sub</pre>
<ol>
<li>Open a new blank Form in Design View. </li>
<li>Add a <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> control on the Form. </li>
<li>While the Command button is in selected state display it’s Property Sheet (<strong>F4 or ALT+Enter</strong>). </li>
<li>Change the <strong>Name</strong> Property Value to <strong>cmdRun</strong>. </li>
<li>Change the <strong>Caption</strong> Property Value to <strong>Run Report</strong>. </li>
<li>Save and close the Form with the name <strong>frmSample</strong>. </li>
<li>Open VBA Editing Window (ALT+F11) and insert a new Standard Module. You can toggle between <a href=" http://www.msaccesstips.com/2008/05/database-daily-backup/">Database</a> and VBA Windows with <strong>ALT+F11</strong> <a href="http://www.msaccesstips.com/2007/12/keyboard-shortcuts/">Keyboard shortcut</a>. </li>
<li>Copy and Paste the following Code into the Standard Module and save it:
<pre>Public Function Write_Code(ByVal frmName As String, ByVal CtrlName As String)
Dim frm As Form, x, txt As String, ctrl As Control

DoCmd.OpenForm frmName, acDesign, , , , acHidden
Set frm = Forms(frmName)
Set ctrl = frm.Controls(CtrlName)
With ctrl
    If .OnClick = &quot;&quot; Then
       .OnClick = &quot;[Event Procedure]&quot;
    End If
End With

x = frm.Module.CreateEventProc(&quot;Click&quot;, ctrl.Name)

txt = &quot;DoCmd.OpenReport &quot; &amp; Chr$(34) &amp; &quot;myReport&quot; &amp; Chr$(34) &amp; &quot;, acViewPreview&quot;
frm.Module.InsertLines x + 1, txt

DoCmd.Close acForm, frmName, acSaveYes
DoCmd.OpenForm frmName, acNormal

End Function</pre>
</li>
<li>Replace the Report name &quot;myReport&quot; with one of your own <a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally/">Report</a> name in the program line: <font class="colrgreen">txt = &quot;DoCmd.OpenReport &quot; &amp; Chr$(34) &amp; &quot;myReport&quot; &amp; Chr$(34) &amp; &quot;, acViewPreview&quot;.</font> </li>
<li>Display the Debug Window (Ctrl+G). </li>
<li>Type the following line in the Debug Window and press Enter Key:
<pre class="alt1">Write_Code &quot;frmSample&quot;,&quot;cmdRun&quot;</pre>
<p>Form’s name &quot;frmSample&quot;&#160; is passed as first <a href="http://www.msaccesstips.com/2008/11/sum-min-max-avg-paramarray/">parameter</a> to the <strong>Write_Code()</strong> Function and Command Button’s name &quot;cmdRun&quot; is as second parameter. </p>
</li>
<li>
<p>Press ALT+F11 to display the Database window.&#160; You can see that frmSample is already open in normal view after inserting the program lines in it’s VBA Module.</p>
</li>
<li>
<p>Click on the Command Button to open your Report in Print Preview with the <strong>cmdRun_Click()</strong> Event Procedure.&#160; You may change the Form View into Design View, open the Form Module and check the lines of Code we have inserted in there.</p>
</li>
</ol>
<p>At the beginning of the above program the <strong>OnClick </strong>Event <a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties/">Property</a> is checked, for the presence of any programmed action of the Command Button (cmdRun), and inserts the text &quot;<strong>[Event Procedure]&quot; </strong>in the property in preparation for writing the program lines in the VBA Module.</p>
<p>In the next step the Form Module’s .CreateEventProc() method is called to create the <strong>Click </strong>Event Procedure of the Command Button: cmdRun.&#160; If you want a Double-Click Event procedure, rather than a Click() event procedure, then change the word &quot;<strong>Click</strong>&quot; to &quot;<strong>dblClick</strong>&quot;.</p>
<p>Replace the <strong>DoCmd.OpenReport. . .</strong> statement with appropriate Code for other actions like MouseMove.</p>
<p>You can call the <strong>Write_Code() </strong>function from a Command Button click event procedure on a Form.&#160; Create two Text Boxes on the Form, enter the Form Name and Control Name in them and use the text box names in both parameters of the Write_Code() function.</p>
<ul>
<li><a href="http://msaccesstips.com/2011/05/continued-on-page-2-on-report/">Continued on Page-2 on Report</a> </li>
<li><a href="http://msaccesstips.com/2011/05/product-group-sequence-with-auto-numbers/">Product Group Sequence with Autonumbers</a> </li>
<li><a href="http://msaccesstips.com/2011/04/invoke-word-mail-merge-from-access2007/">Invoke Word Mail-Merge from Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/copy-paste-data-from-excel-to-access2007/">Copy Paste Data from Excel to Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/user-level-access-security-and-access2007/">User-level Access Security and Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/11/writing-vba-code-with-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control SetFocus on Tab Page Click</title>
		<link>http://msaccesstips.com/2011/11/control-setfocus-on-tab-page-click/</link>
		<comments>http://msaccesstips.com/2011/11/control-setfocus-on-tab-page-click/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 18:02:19 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[SetFocus]]></category>
		<category><![CDATA[Tab-Page]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/11/control-setfocus-on-tab-page-click/</guid>
		<description><![CDATA[&#34;When I Click on a Tab Control Page I want to set focus on a particular Text box on that page, not on the first Text box on the Tab page, how?&#34; The above question was raised in an MS-Access Discussion Forum on the Net.&#160; The user tried a similar set of the sample code [...]]]></description>
			<content:encoded><![CDATA[<p>&quot;When I Click on a Tab Control Page I want to set focus on a particular Text box on that page, not on the first Text box on the Tab page, how?&quot;</p>
<p>The above question was raised in an MS-Access Discussion Forum on the Net.&#160; The user tried a similar set of the sample code given below (with one of the three lines inter-changeably) on the Page2_Click() Event procedure to move the focus to the &quot;Ship City&quot; Field on the tab page, but none of those lines worked, why?:</p>
<pre class="alt2">Private Sub Page2_Click()
     Forms!frm_Main![Ship City].SetFocus
     frm_MainMenu![Ship City].SetFocus
     me.[Ship City].SetFocus
End Sub </pre>
<p>Tab-Control is an interesting piece of Object to use on a Form. I have used this control mainly for building form based Menus with List Boxes on them. You can find a sample image of a Control Screen below with List box based Menus on it:</p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/CS2.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Form Menu image" border="0" alt="Form Me" src="http://www.msaccesstips.com/uploaded_images/CS2.jpg" width="238" height="155" /></a></p>
<p><!-- Uploaded_images--></p>
<p>In the middle of the <a href="http://www.msaccesstips.com/2007/06/control-screen-design/">Control Form</a> shows a list as a menu of choices.&#160; In fact there are fifteen different set of menus displayed there.&#160; They are displayed one over the other by clicking on a set of Command Buttons, shown on either side of the list box.&#160; You can learn this trick from <a href="http://www.msaccesstips.com/2007/06/control-screen-menu-design/">here</a>. </p>
<p>Coming back to the topic, first thing that you should know is that when you click on the <strong>Tab-Page Button</strong> (see the sample image below) on a Tab-Control the Click Event procedure will not be fired. </p>
<p><!-- Uploaded_images--><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/TabCtl1.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Tab Page Design" border="0" alt="Tab Page Design" src="http://www.msaccesstips.com/uploaded_images/TabCtl1_thumb.jpg" width="238" height="155" /></a></p>
<p><!-- Uploaded_images--></p>
<p>This will happen only when you click somewhere on the body of the Tab-Page.&#160; So you need two clicks, one click on the Tab-Page button to make that page contents visible followed by another click on the body of the Tab-Page to run the <strong>Page2_Click()</strong> Event Procedure so that whatever Code you put in the procedure is executed.&#160; This is not an attractive proposition, but we will take an alternative route to do it with a single-click.</p>
<p>If you have already visited the above text links that I have suggested then you are armed with few ideas and you are already ahead of me on what I am going to say here.&#160; </p>
<p>We will implement the following ideas for a single click solution:</p>
<p>&#160;</p>
<ol>
<li>Create separate <a href="http://www.msaccesstips.com/2009/01/command-button-animation-2/">Command Button</a> for each Tab-Page with one line of VBA Code to make it current or visible. </li>
<li>On the second Command Button click event procedure we will add one more line of code to move the focus to a particular text box at the middle of the tab-page. </li>
<li>Since, we have Command Buttons to display Tab Pages we will hide the Tab-Page Buttons of the Tab-control. Optionally, change the Tab-control’s back-style design transparent to make the tab control’s border design invisible. </li>
</ol>
<p>Before going into the detail design of the above steps I can give you a very simple solution, if you are not interested to go into all the fancy work. Set the Tab Index Property Value of the Text box (like [Ship City]) to 0 (zero).</p>
<p>Don’t mix up <strong>Tab Index</strong> with Tab Control and Tab Page.&#160; When you tap on the Tab-Key on the Keyboard the cursor jumps from one control (Text Box, Combo box, Check-box etc.) to the next based on the <strong>Tab Index Property</strong> Value setting on those controls.</p>
<p>This value is sequentially numbered from 0 to the number of such controls on a Form.&#160; This is automatically set sequentially in the order in which you place the controls on the form at design time manually or through <a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard/">Form Wizards</a>.&#160; When a Form is open the control with Tab Index value 0 will get focus by default, irrespective of it’s physical placement on the form. </p>
<p>So, if the [Ship City] Field is not the starting point on your form and you want to make it so then do the following:</p>
<ol>
<li>Open the Form in design view. </li>
<li>Click on the [Ship City] field to select it. </li>
<li>Display it’s Property Sheet (F4 or ALT+Enter). </li>
<li>Find the <strong>Tab Index Property</strong> and change the Value to <strong>0</strong>.&#160; Other controls’ Tab Index Property values will be automatically changed by Access.&#160; You must review and change them, if needed, to bring them to the desired order. </li>
</ol>
<p><strong>NB:</strong>&#160; Each Tab Page is like a separate sub-form and have separate set of Tab Index sequence numbers starting with zero on them, even if you place different group of fields of the current record.</p>
<p>Now, you are already armed with an easy solution, you may be interested to learn some fancy trick on the Tab Control programming too. </p>
<p>A database can be filled with data very easily.&#160; Any Tom, Dick and Harry can build a database to do that, with whatever easy method available to him.&#160; If it is for his own use then no issues.&#160; But, when it is presented to a Client/User it should have an impressive appearance and should be user-friendly.&#160; Besides that it gives you a chance to advertise your professionalism in your work too.</p>
<p>Coming back to the topic, we will now take the first three steps of action, we have defined above, for a different approach to solve the problem.&#160; A sample design of a Form, with a Tab Control with three pages to hold different group of information from the Orders Table of Northwind.accdb sample database.&#160; You may use any table you like for designing a similar Form, with three <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Buttons</a> at the left side of the Tab Control for trial run:</p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/tabpage-focus.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-left-width: 0px" title="Tab Page Control SetFocus" border="0" alt="Tab Page Control SetFocus" src="http://www.msaccesstips.com/uploaded_images/tabpage-focus_thumb.jpg" width="357" height="216" /></a></p>
<p><!-- Uploaded_images--></p>
<ol>
<li>Click on the first Command Button to select it.
<ul>
<li>Display it’s Property Sheet (F4 or ALT+Enter keys). </li>
<li>Change the <strong>Name</strong> Property Value to <strong>cmdOrder</strong> and change the <strong>Caption </strong>property value to <strong>Order Details</strong>. </li>
<li>Click on the <strong>Event</strong> Tab of the Property&#160; Sheet, select <strong>On Click</strong> Event property, select [Event Procedure] from the drop-down control. </li>
<li>Click on the Build ( . . . ) button to open the Form’s VBA Module with an opening and closing statements of a program. </li>
<li>Copy and paste the following lines of Code, over-writing the existing lines, or simply copy the middle line alone and paste it between the opening and closing statements of the program:
<pre class="alt2">Private Sub cmdOrder_Click()
  Me.TabCtl0.Pages(0).SetFocus
End Sub</pre>
</li>
</ul>
</li>
<li>Similarly change the middle <a href="http://www.msaccesstips.com/2008/04/transparent-command-button/">Command Button’s</a> <strong>Name</strong> Property Value to <strong>cmdShipper</strong> and <strong>Caption</strong> Property Value to <strong>Shipper Details.</strong>
<ul>
<li>Follow the last three steps mentioned above to copy paste the following Code for the middle Command Button Click Event Procedure:
<pre class="alt2">Private Sub cmdShipper_Click()
  Me.TabCtl0.Pages(1).SetFocus
  Me.Ship_City.SetFocus
End Sub</pre>
<p>In the first line code we have changed Tab page reference <strong>.Page(0)</strong> to <strong>.Page(1)</strong> that refers to the second page of the Tab Control.&#160; Here we have added one more line <strong>Me.Ship_City.SetFocus</strong> to move the insertion point (cursor) to the “Ship City” field, wherever it is physically placed.&#160; So, with one click on the Command Button will select the second page of the Tab Control and will set the focus on the Ship City field too. </p>
<p>We are addressing the control (<strong>Me</strong>.Ship_City.SetFocus) as if it is directly placed on the form surface rather than as a child control on the Tab Page.&#160; Remember, each group of fields on each Tab Page have separate set of Tab Index sequence numbers starting from 0, to move the cursor around on that page.</p>
<p>So, if you set the reference of the “Ship City” field as a child control on <strong>Tab Page2</strong>, like <strong>Me.TabCtl0.Pages(1).Controls(&quot;Ship City&quot;).SetFocus, </strong>it is equally valid. </p>
</li>
</ul>
</li>
<li>Change the last <a href="http://www.msaccesstips.com/2008/03/double-action-command-button/">Command Button’s</a> <strong>Name</strong> Property Value to <strong>cmdPayment</strong> and <strong>Caption</strong> Property Value to <strong>Payment Details</strong>.
<ul>
<li>Copy paste the following lines of Code for the last Command Button Click Event Procedure, as you did for the earlier two cases:
<pre class="alt2">Private Sub cmdPayment_Click()
   Me.TabCtl0.Pages(2).SetFocus
End Sub</pre>
</li>
</ul>
</li>
<li>Save the <a href="http://msaccesstips.com/2010/10/memo-field-and-data-filtering/">Form</a> and open it in normal view. When you open the form, by default <strong>Page1</strong>&#160; of the tab control will be active. </li>
<li>Click on the middle Command Button. You can see the second page of the Tab Control become active and the control &quot;Ship City&quot; field is in focus now. </li>
<li>Click on the <strong>Payment Details</strong> Command Button to select the third page. You may try all the command buttons repeatedly to get the feel of their usage.
<p>Since, our <a href="http://www.msaccesstips.com/2006/09/command-button-animation/">command buttons</a> took over the function of Tab-Pages of the Tab Control Object we don&#8217;t need the Tab Control Page buttons above and we will remove immediately.</p>
</li>
<li>Change the Form Mode into Design View. </li>
<li>Click on the Tab Control by clicking on the right side of the <strong>Page3</strong> button. </li>
<li>Display the Property Sheet (<strong>F4</strong>). </li>
<li>Click on the <strong>All</strong> tab of the property sheet and set the <strong>Style</strong> Property Value to <strong>None</strong> from the drop-down list.
<p>If you open the Form in normal view the Tab Control will look like the image given below, without the Tab Page indicators. Clicking on the Command Buttons will turn the Pages as before. You can do a magic trick by completely hiding the Tab Control&#8217;s identity marks by setting the <strong>Back Style</strong> Property Value to <strong>Transparent.</strong></p>
<p><!-- Uploaded_images--></p>
<p><a href="http://www.msaccesstips.com/uploaded_images/tabpage-focus2.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Tab Page Design-2" border="0" alt="Tab Page Design-2" src="http://www.msaccesstips.com/uploaded_images/tabpage-focus2_thumb.jpg" width="354" height="198" /></a></p>
<p><!-- Uploaded_images--></li>
<li>Change the form to design view (if the form is in normal view) and change the <strong>Back Style</strong> Property Value to <strong>Transparent.</strong> </li>
<li>Save the Form and open it in Normal View.
<p>No sign of the Tab Control now, except displaying the controls on the first Tab Page with their values and labels. Click on the Command Buttons one after the other. You will find that the data fields and their labels appear from nowhere occupying the same area every time, like magic.</p>
</li>
</ol>
<ul>
<li><a href="http://msaccesstips.com/2011/05/product-group-sequence-with-auto-numbers/">Product Group Sequence with Autonumbers</a> </li>
<li><a href="http://msaccesstips.com/2011/04/invoke-word-mail-merge-from-access2007/">Invoke Word Mail-Merge from Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/copy-paste-data-from-excel-to-access2007/">Copy Paste Data from Excel to Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/user-level-access-security-and-access2007/">User-level Access Security and Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/macros-and-temporary-variables/">Macro and Temporary Variables</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/11/control-setfocus-on-tab-page-click/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Data directly into External Databases</title>
		<link>http://msaccesstips.com/2011/10/adding-data-directly-into-external-databases/</link>
		<comments>http://msaccesstips.com/2011/10/adding-data-directly-into-external-databases/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 07:45:48 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Queries]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[External]]></category>
		<category><![CDATA[Query]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/10/adding-data-directly-into-external-databases/</guid>
		<description><![CDATA[Back-End to Front-End database designs are common in MS-Access .&#160; Back-end can be MS-Access, dBase, SQL Server, Excel or Paradox databases with their linked Tables.&#160; Once the tables are linked they function as if they are the native tables of Access Database.&#160; You can design Queries, Forms, Report on them and manage them from FE. [...]]]></description>
			<content:encoded><![CDATA[<p><em>Back-End</em> to <em>Front-End</em> database designs are common in MS-Access .&#160; Back-end can be MS-Access, dBase, SQL Server, Excel or Paradox databases with their linked Tables.&#160; Once the tables are linked they <a href="http://www.msaccesstips.com/2007/09/useful-report-functions/">function</a> as if they are the native tables of Access Database.&#160; You can design <a href="http://www.msaccesstips.com/2008/02/union-query/">Queries</a>, <a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars/">Forms</a>, <a href="http://www.msaccesstips.com/2008/09/no-data-and-report-error/">Report</a> on them and manage them from FE.</p>
<p>But, can we manage without directly linking them to the FE?&#160; For example; can we create a Query in the current database using an external Table (not a linked table) from another MS-Access database?</p>
<p>This topic we have already discussed earlier and proved that it is possible.&#160; Check the following Blog Posts to learn this trick on different types of external data sources:</p>
<ol>
<li><a href="http://www.msaccesstips.com/2008/07/opening-external-data-sources/">Opening External Data Sources</a> </li>
<li><a href="http://www.msaccesstips.com/2008/07/opening-dbase-files-directly/">Opening dBase Files directly</a> </li>
<li><a href="http://www.msaccesstips.com/2008/08/opening-excel-database-directly/">Opening Excel Database directly</a> </li>
<li><a href="http://www.msaccesstips.com/2008/08/display-excel-value-directly-on-form/">Display Excel Values directly on Form</a> </li>
<li><a href="http://www.msaccesstips.com/2008/08/database-connection-string-properties/">Database Connection String Properties</a> </li>
<li><a href="http://www.msaccesstips.com/2008/09/source-connect-str-property-and-odbc/">Source ConnectStr Property and ODBC</a> </li>
<li><a href="http://www.msaccesstips.com/2008/09/link-external-tables-with-vba/">Link External Tables with VBA</a> </li>
<li><a href="http://www.msaccesstips.com/2008/09/lost-links-of-external-tables/">Lost Links of External Tables</a> </li>
<li><a href="http://www.msaccesstips.com/2008/08/ms-access-live-data-in-excel/">MS-Access Live data in Excel</a> </li>
<li><a href="http://www.msaccesstips.com/2008/08/access-live-data-in-excel-2/">MS-Access Live data in Excel-2</a> </li>
</ol>
<p>As you can see from the above list that serial number 1 to 6 methods are used for bringing external data into Access in different ways without keeping them linked to the Access Database.&#160; When working with dBase or Foxpro Tables, the path to the Folder, where the dBase/Foxpro Table is located stands as the database name. </p>
<p>If you have gone through the second Article <a href="http://www.msaccesstips.com/2008/07/opening-dbase-files-directly/">Opening dBase Files directly</a> then you already know what we are going to explore here and have a general idea by now as how to send output data into external databases without linking them to MS-Access.</p>
<p>Before going into that let us take a closer look at the sample SQL that brings in data from a dBase Table through a Query, without linking the table into MS-Access database. </p>
<p><strong>NB:</strong>&#160; If you don’t have a dBase Table, to try out these examples, you can create dBase Tables by exporting one or more of your Access Tables into a separate Folder on your disk.&#160; You don’t have to install dBase Application on your machine. Necessary ODBC Driver Files are already installed by MS-Office in your machine.</p>
<pre class="alt2">

SELECT Employees.* FROM Employees IN 'C:\MydBase'[DBASE IV;];
</pre>
<p>The SELECT Query will return the entire records from the Employees.dbf Table from the dBase database ‘C:\MydBase’.&#160; The text&#160; [DBASE IV;] is the database type and version indicator.&#160; The SQL <em>IN &#8216;C:\MydBase&#8217;[DBASE IV;]; </em>clause creates a direct link to the Employees.dbf Table without a physical link.&#160; That means the Employees.dbf data is available to other processes through this query only.</p>
<p>Through out the above articles we were discussing about bringing data in from external databases without keeping them linked to the Access.&#160; This time we will explore how to update or add data into the external databases. </p>
<p>A sample SQL that updates an external dBase Table is given below:</p>
<pre class="alt2">

UPDATE Products IN 'C:\MydBase'[DBASE 5.0;] SET Products.TARGET_LEV = 45
WHERE (((Products.TARGET_LEV)=40) AND ((Products.REORDER_LE)=10));
</pre>
<p>With the above SQL we are updating the Products stock Target level to 45 from 40, for items with Re-order Level (Minimum Stock Level) is 10 and current stock quantity target level is 40.</p>
<p>Let us append some data from Products_Tmp Table from the current MS-Access Database to the Products.dbf Table of <em>C:\MydBase</em> dBase Database.&#160; The sample SQL is given below:</p>
<p>&#160;</p>
<pre class="alt2">
  INSERT INTO Products
  SELECT Products_Tmp.*
  FROM Products_Tmp IN 'C:\MydBase'[DBASE 5.0;];
</pre>
<p>Let us examine the <a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table/">Property Sheet</a> of one of the above Queries to check for any indication about the SQL <em>IN Clause</em> setting is in there or not?</p>
<ol>
<li>Open one of the above Queries in Design View. </li>
<li>Display the Property Sheet of the Query. Press <em>F4</em> or <em>ALT+Enter</em> to display the property sheet and make sure that it is the Query Property Sheet. Below the Title of the Property Sheet there will be a description: <em>Selection Type Query Property.</em> </li>
<li>You may click on an empty area to the right of the Table on the Query Design surface to make sure that the Property Sheet displayed is Query&#8217;s Property Sheet, not the Table or Query Column Property Sheet. Check the sample image given below.<br />
 <!-- Uploaded_images--></p>
<p><a href="http://msaccesstips.com/uploaded_images/query-connectstr.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Query ConnectStr Property" border="0" alt="Query ConnectStr Property" src="http://msaccesstips.com/uploaded_images/query-connectstr_thumb.jpg" width="375" height="193" /></a></p>
<p><!-- Uploaded_images--></li>
<li>Check the <em>Source Database</em> and <em>Source Connect Str</em> Property Values. If you find it difficult to memorize the correct syntax of the <em>IN Clause </em>in the SQL then you can populate the respective values in these properties of the Query as shown. This will automatically insert the Connection String with correct syntax in the SQL.</li>
</ol>
<p>You can find correct syntax for Access, Excel, Paradox and ODBC connection string for IBM iSeries machine, SQL Server etc. from the above quoted Articles.</p>
<p><font style="font-size: 14pt; font-weight: bold">A Word of Caution:</font> </p>
<p>Even though the above methods provide some convenient way to manage external tables, without keeping them permanently linked to MS-Access database, extensive use of this method can lead to issues at a later stage, if you are not careful. It is important that you maintain some form of documentation of these Queries for safe keep.</p>
<p><font style="font-size: 12pt; font-weight: bold">What kind of issues?</font></p>
<p>Let us take the example of an external MS-Access database itself. The SQL given below appends some data into the Employees table in another Microsoft Access database on LAN Server directly. This is a routine process done daily or weekly etc.</p>
<pre class="alt2">INSERT INTO Employees IN 'T:\Sales\mdbFolder\Database1.accdb'
SELECT Employees_tmp.*
FROM Employees_tmp;</pre>
<p>Everything works just fine and you forgot about this specific Query or other Queries similar to this one. After about six month’s time you thought of shifting or copying the databases from the current location into another Folder on Server (say T:\Export\mdbFolder), leaving a copy in the old . . .\Sales\. . . folder as backup, and installed in the new . . .\Export\. . . folder. Everything found working OK without triggering any error in the new location and the Users are also happy.</p>
<p>Your database have few <a href="http://www.msaccesstips.com/2008/02/percentage-on-total-query/">Queries</a> with the above Connection Strings in their SQL, which never crossed into your mind of attending to them and to change the SQL to point them correctly to the databases on the new location. The <a href="http://www.msaccesstips.com/2008/02/crosstab-union-queries-for-charts/">Queries</a> will keep on servicing the Table in the old location . . .\Sales\. . . , instead of the Table in . . .\Export\. . . location. The data missing problem when reported by the user may not trigger the <a href="http://www.msaccesstips.com/2008/03/filtering-data-for-different-users/">Query</a> <em>IN Clause</em> button in your mind immediately and you may be pulling your hair to find out what went wrong, wasting hours or days, till you arrive at the accident spot.</p>
<p>In spite of these draw-backs it is a good way to use the external databases when needed only, if the frequency is minimal, rather than keeping them always attached to the FE.&#160; </p>
<ul>
<li><a href="http://msaccesstips.com/2011/04/invoke-word-mail-merge-from-access2007/">Invoke Word Mail-Merge from Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/copy-paste-data-from-excel-to-access2007/">Copy Paste Data from Excel to Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/user-level-access-security-and-access2007/">User-level Access Security and Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/macros-and-temporary-variables/">Macro and Temporary Variables</a> </li>
<li><a href="http://msaccesstips.com/2011/03/easy-read-reports/">Easy-read Reports</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/10/adding-data-directly-into-external-databases/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Users and Groups Listing from Workgroup Information File</title>
		<link>http://msaccesstips.com/2011/10/users-and-groups-listing-from-workgroup-information-file/</link>
		<comments>http://msaccesstips.com/2011/10/users-and-groups-listing-from-workgroup-information-file/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 15:02:50 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[MS-Access Security]]></category>
		<category><![CDATA[Groups]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[Workgroup]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/10/users-and-groups-listing-from-workgroup-information-file/</guid>
		<description><![CDATA[How about taking a print out of Users and Groups from the active Workgroup Information File (Microsoft Access Security File)? This is only for users of Microsoft Access 2003 or earlier version databases implemented with Microsoft Access Security. You can use earlier version databases in Access2007 or in Access 2010 without converting them. I am [...]]]></description>
			<content:encoded><![CDATA[<p>How about taking a print out of <strong>Users</strong> and <strong>Groups</strong> from the active Workgroup Information File (<a href="http://www.msaccesstips.com/2006/11/microsoft-access-security/">Microsoft Access Security</a> File)?</p>
<p>This is only for users of Microsoft Access 2003 or earlier version databases implemented with Microsoft Access Security. You can use earlier version databases in Access2007 or in Access 2010 without converting them. I am not yet upgraded to Access2010.</p>
<p>You can run the Workgroup Administrator program from Access2007 to link to the <a href="http://www.msaccesstips.com/2006/11/convert-oldversion-workgroup-file/">Workgroup Information File</a> (.mdw). Please refer the Article: <a href="http://msaccesstips.com/2011/08/running-workgroup-admin-in-access2007/">Running Workgroup Admin Program from Access2007</a> for details.</p>
<p>Frankly speaking, I am not happy with the idea of frequent changes of versions, irrespective of what advantages they provide. It is true that I am really excited to learn new features, but not on the cost of what we have already learned and implemented. I still wonder why the <a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars/">Menus and Toolbars</a> are jumbled around and presented them with fancy names like Ribbons in Access2007. These kind of changes will only add to the confusion and waste of time to find out things we are already familiar in earlier version.&#160; By the time users are out of the woods with the new changes they are slapped with a new version and start all over again looking for things, which were in easy reach earlier.</p>
<p>Upgrades are good if draw-backs and bugs of earlier Versions are corrected and implemented with real enhancements, which users can find them easily.&#160; </p>
<p>Coming back to the topic of taking print out of <strong><a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account/">Users</a></strong> and <strong><a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account/">Groups</a></strong>, there is an option already available in Access.&#160; The only problem is that the listing will be dumped directly to the <a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup/">Printer</a>.</p>
<p>To use this option select <strong>Tools &#8211; - &gt; Security &#8211; - &gt; Users and Group Accounts &#8211; - &gt; Users &#8211; - &gt; Print Users and Groups</strong>.&#160;&#160; </p>
<p>In Microsoft Access2007, open a database of Access2003 or earlier version first, then select <strong>Database Tools &#8211; - &gt; Administer &#8211; - &gt; Users and Permissions &#8211; - &gt; User and Group Accounts . . . &#8211; - &gt; Users &#8211; - &gt; Print Users and Groups.</strong></p>
<p>But, why you should waste stationery when you have a better option?&#160; You can create a list of Users and Groups in a Text file and save it on your disk with the VBA Program given below.&#160; Copy and paste the following Code into a Standard Module and save it:</p>
<pre>Public Function UsersList()
'-------------------------------------------------------------
'Author : a.p.r. pillai
'Date   : Oct 2011
'Rights : All Rights Reserved by www.msaccesstips.com
'Remarks: Creates a list of Users &amp; UserGroups from the
'       : active Workgroup Information File and saves
'       : the list into a text file: UserGroup.txt
'       : in the current database path
'-------------------------------------------------------------
Dim wsp As Workspace, grp As Group, usr As User
Dim fs As Object, cp_path As String
Dim a, txt
Const ten As Integer = 10 

cp_path = CurrentProject.Path
Set wsp = DBEngine.Workspaces(0)
'Create a Text file: UserGroup.txt with FileSystemObject
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set a = fs.CreateTextFile(cp_path &amp; &quot;\UserGroup.txt&quot;, True) 

'Write headings
a.writeline &quot;SYSTEM-DEFAULT GROUPS&quot;
a.writeline &quot;-----------------------&quot;
a.writeline (&quot;User-Groups  User-Names&quot;)
a.writeline (&quot;-----------  ----------&quot;) 

'List Default Admins &amp; Users Group First
For Each grp In wsp.Groups
   txt = grp.Name
   If txt = &quot;Admins&quot; Or txt = &quot;Users&quot; Then
     a.writeline txt &amp; Space(ten - Len(grp.Name)) &amp; Space(3) &amp; &quot;...&quot;
     For Each usr In grp.Users
        txt = Space(Len(grp.Name) + (ten - Len(grp.Name))) &amp; Space(3) &amp; usr.Name
        a.writeline txt
     Next: a.writeline crlf
   End If
Next 

'Groups, except Default Admins &amp; Users
a.writeline &quot;ADMINISTRATOR-DEFINED GROUPS&quot;
a.writeline &quot;----------------------------&quot;
a.writeline (&quot;User-Groups  User-Names&quot;)
a.writeline (&quot;-----------  ----------&quot;) 

For Each grp In wsp.Groups
   txt = grp.Name
   If txt = &quot;Admins&quot; Or txt = &quot;Users&quot; Then
      GoTo nextitem
   Else
      a.writeline txt &amp; Space(ten - Len(grp.Name)) &amp; Space(3) &amp; &quot;...&quot;
      For Each usr In grp.Users
         txt = Space(Len(grp.Name) + (ten - Len(grp.Name))) &amp; Space(3) &amp; usr.Name
         a.writeline txt
      Next: a.writeline crlf
   End If
nextitem:
Next
a.Close
'Open UserGroup.txt file with the list User list.
Call Shell(&quot;Notepad.exe &quot; &amp; CurrentProject.Path &amp; &quot;\UserGroup.txt&quot;, vbNormalFocus) 

End Function</pre>
<p>You can run the Code directly from the Debug Window or from a <a href="http://www.msaccesstips.com/2008/03/double-action-command-button/">Command Button</a> Click on a Form.&#160; The <a href="http://www.msaccesstips.com/2006/12/create-text-file-from-msaccess/">Text File</a> will be created in the current database folder with the name <strong>UserGroup.txt</strong> and it will be opened in Windows Notepad automatically.&#160; </p>
<p>Whenever you run this program the earlier file will be over-written.&#160; You may rename the file for safe keep.</p>
<p>The result of a sample run of the program is given below:</p>
<p><a href="http://msaccesstips.com/uploaded_images/users-group.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Users and Group Listing" border="0" alt="Users and Group Listing" src="http://msaccesstips.com/uploaded_images/users-groups_thumb.jpg" width="170" height="363" /></a></p>
<p>If you need a print out of Users and Groups then you may print it from the text file.</p>
<p>&#160;</p>
<ul>
<li><a href="http://msaccesstips.com/2011/04/copy-paste-data-from-excel-to-access2007/">Copy Paste Data from Excel to Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/user-level-access-security-and-access2007/">User-level Access Security and Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/macros-and-temporary-variables/">Macro and Temporary Variables</a> </li>
<li><a href="http://msaccesstips.com/2011/03/easy-read-reports/">Easy-read Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Top N Records in Query</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/10/users-and-groups-listing-from-workgroup-information-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access Security Key Diagram</title>
		<link>http://msaccesstips.com/2011/10/access-security-key-diagram/</link>
		<comments>http://msaccesstips.com/2011/10/access-security-key-diagram/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 08:32:15 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[MS-Access Security]]></category>
		<category><![CDATA[Access Security]]></category>
		<category><![CDATA[Diagram]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/10/access-security-key-diagram/</guid>
		<description><![CDATA[As you are aware implementing Microsoft Access Security is serious business. Even though this has been deprecated from Access2007 and later versions, thousands of Access Developers are still using this feature.&#160; There are several pages of MS-Access Help text explaining the complexities of this feature and it is difficult to visualize how all of them [...]]]></description>
			<content:encoded><![CDATA[<p>As you are aware implementing <a href="http://www.msaccesstips.com/2006/11/microsoft-access-security/">Microsoft Access Security</a> is serious business. Even though this has been deprecated from Access2007 and later versions, thousands of Access Developers are still using this feature.&#160; There are several pages of MS-Access Help text explaining the complexities of this feature and it is difficult to visualize how all of them fit together to form the security key.</p>
<p>I made an attempt here to put the main elements of Microsoft Access Security elements together into the form of a picture so that we will get a general idea as what all components are involved and where they are all kept for implementing Microsoft Access Security.&#160;&#160; </p>
<p>It is important to regulate Users&#8217; roles and maintain security of data, integrity of various objects and VBA Code.</p>
<p>We already have several Articles discussing Microsoft Access Security. You can access these articles from the <a href="http://www.msaccesstips.com/2006/11/microsoft-access-security/">Security</a> Sub-Menu from the Main Menu Bar on this site.</p>
<p>Microsoft Access Security can be divided into two parts:</p>
<ol>
<li>The first part of the Security elements (<em>Workgroup File Id</em> elements and <em>User/Group Names, Personal IDs and Passwords</em>), which resides within the Workgroup Information File.&#160; </li>
<li>Object level access rights information which resides within the Database, forms the second part. </li>
</ol>
<p>When both parts are combined, consisting of fourteen pieces of security elements, becomes the full security key of a User.&#160; See the Diagram given below:</p>
<p><a href="http://msaccesstips.com/uploaded_images/Access-Security-Key.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Access Security Key" border="0" alt="Access Security Key" src="http://msaccesstips.com/uploaded_images/Access-Security-Key_thumb.jpg" width="423" height="368" /></a></p>
<p>The first three elements: <em>Workgroup Name, Organization</em> &amp; <em>Workgroup Id</em> forms the unique Workgroup Information File identification elements. You must keep these information in a safe place, after creating the <a href="http://www.msaccesstips.com/2006/11/convert-oldversion-workgroup-file/">Workgroup Information File</a>.&#160; If you somehow got lost this file you must give these specific information to create this Workgroup Information File again.&#160; MS-Access distinguishes one Workgroup Information File from the other using this unique information.</p>
<p>The next three elements: <em><a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account/">User</a> or Group Name, Personal ID &amp; Password</em> are User specific information.&#160; <a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account/">Group Account</a> have only <em>Group Names</em> and <em>Personal IDs</em>, no passwords.&#160; It is very important that you keep a record of the User/Group Names and their Personal ID information in a safe place.</p>
<p>The Group Security Account is only a means of organizing Users into different groups so that their access privileges can be assigned at Group level.&#160; The Users inherits the access privileges assigned to the Users’ Group Account when they are added to the Group.</p>
<p>When you create a new Workgroup Information File, by default there will be only one User Account: <strong>Admin</strong> and two Group Accounts: <strong>Admins</strong> &amp; <strong>Users</strong> .&#160; The <strong>Admin</strong> User account is a member of the <strong>Admins &amp; Users </strong>Group Accounts.&#160; You cannot delete these two Group Accounts and any new User Account you create will be a member of the <strong>Users</strong> Group Account by default.&#160; You cannot <a href="http://www.msaccesstips.com/2006/11/delete-msaccess-security-user-account/">delete</a> the <strong>Admin</strong> User Account either but it can be removed from the <strong>Admins </strong>Group Account as part of a security measure.</p>
<p>Members of the Admins Group have full administrative power to assign permissions to Objects and transfer ownership of objects (except the Database Object) to other <strong>User/Group</strong> accounts.</p>
<p>Here, one important aspect you have to keep in mind is that the <strong>Owner</strong> of the Database (the User who created the Database)/Object have equal privileges of an Administrator, a member of the <em><strong>Admins</strong></em> Group Account.&#160; The Owner of an object can assign permissions, like an administrator, for other Users or transfer his <a href="http://www.msaccesstips.com/2006/11/view-or-transfer-ownership/">ownership</a> of the object to another User.&#160;&#160; </p>
<p>Ownership of a Database Object cannot be transferred to anybody.&#160; But, one who likes to take the ownership of a Database, he must create a new database and import all the objects (if, he has enough privileges to do that) into the new Database.</p>
<p>&#160;</p>
<ul>
<li><a href="http://msaccesstips.com/2011/04/user-level-access-security-and-access2007/">User-level Access Security and Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/04/macros-and-temporary-variables/">Macro and Temporary Variables</a> </li>
<li><a href="http://msaccesstips.com/2011/03/easy-read-reports/">Easy-read Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Top N Records in Query</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment field in Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/10/access-security-key-diagram/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Sub-Form Recordset from Main Form</title>
		<link>http://msaccesstips.com/2011/10/updating-sub-form-recordset-from-main-form/</link>
		<comments>http://msaccesstips.com/2011/10/updating-sub-form-recordset-from-main-form/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 11:54:55 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[Main Form]]></category>
		<category><![CDATA[SubForm]]></category>
		<category><![CDATA[updating]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/10/updating-sub-form-recordset-from-main-form/</guid>
		<description><![CDATA[Sub-Form on a Main Form is the common design that we follow to display several related records of the record on the Main Form. Order Detail records related to Orders, Bank Account and it&#8217;s transactions, Mark-List and Student&#8217;s Id and in short almost all databases have these kind of one-to-many relationships and records are displayed [...]]]></description>
			<content:encoded><![CDATA[<p>Sub-Form on a Main <a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars/">Form</a> is the common design that we follow to display several related records of the record on the Main Form. <em>Order Detail</em> records related to Orders, Bank Account and it&#8217;s transactions, Mark-List and Student&#8217;s Id and in short almost all databases have these kind of one-to-many relationships and records are displayed in this way to get a quick view of maximum information.</p>
<p>When we open a form with a Table or <a href="http://www.msaccesstips.com/2008/02/union-query/">Query</a> as <em>Record Source</em> the Form when loaded opens a parallel recordset in memory with unique bookmarking of each record. We can search through this virtual recordset in memory without directly touching the actual Table or <a href="http://www.msaccesstips.com/2008/02/percentage-on-total-query/">Query</a>. But, when we add or update a record in this virtual recordset that change is saved in the actual table. We call this virtual recordset as the RecordsetClone of the Form.</p>
<p>Sample VBA Code given below shows how to address the Form&#8217;s RecordsetClone to find a record based on some criteria.</p>
<pre>Private Sub FindPID_Click()
'Find Record matching Product ID
Dim m_find, rst As Recordset

'validation check of search key value
m_find = Me![xFind]
If IsNull(m_find) Then
   Me.FilterOn = False
   Exit Sub
End If

'validation check of search key value
If Val(m_find) = 0 Then
  MsgBox &quot;Give Product ID Number..!&quot;
   Exit Sub
End If

'Find a record that matches the ProductID
'and make that record current using the recordset bookmark.
If Val(m_find) &gt; 0 Then
   Set rst = Me.RecordsetClone 'declare the recordset of the form
   rst.FindFirst &quot;ProductID = &quot; &amp; m_find
   If Not rst.NoMatch Then '&lt;if record found then make that record current
      Me.Bookmark = rst.Bookmark
   End If
   rst.Close
End If

End Sub</pre>
<p>We have a Blog Post on Data search and filter on Form through the above code. If you would like to take a look at it then click <a href="http://www.msaccesstips.com/2007/12/find-or-filter-data-on-form/">here</a>.</p>
<p>In the above example we were using the RecordsetClone Object of the Main <a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form/">Form</a> on the main form module itself. But how do we address the RecordsetClone Object of the Sub-Form, from Main-Form, to update the current recordset on the Sub-Form. Here, what we have to keep in mind is that the records, which appears on the Sub-Form Datasheet View, are related to the current record on the Main-Form and only those records can be accessed for whatever operation we planned to do on them. Not all the records of the Record Source Table/Query.</p>
<p>On the Main Form, all records of the Record Source Table/Query can be accessed through the RecordsetClone object, for search or update operation. But, the RecordsetClone of the sub-form will have only those records displayed on the sub-form, related to the current record on the main-form.</p>
<p>Let us try an example to learn how to access the sub-form recordset from the main form and update records.</p>
<ol>
<li>Import the following two Tables from the Northwind.accdb (or Northwind.mdb) database:
<ul>
<li>Orders </li>
<li>Order Details </li>
</ul>
</li>
<li>Open the Order Details Table in design view.
</p>
</li>
<li>Add a new field: <em>SaleValue</em> with <em>Data Type</em> Number and <em>Field Size</em> Double. </li>
<li>Save the Order Details Table with the new field </li>
<li>Design the Main form for Orders Table in column format.
<p>If you have used the Form Wizard and created a Split Form then delete the Datasheet sub-form or table (Access2007). Display the Property Sheet of the Form, find the <em>Default View</em> property, change the <em>Split Form</em> value to <em>Single Form</em>.</p>
</li>
<li>Design a Datasheet Sub-Form for <em>Order Details</em> Table. </li>
<li>Expand the Footer of the Sub-Form and create a Text box there. </li>
<li>Change the <em>Name</em> Property value to <em>TotSale.</em> </li>
<li>Write the expression <font class="colrgreen">=Sum([SaleValue])</font> in the Control Source property. </li>
<li>Save and close the Form with the name: <em>Order Details</em>. </li>
<li>Insert the <em>Order Details</em> sub-form in the Detail Section of the Orders Form below the Orders Form controls. See the image given below:
<p><a href="http://msaccesstips.com/uploaded_images/sub-form-update.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Updating Sub-Form Recordset" border="0" alt="Updating Sub-Form Recordset" src="http://msaccesstips.com/uploaded_images/sub-form-update_thumb.jpg" width="405" height="228" /></a> </p>
</li>
<li>While the Sub-Form is still in selected state display it&#8217;s <a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table/">Property</a> Sheet (F4). </li>
<li>Change the <em>Link Master Field</em> Property Value to <em>Order ID</em>. </li>
<li>Change the <em>Link Child Field</em> Property Value to <em>Order ID</em>. </li>
<li>Add a <a href="http://www.msaccesstips.com/2009/01/command-button-animation-2/">Command Button</a> above the sub-form as shown on the design above. </li>
<li>Display the Property Sheet of the <a href="http://www.msaccesstips.com/2008/03/double-action-command-button/">Command Button</a> (F4 or Alt+Enter. </li>
<li>Change the <em>Name</em> property value to <em>cmdUpdate</em> </li>
<li>Select the <em>On Click</em> Event property and select <em>[EventProcedure]</em> from the drop-down list. </li>
<li>Click on the Build (. . .) Button at the right end of the property to open the VBA Module of the Form. </li>
<li>Copy and Paste the following VBA Code into the VBA Module overwriting the skeleton lines of the Sub-Routine there.
<pre>Private Sub cmdUpdate_Click()
Dim rst As dao.Recordset
Dim m_UnitPrice As Double
Dim m_Discount As Double
Dim m_Quantity As Long
Dim m_SaleValue As Double

'Address the recordset on the Sub-Form [Order Details]
Set rst = [Order Details].Form.RecordsetClone
rst.MoveFirst
Do While Not rst.EOF
    m_UnitPrice = rst![Unit Price]
    m_Discount = rst![Discount]
    m_Quantity = rst![Quantity]
    m_SaleValue = m_Quantity * ((1 - m_Discount) * m_UnitPrice)
    rst.Edit
    rst![SaleValue] = m_SaleValue
    rst.Update
    [Order Details].Form.Bookmark = rst.Bookmark
rst.MoveNext
Loop
rst.Close

Set rst = Nothing

End Sub</pre>
</li>
<li>Create a Text box to the right of the Command Button. </li>
<li>Change the Caption of the Child Label to <em>Order Value:</em> </li>
<li>Write the expression <font class="colrgreen">=[Order Details].[Form]![totSale]</font>. The idea of this expression is to bring the Summary Value from the <a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins/">Text box</a>, we have created in the Footer Section of the sub-form, into the Order Form. </li>
<li>Save and close the Orders Form. </li>
<li>Open the Orders Form in normal View. </li>
<li>If the <em>SaleValue</em> column is not appearing in the visible area of the Datasheet then move the bottom scrollbar to the right, highlight the SaleValue column, click and hold the mouse button and drag it to the left and place it into the visible area.
<p>You can now see the Sub-Form shows some records related to the <em>Order ID</em> on the main Form. The new Text box we have created to the right of the Command Button is empty because we have not updated the [SaleValue] field on the datasheet.</p>
</li>
<li>Click on the <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> to calculate and update the Sale Value of each record on the Datasheet Sub-Form. </li>
</ol>
<p>Now you will find the Sale Value column of all records on the sub-form updated and the Summary value of all records appearing in the Text box to the right of the Command Button. The records updated are only those Order Details records related to Order Id on the Orders Form. If you move the Orders record forward their related record sale value is not updated. They will be updated only when you click on the Command Button.</p>
<p>The statement in the above code <font class="colrgreen">Set rst = [Order Details].Form.RecordsetClone</font> is setting a reference to the RecordsetClone Object of the Sub-Form [Order Details]. Subsequent lines calculates the Sale Value after Discount, if any, and updates the sale value into the new field [SaleValue] we have created in the Order Details Table.</p>
<p>The statement <font class="colrgreen">[Order Details].Form.Bookmark = rst.Bookmark</font> overwrites the form&#8217;s Bookmark with the recordset&#8217;s current record Bookmark. The result of this action is that the current record processed in the recordset clone become current record on the sub-form. If you have several records on the sub-form you can see some visible action on the sub-form moving the cursor from one record to other very fast, starting from the first record to the last one-by-one as the updating action progress through the records.</p>
<ul>
<li><a href="http://msaccesstips.com/2011/04/macros-and-temporary-variables/">Macro and Temporary Variables</a> </li>
<li><a href="http://msaccesstips.com/2011/03/easy-read-reports/">Easy-read Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Top N Records in Query</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment field in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/10/updating-sub-form-recordset-from-main-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy Reference Access2003 Commands in Access2007</title>
		<link>http://msaccesstips.com/2011/10/easy-reference-access2003-commands-in-access2007/</link>
		<comments>http://msaccesstips.com/2011/10/easy-reference-access2003-commands-in-access2007/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 11:07:54 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Access2003]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/10/easy-reference-access2003-commands-in-access2007/</guid>
		<description><![CDATA[You are very familiar with Access2003 Menus and Toolbars. Design tasks are so easy when you know what to look for and where they can be located.&#160; Everything runs so smoothly and one day you hear some exciting news, Microsoft Access2007 released.&#160; You can’t wait to see it and want to start using it’s exciting [...]]]></description>
			<content:encoded><![CDATA[<p>You are very familiar with Access2003 Menus and Toolbars. Design tasks are so easy when you know what to look for and where they can be located.&#160; Everything runs so smoothly and one day you hear some exciting news, Microsoft Access2007 released.&#160; You can’t wait to see it and want to start using it’s exciting new features. You learned lot of things from Access2003 and ready to learn more and new things.</p>
<p>Finally, that day has come and you have got Microsoft Access2007 installed on your machine.&#160; Started exploring the new interfaces to get a feel of things in the new version.</p>
<p>After a few days you are uncomfortable with the whole set up.&#160; Don’t know where to locate Menus and Toolbar buttons (new name Ribbon) you were so familiar with earlier version of Access.&#160; You suddenly realizes that design tasks of <a href="http://www.msaccesstips.com/2010/05/label-animation-zoom-out-fade/">Forms</a> and <a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals/">Reports</a> are not going to be as easy as before, at least till you are familiar and comfortable with the new version of Access.</p>
<p>I know, you are ready to take any possible help from anybody to get going.&#160; I think Microsoft also knows about your hardships and they have something for you to get around this issue, provided if you know what to look for in Access2003.&#160; </p>
<p>There is an Excel Workbook: <em>accessmaps.xls</em> with Access2003 and Access2007 <a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars2/">Menus and Toolbar</a> Options side-by-side.&#160; You can select the Access2003 Menus in Worksheets <em>File, Edit</em> etc. and at the left side locate menu options of Access2003 and at the right column you will find the corresponding Access2007 option, easy?</p>
<p>Well then, find the<em> accessmaps.xls</em> file and save a copy where you can find it easily, probably on your desktop.</p>
<p>Do the following to get the file:</p>
<ol>
<li>Click on the Access Help <a href="http://www.msaccesstips.com/2008/03/double-action-command-button/">button</a> (the circular button with a white question mark in blue background at the right end of the Menu Bar).&#160; Microsoft Access Help window opens. </li>
<li>Click on the <strong><em>Getting started</em></strong> option, under <em>the Table of Contents</em>, to open the sub-topics. </li>
<li>Find <em>Reference: Locations of Access 2003 commands in Access 2007 </em>and click on it to open the details page at the right window. </li>
<li>Click on <em>New locations of familiar commands</em> <a href="http://www.msaccesstips.com/2009/02/external-files-list-in-hyperlinks/">hyperlink</a> to send you to the bottom of the document or use the vertical scroll bar to move to the bottom of the document. </li>
<li>Click on the <em>Access Ribbon mapping workbook </em>and a <em>File Download </em>dialog box&#160; opens up asking whether you want to open or save the accessmaps.xls file. </li>
<li>You better save a copy on your Desktop so that whenever you want it you can find it easily. </li>
</ol>
<ul>
<li><a href="http://msaccesstips.com/2011/03/easy-read-reports/">Easy-read Reports</a> </li>
<li><a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Top N Records in Query</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment field in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment Field in Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/10/easy-reference-access2003-commands-in-access2007/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IIF vs SWITCH Function in MS-Access</title>
		<link>http://msaccesstips.com/2011/09/iif-vs-switch-function-in-ms-access/</link>
		<comments>http://msaccesstips.com/2011/09/iif-vs-switch-function-in-ms-access/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 11:43:02 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[iif]]></category>
		<category><![CDATA[msaccess]]></category>
		<category><![CDATA[switch]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/09/iif-vs-switch-function-in-ms-access/</guid>
		<description><![CDATA[The IIF() Function definition is reproduced here from Microsoft Visual Basic for Applicatiions Reference below: IIf Function Returns one of two parts, depending on the evaluation of an expression. Syntax: IIf(expr, truepart, falsepart) The IIf function syntax has these named arguments: Part Description expr Required. Expression you want to evaluate. truepart Required. Value or expression [...]]]></description>
			<content:encoded><![CDATA[<p>The IIF() Function definition is reproduced here from <a href="http://www.microsoft.com/">Microsoft</a> Visual Basic for Applicatiions Reference below:<br />
<blockquote>
<p>IIf Function Returns one of two parts, depending on the evaluation of an expression.</p>
<p>Syntax: IIf(expr, truepart, falsepart)</p>
<p>The IIf function syntax has these named arguments: </p>
<table border="1" cellspacing="0" cellpadding="0" width="450">
<tbody>
<tr>
<th width="100">Part</th>
<th width="350">Description</th>
</tr>
<tr>
<td width="100">expr</td>
<td width="350">Required. Expression you want to evaluate.</td>
</tr>
<tr>
<td width="100">truepart</td>
<td width="350">Required. Value or expression returned if expr is True.</td>
</tr>
<tr>
<td width="100">falsepart</td>
<td width="350">Required. Value or expression returned if expr is False.</td>
</tr>
</tbody>
</table>
<p>Remarks</p>
<p>IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True. </p>
<p>Example </p>
<p>This example uses the IIf function to evaluate the TestMe parameter of the CheckIt procedure and returns the word &quot;Large&quot; if the amount is greater than 1000; otherwise, it returns the word &quot;Small&quot;. </p>
<pre class="alt2">  Function CheckIt(TestMe As Integer)
      CheckIt = IIf(TestMe &gt; 1000, &quot;Large&quot;, &quot;Small&quot;)
  End Function </pre>
</blockquote>
<p>Courtesy: <a href="http://www.microsoft.com">Microsoft Access Help</a></p>
<p>Let us expand the above function to check a series of expressions to return one of the values among them.</p>
<pre class="alt2">  Function CheckIt(TestMe As Integer)
      CheckIt = IIF(TestMe &gt; 0 AND TestMe &lt; 256, &quot;Byte&quot;,IIF(TestMe &gt; 255 AND TestMe &lt; 32768,&quot;Integer&quot;,&quot;Large&quot;))
  End Function </pre>
<p>As you can see from the above example that for testing of each expression we have to nest the IIF() function one within another, when two or more expressions are evaluated, and it is absolutely necessary that the parentheses are pared properly.&#160; This is where we face problems while using this function in <a href="http://msaccesstips.com/2011/01/sub-query-in-query-column-expressions/">Query</a> columns or in criteria rows etc.</p>
<p>If we need a valid value to be returned when none of the expressions evaluated to True (in the above example the text &quot;Large&quot;) then IIF() is the correct solution, otherwise we have alternative function Switch().</p>
<p>The Switch() Function is very simple to use without nesting of expressions like IIF().&#160; Let us rewrite the CheckIt() Function with Switch() function to see how simple it is.</p>
<p>&#160; Function CheckIt(TestMe As Integer)<br />
  <br />&#160;&#160;&#160;&#160;&#160; CheckIt = Switch(TestMe &gt; 0 AND TestMe &lt; 256, &quot;Byte&quot;,TestMe &gt; 255 AND TestMe &lt; 32768,&quot;Integer&quot;) </p>
<p>&#160; End Function </p>
<p>The above function does the same work but if none of the expressions evaluated to True then the result returned in CheckIt variable is Null instead of the text “Large”.&#160; If you want to check the returned result for Null and replace Null with the text “Large” then rewrite the expression as below:</p>
<p>CheckIt = NZ(Switch(TestMe &gt; 0 AND TestMe &lt; 256, &quot;Byte&quot;,TestMe &gt; 255 AND TestMe &lt; 32768,&quot;Integer&quot;),&quot;Large&quot;)</p>
<p>OR</p>
<p>x = Switch(TestMe &gt; 0 AND TestMe &lt; 256, &quot;Byte&quot;,TestMe &gt; 255 AND TestMe &lt; 32768,&quot;Integer&quot;)</p>
<p>CheckIt = Nz(x,”Large”)</p>
<p>If you are using the Switch() Function in a <a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Query</a> column or criteria row then the first example must be used with Switch() enveloped in Nz().&#160; </p>
<p>I think it is easier and compact to use Switch() <a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2/">Function</a> when compared with IIF() that needs repeating the function name IIF with balancing of several parenthesis when several expressions are evaluated.</p>
<p>Usage in a sample Query: </p>
<pre class="alt2">UPDATE Employees SET Employees.Designation = Switch(Employees.Designation IS NULL,'UNKNOWN')
WHERE ((Employees.FirstName IS NOT NULL));</pre>
<p>See the Switch() Function definition is given below for details, taken from <a href="http://www.microsoft.com">Microsoft</a> Access Help Document.</p>
<p>&#160;</p>
<blockquote>
<p>Switch Function Evaluates a list of expressions and returns a Variant value or an expression associated with the first expression in the list that is True. </p>
<p>Syntax</p>
<p>Switch(expr-1, value-1[, expr-2, value-2 … [, expr-n,value-n]])</p>
<p>The Switch function syntax has these parts: </p>
<table border="1" cellspacing="0" cellpadding="0" width="450">
<tbody>
<tr>
<th width="100">Part</th>
<th width="350">Description</th>
</tr>
<tr>
<td width="100">expr</td>
<td width="350">Required. Variant expression you want to evaluate. </td>
</tr>
<tr>
<td width="100">value</td>
<td width="350">Required. Value or expression to be returned if the corresponding expression is True.</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p>Remarks</p>
<p>The Switch function argument list consists of pairs of expressions and values. The expressions are evaluated from left to right, and the value associated with the first expression to evaluate to True is returned. If the parts aren&#8217;t properly paired, a run-time error occurs. For example, if expr-1 is True, Switch returns value-1. If expr-1 is False, but expr-2 is True, Switch returns value-2, and so on. </p>
<p>Switch returns a Null value if: None of the expressions is True. The first True expression has a corresponding value that is Null. Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs. </p>
<p>Example </p>
<p>This example uses the Switch function to return the name of a language that matches the name of a city. </p>
<pre class="alt2">Function MatchUp (CityName As String)
    Matchup = Switch(CityName = &quot;London&quot;, &quot;English&quot;, CityName _
                    = &quot;Rome&quot;, &quot;Italian&quot;, CityName = &quot;Paris&quot;, &quot;French&quot;)
End Function</pre>
</blockquote>
<ul>
<li><a href="http://msaccesstips.com/2011/03/top-n-records-in-query/">Top N Records in Query</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment field in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment Field in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/02/primarykey-usage-with-many-fields/">PrimaryKey usage with many fields</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/09/iif-vs-switch-function-in-ms-access/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Preparing Rank List</title>
		<link>http://msaccesstips.com/2011/09/preparing-rank-list/</link>
		<comments>http://msaccesstips.com/2011/09/preparing-rank-list/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 10:33:19 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Rank]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/09/preparing-rank-list/</guid>
		<description><![CDATA[We use Autonumber Field in a Table to create automatic sequence numbers for each record entered into the Table. This can be defined as Primary Key field. Related Table field can be assigned these values as Foreign Key to link with the parent Table, so that combined related information can be obtained for Data Views [...]]]></description>
			<content:encoded><![CDATA[<p>We use <strong>Autonumber</strong> Field in a Table to create automatic sequence numbers for each record entered into the Table. This can be defined as Primary Key field. Related Table field can be assigned these values as Foreign Key to link with the parent Table, so that combined related information can be obtained for Data Views or <a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report/">Reports</a>.&#160; Even if it is a stand alone table, not part of any relationships, still it is a good idea to create an autonumber field so that the data can be sorted in keyed-in sequence, especially when the data entry <strong>date/time</strong> is not recorded with the table.</p>
<p>But, when you pull this field into a <a href="http://www.msaccesstips.com/2008/10/multiple-parameters-for-query/">Query</a> with some filter criteria then the autonumber Field contents may not be in consecutive order. If you have planned to use the autonumber field on the report for sequence numbers then you have to look for alternatives. As far as the Report is concerned this is not an issue, you can easily create a Textbox in the <strong>Detail Section</strong> of the Report and type the expression <strong>=1</strong> in the <strong>Control Source</strong> <a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties/">property</a> and set the <strong>Running Sum</strong> property value to <strong>Yes</strong>.</p>
<p>If the the <a href="http://www.msaccesstips.com/2008/04/finding-consecutive-workdays-with-query/">Query</a> is used as a Data View file or create an output table from the filtered data with proper sequence numbers then we have to think of devising some tricks to achieve that. I have already created a Function for generating Sequence Numbers for filtered data in a Query column in an earlier Blog Post and you can have it from the link: <a href="http://www.msaccesstips.com/2010/01/auto-numbering-in-query-column/">Auto-Numbering in Query Column</a>.</p>
<p>The above was only an introduction to what we are going to do here.&#160; What we have seen in the above Auto-numbering example is assigning sequence numbers for the entire query output records.&#160; But, what if we want separate sequence numbers for each category of records or records belongs to a particular group? </p>
<p><strong>For example</strong>: In a School the Headmaster would like to know who is the highest rank holder in each Subject in a particular Class/School.&#160; Or to find top 5 State-level student Rank holders of the Schools in each Subject.&#160; Or you have invited quotations for supplying electronic goods and you would like to know item-wise lowest Quotes from among several suppliers.</p>
<p>To do this we can write a VBA Function to work on a report source table with a new data field: <strong>Rank, </strong>to write out the rank list values.&#160; First, the Data Table must be prepared by combining information from input Tables/Queries etc.&#160; A sample image of a Students’ Table with several subjects is given below, ready for running our RankList() Program.</p>
<p>&#160;<a href="http://msaccesstips.com/uploaded_images/school-data1.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="School Data1" border="1" alt="School Data1" src="http://msaccesstips.com/uploaded_images/school-data1_thumb.jpg" width="321" height="322" /></a> </p>
<p>Our task is to organize the above data in a specified order and assign Rank numbers as 1,2,3 etc. based on the highest values in the <strong>Score</strong> field (sorted in Descending order) for each group of subjects in the <strong>Event</strong> field (sorted in Ascending order).&#160; This rank list is prepared for Class No.2 involving several schools in the area.</p>
<p>Table Name: SchoolTable</p>
<p>Sorting Order: <strong>Event</strong> (Ascending), <strong>Score</strong> (Descending), <strong>School </strong>(Ascending) – School field sorting optional</p>
<p>Function Call Syntax: RankList(TableName, Primary Sorting Field, Value Field, Optional Third Sorting Field)</p>
<p>Sample Function Call:<strong> RankList(“SchoolTable”,”Events”,”Score”,”School”)</strong></p>
<p>The RankList() Function Code is given below:</p>
<pre>Public Function RankList(ByVal TableName As String, _
                         ByVal Grp1Field As String, _
                         ByVal ValueField As String, _
                         Optional ByVal Grp2Field As String)
'-----------------------------------------------------------------
'Preparing Rank List
'Author : a.p.r.pillai
'Date   : August 2011
'Rights : All Rights Reserved by www.msaccesstips.com
'Remarks: Free to use in your Projects
'-----------------------------------------------------------------
'Parameter List:
'TableName  : Source Data Table
'Grp1Field  : Category Group to Sort on
'ValueField : On which to determine the Rank Order
'Grp2Field  : Sorted on for values with the same rank number
'-----------------------------------------------------------------
Dim db As Database, rst As Recordset, curntValue, prevValue
Dim srlRank As Byte, curntGrp1, prevGrp1
Dim prevGrp2, curntGrp2
Dim fld As Field, tbldef As TableDef, idx As Index
Dim FieldType As Integer

On Error Resume Next

Set db = CurrentDb
Set rst = db.OpenRecordset(TableName, dbOpenTable)

'Check for presence of Table Index &quot;MyIndex&quot;
'if not found then create
rst.Index = &quot;MyIndex&quot;

If Err &gt; 0 Then
   Err.Clear
   On Error GoTo RankList_Err

Set tbldef = db.TableDefs(TableName)
Set idx = tbldef.CreateIndex(&quot;MyIndex&quot;)

FieldType = rst.Fields(Grp1Field).Type
Set fld = tbldef.CreateField(Grp1Field, FieldType)
idx.Fields.Append fld

FieldType = rst.Fields(ValueField).Type
Set fld = tbldef.CreateField(ValueField, FieldType)
fld.Attributes = dbDescending ' Line not required for sorting in Ascending
idx.Fields.Append fld

FieldType = rst.Fields(Grp2Field).Type
Set fld = tbldef.CreateField(Grp2Field, FieldType)
idx.Fields.Append fld

rst.Close

tbldef.Indexes.Append idx
tbldef.Indexes.Refresh
Set rst = db.OpenRecordset(TableName, dbOpenTable)
rst.Index = &quot;MyIndex&quot;
End If

curntGrp1 = rst.Fields(Grp1Field)
prevGrp1 = curntGrp1
curntValue = rst.Fields(ValueField).Value
prevValue = curntValue

Do While Not rst.EOF
     srlRank = 1
     Do While (curntGrp1 = prevGrp1) And Not rst.EOF
       If curntValue &lt; prevValue Then
          srlRank = srlRank + 1
       End If
          rst.Edit
          rst![Rank] = srlRank
          rst.Update
          rst.MoveNext
          If Not rst.EOF Then
             curntGrp1 = rst.Fields(Grp1Field)
             prevValue = curntValue
             curntValue = rst.Fields(ValueField).Value
          End If
     Loop
     prevGrp1 = curntGrp1
     prevValue = curntValue
Loop
rst.Close
'Delete the Temporary Index
tbldef.Indexes.Delete &quot;MyIndex&quot;
tbldef.Indexes.Refresh

Set rst = Nothing
Set db = Nothing

RankList_Exit:
Exit Function

RankList_Err:
MsgBox Err &amp; &quot; : &quot; &amp; Err.Description, , &quot;RankList()&quot;
Resume RankList_Exit

End Function</pre>
<p>In the first part of the Program we check for the presence of an Index &#8216;MyIndex&#8217; in the input table. If not found then creates the Index, for temporary use.&#160; After creating the rank list on the table we delete the temporary Index “MyIndex” from the table. </p>
<p>Result of the run of RankList(&quot;SchoolTable&quot;,&quot;Events&quot;,&quot;Score&quot;,&quot;School&quot;) Function is given below.&#160; Check the <strong>Rank</strong> field values based on the Score field values of Event field.</p>
<p>&#160;</p>
<p>&#160;<a href="http://msaccesstips.com/uploaded_images/school-data2.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="School Data1 Sorted and Ranked" border="1" alt="School Data1 Sorted and Ranked" src="http://msaccesstips.com/uploaded_images/school-data2_thumb.jpg" width="324" height="319" /></a></p>
<p>The first two ranks for Accounting are obtained by City View School, 3rd rank by Krum School, 4,5 &amp; 6 awarded to Holiday School.&#160; Seventh rank is shared by City View and Holiday Schools.</p>
<p>Similarly, Current Events and Social Studies are also listed according to their order of ranks.</p>
<ul>
<li><a href="http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment Field in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/02/primarykey-usage-with-many-fields/">PrimaryKey usage with many fields</a> </li>
<li><a href="http://msaccesstips.com/2011/02/percentage-on-report-summary/">Percentage on Report Summary</a> </li>
<li><a href=" http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/09/preparing-rank-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy Onam to all our Readers</title>
		<link>http://msaccesstips.com/2011/09/happy-onam-to-all-our-readers/</link>
		<comments>http://msaccesstips.com/2011/09/happy-onam-to-all-our-readers/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 02:54:32 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[External Links]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/09/happy-onam-to-all-our-readers/</guid>
		<description><![CDATA[Image Source: www.dgreetings.com &#160; പുന്നെല്ലടകൊണ്ടടപ്രഥമന്‍ &#8211; അതില്‍ പൊന്തിക്കിടക്കുന്ന നാളികേരത്തുണ്ട് നെയ്യില്‍ വറുത്തിട്ട മുന്തിരി.. അണ്ടിപ്പരിപ്പുകള്‍ കണ്ണൊന്നിറുക്കി ; നാക്കിലയില്‍ കിടന്നെന്നെ കൊതിപ്പിക്കും പായസങ്ങള്‍&#8230;. Source: http://www.greetings.prokerala.com/ &#160; Wishing you Bountiful of Joy and abounding prosperity on the occasion of Thiruvonam Day. HAPPY ONAM!]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.dgreetings.com/newimages/onam/onam-02.jpg" /></p>
<p>Image Source: <a href="http://www.dgreetings.com">www.dgreetings.com</a></p>
<p>&#160;</p>
<p>പുന്നെല്ലടകൊണ്ടടപ്രഥമന്‍ &#8211; അതില്‍    <br />പൊന്തിക്കിടക്കുന്ന നാളികേരത്തുണ്ട്     <br />നെയ്യില്‍ വറുത്തിട്ട മുന്തിരി.. അണ്ടിപ്പരിപ്പുകള്‍     <br />കണ്ണൊന്നിറുക്കി ; നാക്കിലയില്‍ കിടന്നെന്നെ     <br />കൊതിപ്പിക്കും പായസങ്ങള്‍&#8230;.</p>
<p>Source: <a href="http://www.greetings.prokerala.com/">http://www.greetings.prokerala.com/</a></p>
<p>&#160;</p>
<p><em><font size="5">Wishing you Bountiful of Joy and abounding prosperity on the occasion of Thiruvonam Day.</font></em></p>
<p><em><font size="5">HAPPY ONAM!</font></em></p>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/09/happy-onam-to-all-our-readers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restoring disabled Full Menus Access2007</title>
		<link>http://msaccesstips.com/2011/08/restoring-disabled-full-menus-access2007/</link>
		<comments>http://msaccesstips.com/2011/08/restoring-disabled-full-menus-access2007/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 13:44:51 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Access2007]]></category>
		<category><![CDATA[Menus]]></category>
		<category><![CDATA[restore]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/08/restoring-disabled-full-menus-access2007/</guid>
		<description><![CDATA[When you develop an application, even if it is for your own use, always consider that each object you design is for someone else use. Then only we will be serious about giving a closer look at each control’s functions, their strength and drawbacks.&#160; Others many not treat each control on a Table, Form, Report [...]]]></description>
			<content:encoded><![CDATA[<p>When you develop an application, even if it is for your own use, always consider that each object you design is for someone else use. Then only we will be serious about giving a closer look at each control’s functions, their strength and drawbacks.&#160; Others many not treat each control on a Table, Form, Report etc. as we visualize their usage, the <a href="http://www.msaccesstips.com/2006/11/microsoft-access-security/">Users</a> may try to enter garbage into the data entry fields or may try to implement their own ideas, if they could, into the design of a <a href="http://www.msaccesstips.com/2007/06/control-screen-design/">Control</a> or Form and so on.</p>
<p>Let us take an example of a Date-of-Birth (or an Invoice <a href="http://www.msaccesstips.com/2008/05/list-box-and-date-part-one/">Date</a>) data entry field on a Form.&#160; If we leave this field open to accept any date value then it is likely that the user may make mistakes like entering a future date.&#160; To prevent such eventualities we must enable the built-in Validation checks on the value entered into the date field and warn the user about the mistake and force him to enter a valid value.</p>
<p>We can do this by setting <strong>Validation Rule </strong>and<strong> Validation Text</strong> property values of the <a href="http://www.msaccesstips.com/2010/02/microsoft-date-time-picker-control/">Date</a> Field.&#160; The <strong>Validation Rule</strong> property of the date field can be set with the expression: <strong>&lt;Date() </strong>to accept date values earlier than Today in the date-of-birth field<strong>. </strong>But, this expression is good only if we are prepared to accept date-of-birth values earlier than 100 years or more, otherwise we must set a lower bound value too, like<strong> &gt;=(DateAdd(“yyyy”,-100,Date()) and &lt;Date(). </strong><strong>&#160;</strong>To warn the user about the data entry error, the <strong>Validation Text</strong> property can be set with a message text like:<strong> <em>Future date is invalid and Age Limit 100 years</em></strong>.&#160; This is better if you implement it on the Table itself rather than on the <a href="http://www.msaccesstips.com/2010/02/form-and-report-open-arguments/">Form</a>.</p>
<p>It is equally important that Users are kept away from modifying objects like Forms, <a href="http://www.msaccesstips.com/2008/10/multiple-parameters-for-query/">Queries</a>, <a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3/">Reports</a>, <a href="http://msaccesstips.com/2011/04/macros-and-temporary-variables/">Macros</a> and VBA Programs.&#160; This is where we consider implementing <a href="http://www.msaccesstips.com/2006/11/microsoft-access-security/">User-level Security</a> in Microsoft Access.&#160; User-level security feature is available in Microsoft Access2003 or earlier versions only.</p>
<p>Another way of preventing users from straying out is to create <strong><a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars2/">Custom Menus</a> </strong>and<strong> Custom Tool bars</strong> for the Application and disable all built-in Menus and Toolbars, so that users are not able to get into object designs through the built in Menus.&#160; If you have designed customized Menus and Toolbars then you can disable the built-in Menus by removing the Check-marks in the <strong>Access Options</strong>.</p>
<blockquote><p><strong>Caution</strong>: Take a backup of the database before making the following changes otherwise you may not be able to get back into the database for making design changes yourself later.</p>
</blockquote>
<p>Select <strong>Office Button &#8211; -&gt; Access Options &#8211; -&gt; Current Database &#8211; -&gt; Ribbon and Toolbar Options</strong></p>
<p>Remove check-marks from the following options<strong>:</strong></p>
<ul>   </ul>
<ul>
<li>Allow Full Menus </li>
<li>Allow Default Shortcut Menus </li>
<li>Allow Built-in Toolbars </li>
</ul>
<p>After removing the check-marks you must close and reopen the database. Now, the customized Menus and Toolbars you have created are only available to the User. But, unfortunately even now your database objects Forms, <a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals/">Reports</a> etc. are not safe from unauthorized changes. It is true that they cannot right-click on an object in the <strong>Navigation Pane</strong> and go into design view, but they can if they select the VBA Module&#8217;s view from the <strong>Navigation Pane</strong>, browse for a Form/Report, select it and then select <strong>View Object </strong>option.</p>
<p> In the VBA Navigation Pane, <a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-3/">Forms</a> and Reports with VBA Sub-Routines behind them are visible to the Users. You can hide those objects by setting their <strong>Hide</strong> Option by right-clicking on the database Navigation Pane. If you don&#8217;t want Users to go into the <strong>Module</strong> View, through the Navigation Pane then you may remove the check-mark from the <strong>Display Navigation Pane</strong> option along with the Menu options explained above. Unless the User is too smart you can consider your Database Objects safe, but not safe enough from a smarter one. If some one familiar with the <a href="http://www.msaccesstips.com/2007/12/keyboard-shortcuts/">Keyboard Shortcuts</a> can open the VBA Module wide open by pressing <strong>ALT+F11</strong>. You can write the rest of the story yourself from there.&#160; Even If you keep the Navigation Pane of the VBA window hidden it can be opened by clicking on the Object browser button on the toolbar.&#160;
<p>Since, the User-level Security is not available in Access2007 and latter versions these are some of the methods available to you to implement security within an Access Database.</p>
<p>Once you remove the <strong>Full Menus</strong> Option it will be difficult for you to get back into the database for making changes to Forms, Reports etc. That&#8217;s why I said to take a back-up, to be on the safe side. </p>
<blockquote><p>Even during design time make it as a regular practice to take <a href="http://www.msaccesstips.com/2008/05/database-daily-backup/">back-ups</a> of the database, to save the work done so far, before starting with latest changes. If the database somehow got corrupted (or deleted by mistake) at any stage of design time you are safe from totally loosing your database.</p></blockquote>
<p>If you want the Full menus back again we can play a small trick to get back into the database and put the check-mark back into the <strong>Allow Full Menus</strong> Option, without going through directly from <strong>Office Button </strong>Menu as explained above.</p>
<ol>
<li>Open the database. </li>
<li>Press ALT+F11 to display the VBA Window </li>
<li>Press CTRL+G to display the Debugging Window (Immediate Window). </li>
<li>Type the following command in the Debug window and press Enter Key:
<pre class="alt1">CurrentDb.Properties(&quot;AllowFullMenus&quot;).Value = True</pre>
</li>
<li>Close and re-open the database again.&#160; </li>
</ol>
<p>Now, you can approach <strong>Access Options</strong> through <strong>Office Button</strong> (top left corner) and make changes to Options there.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7f7549af-15bb-44a7-973c-5d73c3c203b9" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/02/attachment-field-in-access2007/">Attachment Field in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/02/primarykey-usage-with-many-fields/">PrimaryKey usage with many fields</a> </li>
<li><a href="http://msaccesstips.com/2011/02/percentage-on-report-summary/">Percentage on Report Summary</a> </li>
<li><a href=" http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/report-design-in-access2007/">Report Design in Access2007</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/08/restoring-disabled-full-menus-access2007/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Workgroup Admin in Access2007</title>
		<link>http://msaccesstips.com/2011/08/running-workgroup-admin-in-access2007/</link>
		<comments>http://msaccesstips.com/2011/08/running-workgroup-admin-in-access2007/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 17:25:38 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Workgroup]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/08/running-workgroup-admin-in-access2007/</guid>
		<description><![CDATA[If you are serious about Microsoft Access User-level Security in earlier versions (.mdb files) of Access Databases and would like to continue&#160; using them in Access2007, with the security settings intact, then you should not convert them into Access2007 (.accdb).&#160; Access2007 Security concepts are totally different and once&#160; the .mdb files are upgraded into .accdb [...]]]></description>
			<content:encoded><![CDATA[<p>If you are serious about Microsoft Access User-level Security in earlier versions (.mdb files) of Access Databases and would like to continue&#160; using them in Access2007, with the security settings intact, then you should not convert them into Access2007 (.accdb).&#160; Access2007 Security concepts are totally different and once&#160; the .mdb files are upgraded into .accdb (Access2007) format the <a href="http://www.msaccesstips.com/2006/11/microsoft-access-security/">User-level Security</a> settings are lost and you will no longer be able to implement them in .accdb databases.&#160; </p>
<p>If you have already converted .mdb database into .accdb format and lost all user-level security settings then you are not totally lost with the database. If you have a <a href="http://www.msaccesstips.com/2008/05/database-daily-backup/">backup</a> of the earlier version database then you are lucky. All you have to do is to restore the database from backup and use it in Access2007 with User-level security intact.&#160; If you lost the backups too then you can save the Access2007 version database into an earlier Version 2002-2003 or 2000, by using the <strong>Save As…</strong>&#160; option from the <strong>Office Menu</strong> (top left corner menu) and select an appropriate .mdb database format and save the active Database as a new copy.</p>
<p>This will not restore the User-level security settings.&#160; You have to restore it manually from scratch by assigning access rights to each and every database object at User-Groups or individual <a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account/">User</a> level.</p>
<p>In either case you must <strong>Join </strong>the <strong>Workgroup Information File</strong> (a database with <strong>.mdw</strong> file extension) from Access2007, to attach your database <strong>Users/Groups</strong> to Access 2007 to use with your .mdb databases or to implement new security profiles on them.</p>
<p>When you open an .mdb database in Access2007 the <strong>Users and Permissions </strong>Menu is visible under<strong> Database Tools.</strong>&#160; But, your database Users or User-groups will not be visible under this option unless you <strong>Join </strong>the<strong> Wrokgroup Information File,</strong> you were using in earlier version of Access<strong>.</strong></p>
<p>In Access2003 there is an option under <strong>Tools—&gt;Security</strong> to run the <strong>Workgroup Administrator</strong> program to <strong>Create/Join</strong> a Workgroup Information File.&#160; In Microsoft Access2000 this program is located in the Language Folder (…\1033 for U.S. English) of MS-Office <font class="colrgreen"><i>C:\Program Files\</i><i>Microsoft Office</i><i>\Office\1033</i>\WrkgAdm.exe</font> to run and <strong>Join </strong>the<strong> Workgroup Information File.</strong></p>
<p>But, in Microsoft Access2007 none of these options are available, except running the following command from VBA:</p>
<pre class="alt1">DoCmd.RunCommand acCmdWorkgroupAdministrator </pre>
<p>You can run this command from the Debug Window (Immediate Window, <strong>Alt+F11</strong> then <strong>Ctrl+G</strong> to display) manually or from a <a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons/">Command Button</a> Click Event Procedure and <strong>Create</strong> a new <strong>Workgroup Information File </strong>or<strong> Join</strong> an existing one on Server. </p>
<p>Once you <strong>Join</strong> the Workgroup Information File you can start using the .mdb files with their User-level security in Microsoft Access2007 or restore the lost security settings manually.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0ede904e-833e-4388-b55c-77b1d8071461" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft+Security" rel="tag">Microsoft Security</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/02/primarykey-usage-with-many-fields/">PrimaryKey usage with many fields</a> </li>
<li><a href="http://msaccesstips.com/2011/02/percentage-on-report-summary/">Percentage on Report Summary</a> </li>
<li><a href=" http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/report-design-in-access2007/">Report Design in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/memo-field-text-formatting/">Memo Field Text Formatting</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/08/running-workgroup-admin-in-access2007/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apply Filter to Table directly</title>
		<link>http://msaccesstips.com/2011/08/apply-filter-to-table-directly/</link>
		<comments>http://msaccesstips.com/2011/08/apply-filter-to-table-directly/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 14:30:32 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[Table]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/08/apply-filter-to-table-directly/</guid>
		<description><![CDATA[Normally we use Filter settings on Forms/Reports to extract records on specific conditions. This can be achieved in several ways like adding a WHERE Condition (without the clause WHERE) in the parameter setting of the OpenForm Macro Action or in ApplyFilter Action parameter of a Macro or in the Docmd.OpenForm (like DoCmd.OpenForm &#34;myForm&#34;, acNormal, , [...]]]></description>
			<content:encoded><![CDATA[<p>Normally we use Filter settings on Forms/Reports to extract records on specific conditions. This can be achieved in several ways like adding a WHERE Condition (without the clause WHERE) in the parameter setting of the <strong><a href="http://www.msaccesstips.com/2007/05/open-forms-with-hyperlinks-in-listbox/">OpenForm</a></strong> Macro <strong>Action</strong> or in <strong>ApplyFilter</strong> Action parameter of a Macro or in the Docmd.OpenForm (like </p>
<p><font class="colrgreen">DoCmd.OpenForm &quot;myForm&quot;, acNormal, , &quot;EmployeeID Between 5 AND 10&quot;</font> command line in VBA) or<strong> Filter by Selection</strong> on Form or use a <a href="http://www.msaccesstips.com/2008/02/percentage-on-total-query/">Query</a> as Record Source and so on.</p>
<p>But, it is very unlikely&#160; that someone think of using the <strong>Filter</strong> Property of a Table directly to filter records when the Table is open in Datasheet View.&#160; If you are working with someone else project and found a table showing only few records in datasheet view but you are told that the table suppose to have hundreds of records in it and want to find out what happened to the rest of the records, then read on.</p>
<p>We will explore how this trick works on a Table, for a change.&#160; If you ever tried to set a Filter condition directly on a Form then you don&#8217;t need any extra help to do this on your own.&#160; To try out this we need some ready made data from Northwind.accdb sample database.&#160; You may try it out with your own table as well.</p>
<ol>
<li>Import the <strong>Order Details</strong>&#160; Table from Northwind.accdb sample database. </li>
<li>Open the Table in Design view. </li>
<li>Press <strong>F4 </strong>to display the Property Sheet of the Table.
<p><a href="http://msaccesstips.com/uploaded_images/table-filter.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="Table Filter Property" border="1" alt="Table Filter Property" src="http://msaccesstips.com/uploaded_images/table-filter_thumb.jpg" width="499" height="234" /></a> </p>
<p>     <strong>
<p>Table Property Sheet View</p>
<p>     </strong></li>
<li>Find the <strong><a href="http://www.msaccesstips.com/2009/04/filter-by-character-and-sort/">Filter</a></strong> Property and type <strong>[Order ID] Between 35 AND 45 </strong>into the property (in Access2007). Type <strong>[OrderID]</strong> <strong>Between 10249 AND 10251</strong> in earlier Access Versions. </li>
<li>Set the <strong>Filter On Load </strong>property value to <strong>Yes.</strong> </li>
<li>Save and close the Table Structure. </li>
<li>Open the Table in Datasheet View to see the Filter in action. </li>
</ol>
<p>The output records displayed are only of Order IDs between 35 and 45.&#160; If you design a <a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard/">Quick Form</a> or Report from this Table the Record Source property will be set with an SQL SELECT statement with the WHERE condition inserted from the <strong>Filter</strong> Property settings from the Table.&#160; But, if you modify the Filter condition on the Table later don&#8217;t expect to reflect that change on the <strong>Record Source</strong> SQL of <a href="http://www.msaccesstips.com/2008/12/custom-report-wizard/">Report</a> or Form automatically.</p>
<p>Like anything else in Microsoft Access If you would like to automate this through VBA, to change the filter criteria with the click of a button then here it is for you.&#160; But, there is a small problem which I will tell you later so that you will know how important it is.&#160; After all it is about setting a simple filter condition on the <strong>Filter </strong>Property of the Table Structure.</p>
<p>We can address the Filter Property of a Table in VBA either through the <em>front-door</em> approach or through the <em>back-door</em> method, so to speak.&#160; The front-door approach is addressing the Filter Property through the <strong>TableDef.Property.Filter</strong> path and the back-door approach is addressing through <strong>Container.Documents.Properties.Filter</strong> path.&#160; As you can see the second method is little bit lengthy, that is why I call it back-door method.&#160; We will try examples of both methods.</p>
<p>The second approach is very useful when working with Forms or <a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3/">Reports</a>, like taking a list of all Forms/Reports or want to change the name of a <a href="http://www.msaccesstips.com/2009/03/change-form-modes-on-user-profile/">Form</a> etc. You can refer an earlier blog post that creates a User-defined Property (Custom Property) to save values in it for opening a <a href="http://www.msaccesstips.com/2009/02/synchronized-floating-popup-form/">Form</a> with last-worked record to continue work from that record onwards, click <a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table/"><strong>here</strong></a> to find out more about it.</p>
<p><strong>Example-1</strong>:</p>
<ol>
<li>Copy and Paste the following VBA Code into a Standard Module of your Database.
<pre class="alt3">Public Function TableFilter1(ByVal OrderStart As Long, ByVal OrderEnd As Long)
Dim db As Database
Dim Tbldef As TableDef

Set db = CurrentDb

Set Tbldef = db.TableDefs(&quot;Order Details&quot;)
Tbldef.Properties(&quot;Filter&quot;).Value = &quot;[Order ID] &gt;=&quot; &amp; OrderStart &amp; &quot; AND [Order ID] &lt;=&quot; &amp; OrderEnd
Tbldef.Properties(&quot;FilterOnLoad&quot;).Value = True
db.TableDefs.Refresh

End Function</pre>
</li>
<li>Run the above sample Code from the Debug Window or from a <a href="http://www.msaccesstips.com/2008/03/double-action-command-button/">Command Button</a> Click Event Procedure like the sample run given below: </li>
</ol>
<pre class="alt1">TableFilter1 35,45</pre>
<p><strong>NB: </strong>The above Code and sample run is given for <strong>Order Details</strong> Table of Access2007.&#160; If you are using an earlier Access Version then change the <strong>[Order ID]</strong> name to <strong>[OrderID]</strong> (i.e. without a space between <strong>Order</strong> and <strong>ID)</strong> and in the sample run type <strong>TableFilter1 10249, 10251</strong> instead of <strong>35,45</strong> for OrderID range values.</p>
<blockquote>
<p>If you have not tried out the manual filter method explained above or removed the filter <a href="http://www.msaccesstips.com/2009/12/filter-with-buildcriteria-function/">criteria</a> setting from the <strong>Filter</strong> Property then you will run into problems with the above program reporting an Error <a href="http://www.msaccesstips.com/2008/03/sending-alerts-to-workstations/">message</a> stating that the <strong>Filter </strong>Property<strong> </strong>not found.</p>
<p>When you implement the VBA method see that an initial criteria setting is set in the <strong>Filter</strong> property of the Table.&#160; Without the criteria setting the <strong>Filter</strong> Property will not be visible in VBA.</p>
</blockquote>
<p><strong>Example-2</strong>:</p>
<p>Copy and Paste the following VBA Code into the Standard VBA Module and run the Code in the same way as <strong>Example-1</strong> with different set of OrderIDs:</p>
<pre class="alt3">Public Function TableFilter2(ByVal OrderStart As Long, ByVal OrderEnd As Long)
Dim db As Database, ctr As Container, doc As Document

Set db = CurrentDb

Set ctr = db.Containers(&quot;Tables&quot;)
Set doc = ctr.Documents(&quot;Order Details&quot;)
doc.Properties(&quot;Filter&quot;).Value = &quot;[Order ID] &gt;=&quot; &amp; OrderStart &amp; &quot; AND [Order ID] &lt;=&quot; &amp; OrderEnd
doc.Properties(&quot;FilterOnLoad&quot;).Value = True
doc.Properties.Refresh

End Function</pre>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9c616952-edc2-49f9-855f-22d3c267dd37" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/02/percentage-on-report-summary/">Percentage on Report Summary</a> </li>
<li><a href=" http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/report-design-in-access2007/">Report Design in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/memo-field-text-formatting/">Memo Field Text Formatting</a> </li>
<li><a href="http://msaccesstips.com/2011/01/sub-query-in-query-column-expressions/">Sub-Query in Query Column Expression</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/08/apply-filter-to-table-directly/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamic Dlookup in Query Column</title>
		<link>http://msaccesstips.com/2011/07/dynamic-dlookup-in-query-column/</link>
		<comments>http://msaccesstips.com/2011/07/dynamic-dlookup-in-query-column/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 13:56:06 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Queries]]></category>
		<category><![CDATA[Dynamic Lookup]]></category>
		<category><![CDATA[Query]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/07/dynamic-dlookup-in-query-column/</guid>
		<description><![CDATA[If we need only a single column value from a related table to incorporate into a Microsoft Access Query then we can use a DLookup() function to bring that value into the Query Column. Normally we place that Table also into the Query&#8217;s design surface, establish link between Primary Key of the main table and [...]]]></description>
			<content:encoded><![CDATA[<p>If we need only a single column value from a related table to incorporate into a Microsoft Access <a href="http://msaccesstips.com/2011/06/change-query-top-values-property-with-vba/">Query</a> then we can use a DLookup() function to bring that value into the <a href="http://msaccesstips.com/2011/01/sub-query-in-query-column-expressions/">Query</a> Column. Normally we place that Table also into the Query&#8217;s design surface, establish link between Primary Key of the main table and Foreign Key of the other table and place the required field into the query column. Here, we will examine an interesting solution to a small problem with a dlookup() function in a query column. The above method that normally we follow have some issues when implemented in the following situations, which we are going to explore.
<p>The DLookup(“TaxRate2005”,”tblTaxRates”,”[Product Code] = ‘” &amp; [ProductCode] &amp; “’”) Function is used in a Query Column to pick up <strong>Sale Tax Rate</strong> from the <strong>tblTaxRates</strong> Table, for each item sold, for calculating the Sale Tax Value for the actual Sale value.&#160; The Tax Rate will change every year during annual <a href="http://msaccesstips.com/2010/08/budgeting-and-control/">budgeting</a> of the government.&#160; The Company maintains the history of these changes and adds a new <strong>tax-rate-field</strong> with <strong>Year as Suffix</strong> to the tblTaxRates Table like: <strong>TaxRate2005</strong>, <strong>TaxRate2006</strong>, <strong>TaxRate2007</strong> etc.&#160; Take a look at the sample image given below:</p>
<p><a href="http://msaccesstips.com/uploaded_images/tax-rate.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="Tax Rate Table" border="1" alt="Tax Rate Table" src="http://msaccesstips.com/uploaded_images/tax-rate_thumb.jpg" width="423" height="182" /></a> </p>
<p>The Query Column name is <strong>TaxRate</strong> where the Dlookup() Function is inserted, irrespective of <strong>TaxRate2005</strong> or <strong>TaxRate2006</strong> or <strong>TaxRate2007</strong> is selected in the function parameter like: <font class="colrgreen">TaxRate:Dlookup(“TaxRate2005”,”tblName”,”Criteria”).&#160; </font>When we design a report we can use the report control name as <strong>TaxRate</strong> and no need to modify every time.</p>
<p>Check the sample Query result image given below:</p>
<p><a href="http://msaccesstips.com/uploaded_images/query-datasheet.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="Query Datasheet View" border="1" alt="Query Datasheet View" src="http://msaccesstips.com/uploaded_images/query-datasheet_thumb.jpg" width="405" height="173" /></a> </p>
<p>Now, assume that there are Orders placed during December with the applicable Tax Rate at that time. There are Orders placed for materials immediately after the budget implementation with revised sale tax rate.&#160; We have to prepare some invoices with previous year sale tax rates and others with current year rates.&#160; That means the Dlookup() function will look like<strong> Dlookup(“TaxRate2005”,” “,” “)</strong> for previous year and <strong>Dlookup(“TaxRate2006”,” “, “ “)</strong> for current year.&#160; The table name and criteria part is omitted for clarity. As you can see the first parameter of the function must be changed every time for printing previous year and current year invoices.</p>
<p>We cannot ask the <a href="http://www.msaccesstips.com/2006/11/add-users-to-security-groups/">User</a> to go in and change the Query design.&#160; There must be a way to define that particular parameter of the function dynamically to refer to different tax rate columns on the tblTaxRates.&#160; The solution is very simple, design a small Form with a Text Box and a Command button and let the user type the tax rate field name&#160; in the Text Box (or create a Combo Box if required) and click the <a href="http://www.msaccesstips.com/2009/01/command-button-animation-2/">Command Button</a> to refresh the Query and open the Report that uses this Query as record source.&#160; Sample image of the Query parameter <a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-3/">Form</a> is given below:</p>
<p><a href="http://msaccesstips.com/uploaded_images/invoice-param.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="Parameter Form View" border="1" alt="Parameter Form View" src="http://msaccesstips.com/uploaded_images/invoice-param_thumb.jpg" width="227" height="155" /></a> </p>
<p>The <a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins/">Textbox</a> name is <strong>Tax</strong> on the above form.&#160; With that in mind our Dlookup() function in the Order Details Query column will look like as given below:</p>
<pre class="alt1">TaxRate:DLookup([Forms]![InvoiceParam]![Tax],”tblTaxRates”,”[ProdCode]= '” &amp; [Product Code] &amp; “'”)</pre>
<p>In the criteria part the <strong>ProdCode</strong> field of tblTaxRate table should match with the (Product Code) field of the Products Table linked with the Order Details Table to return the tax rate value for each item on the Order Details table.</p>
<p>The sample SQL of the Query is given below:</p>
<pre class="alt3">SELECT [Order Details].[Order ID],
 Products.[Product Code],
 Products.[Product Name],
 [Order Details].Quantity,
 [Order Details].[Unit Price],
 [Quantity]*[Unit Price] AS SaleValue,
 Val(DLookUp([Forms]![InvoiceParam]![Tax],&quot;TaxRates&quot;,&quot;[ProdCode]='&quot; &amp; [Product Code] &amp; &quot;'&quot;)) AS TaxRate,
 [SaleValue]*[TaxRate] AS SaleTax,
 [SaleValue]+[SaleTax] AS TotalSaleValue
FROM Products INNER JOIN [Order Details] ON Products.ID = [Order Details].[Product ID];</pre>
<p>The <a href="http://www.msaccesstips.com/2008/04/transparent-command-button/">Command Button</a> Click Event Procedure can run the following Code to open the Sales Invoice <a href="http://www.msaccesstips.com/2008/12/custom-report-wizard/">Report</a> after refreshing the change on the Form:</p>
<pre class="alt1">Private Sub cmdRun_Click()
Me.Refresh
DoCmd.OpenReport &quot;SalesInvoice&quot;, acViewPreview
End Sub</pre>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5628a884-658d-4a27-9d87-355787344ff9" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
</p>
<ul>
<li><a href=" http://msaccesstips.com/2011/01/embedded-macros-in-access2007/">Embedded Macros in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/report-design-in-access2007/">Report Design in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/memo-field-text-formatting/">Memo Field Text Formatting</a> </li>
<li><a href="http://msaccesstips.com/2011/01/sub-query-in-query-column-expressions/">Sub-Query in Query Column Expression</a> </li>
<li><a href="http://msaccesstips.com/2010/12/getrows-function-and-exporting-data/">GetRows() Function and Exporting Data</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/07/dynamic-dlookup-in-query-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Watermark on MS-Access Reports</title>
		<link>http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/</link>
		<comments>http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 14:49:54 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Reports]]></category>
		<category><![CDATA[ms-access]]></category>
		<category><![CDATA[Water-Mark]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/</guid>
		<description><![CDATA[No matter what kind of database design you plan for your Company, reports (in text or Chart form) are the main output the external users expect from the application. The Charts can be with 2D design or can be in pretty 3D design with gradient colors which makes them more attractive to look at. In [...]]]></description>
			<content:encoded><![CDATA[<p>No matter what kind of database design you plan for your Company, reports (in text or Chart form) are the main output the external users expect from the application. The Charts can be with <a href="http://www.msaccesstips.com/2007/08/ms-access-and-graph-charts/">2D design</a> or can be in pretty <a href="http://www.msaccesstips.com/2007/09/ms-access-and-graph-charts2/">3D design</a> with <a href="http://www.msaccesstips.com/2009/04/form-background-with-gradient-color/">gradient colors</a> which makes them more attractive to look at. In either case the information in them must be meaningful and must serve their purposes. It is like the difference between a song sung by the bathroom singer and by a professional one. The lyrics is same but the listener definitely prefer the second choice.</p>
<p>You can design a report in minutes. Or you can design the same report giving personal attention to each and every control on the report for their placement, control size, font size, highlighting, heading, footer, summary lines and so on. It may take several hours before you are satisfied with the idea of presenting the report to the boss, stand back and look for the sign of appreciation appearing on his face.</p>
<p>Talking of controls and enhancements whey can&#8217;t we place a Watermark (a Company Logo or Company Name) on the Report Background to give the report a touch of class? It will not take much to do that. If you have an Image of your Company Logo (in .bmp format) with a very light gray scale color (like the image given below) you can easily implement this idea on your Report.</p>
<p><a href="http://msaccesstips.com/uploaded_images/watermark.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="Report Watermark" border="1" alt="Report Watermark" src="http://msaccesstips.com/uploaded_images/watermark_thumb.jpg" width="232" height="149" /></a> </p>
<ol>
<li>Open the Report in Design View. </li>
<li>Display the Report&#8217;s Property Sheet (<strong>F4</strong>). </li>
<li>Look for the <strong>Picture</strong> <a href="http://www.msaccesstips.com/2008/08/database-connection-string-properties/">Property</a> and click on the property to select it. </li>
<li>Click on the Build button (<strong>. . .</strong> at the right end of the property) to browse for the Watermark image on the disk and select it. </li>
<li>With the following three <a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties/">property</a> settings of the Report you can display and print the watermark image in various ways:
<ul>
<li>PictureAlignment = 2 (center) </li>
<li>PictureTiling = False </li>
<li>PictureSizeMode = 3 (zoom) </li>
</ul>
</li>
</ol>
<p>When you load the Watermark picture in the background, with the above property settings, the Report Print Preview looks like the image given below:</p>
<p>&#160;<a href="http://msaccesstips.com/uploaded_images/rptwatermark.jpg"><img style="border-right-width: 1px; display: inline; border-top-width: 0px; border-bottom-width: 1px; border-left-width: 0px" title="Watermark Preview" border="1" alt="Watermark Preview" src="http://msaccesstips.com/uploaded_images/rptwatermark_thumb.jpg" width="200" height="249" /></a> </p>
<p>Print the Report on <a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2/">Printer</a> or convert into MS-Access Snapshot format (.snp) or into PDF.</p>
<p>The above manual work made easier for any Report with the VBA Code given below:</p>
<pre>Public Function ReportWaterMark()
Dim rpt As Report, txtRpt As String
Dim imgPath As String

txtRprt = &quot;&quot;
imgPath = &quot;&quot;

Do While txtRpt = &quot;&quot; Or imgPath = &quot;&quot;
  If txtRpt = &quot;&quot; Then
   txtRpt = Nz(InputBox(&quot;Give Report Name:&quot;, &quot;Report Water Mark&quot;), &quot;&quot;)
  End If
  If imgPath = &quot;&quot; Then
   imgPath = Nz(InputBox(&quot;Watermark Image PathName:&quot;, &quot;Report Water Mark&quot;), &quot;&quot;)
  End If
Loop

DoCmd.OpenReport txtRpt, acViewDesign

Set rpt = Reports(txtRpt)
With rpt
    .Picture = imgPath
    .PictureAlignment = 2
    .PictureTiling = False
    .PictureSizeMode = 3
End With
DoCmd.Close acReport, txtRpt, acSaveYes
Set rpt = Nothing

DoCmd.OpenReport txtRpt, acViewPreview

End Function</pre>
<p>Copy and paste the above code into a Standard VBA Module and save the code.&#160; You can run this program from a <a href="http://www.msaccesstips.com/2008/04/transparent-command-button/">Command Button</a> Click Event Procedure like:</p>
<pre class="alt1">Private Sub cmdWMark_Click()
    ReportWaterMark
End Sub</pre>
<p>When you run the main program it will prompt for the <strong><a href="http://www.msaccesstips.com/2008/09/no-data-and-report-error/">Report</a> Name</strong> and for the <strong>Watermark Image location with image name</strong>. You must note down these information somewhere before you attempt to run the program. You need to run this program only once for a <a href="http://www.msaccesstips.com/2007/08/highlighting-reports/">report</a>. The image stays as the backgroud picture on the report till you run the program again to change the image.</p>
<p>Try the following property settings to see how they appear on the Report Print Preview:</p>
<pre class="alt1">
    .PictureAlignment = 0
    .PictureTiling = True
    .PictureSizeMode = 0</pre>
<pre class="alt1">    .PictureAlignment = 2
    .PictureTiling = False
    .PictureSizeMode = 1</pre>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:64a3bcab-24e1-4f49-8eeb-66f32520e825" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Microsoft" rel="tag">Microsoft</a></div>
<ul>
<li><a href="http://msaccesstips.com/2011/01/report-design-in-access2007/">Report Design in Access2007</a> </li>
<li><a href="http://msaccesstips.com/2011/01/memo-field-text-formatting/">Memo Field Text Formatting</a> </li>
<li><a href="http://msaccesstips.com/2011/01/sub-query-in-query-column-expressions/">Sub-Query in Query Column Expression</a> </li>
<li><a href="http://msaccesstips.com/2010/12/getrows-function-and-exporting-data/">GetRows() Function and Exporting Data</a> </li>
<li><a href="http://msaccesstips.com/2010/12/create-menus-with-macros-2/">Create Menus with Macros-2</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/07/creating-watermark-on-ms-access-reports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iSeries Date in Imported Data</title>
		<link>http://msaccesstips.com/2011/07/iseries-date-in-imported-data/</link>
		<comments>http://msaccesstips.com/2011/07/iseries-date-in-imported-data/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 08:47:34 +0000</pubDate>
		<dc:creator>a.p.r.pillai</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[iSeries Date]]></category>

		<guid isPermaLink="false">http://msaccesstips.com/2011/07/iseries-date-in-exported-data/</guid>
		<description><![CDATA[If you have IBM iSeries Machine (IBM AS400) and taking raw data from there for customized report preparation in Microsoft Access then you might have noticed that the date value they provide will look like an ordinary number in mmddyyyy format (07092011) or in ddmmyyyy (09072011) or like yyyymmdd (20110709).&#160; We cannot directly use this [...]]]></description>
			<content:encoded><![CDATA[<p>If you have IBM iSeries Machine (IBM AS400) and taking raw data from there for customized report preparation in Microsoft Access then you might have noticed that the date value they provide will look like an ordinary number in mmddyyyy format (07092011) or in ddmmyyyy (09072011) or like yyyymmdd (20110709).&#160; We cannot directly use this number as a date in a <a href="http://www.msaccesstips.com/2008/02/percentage-on-total-query/">Query</a> or anywhere else for analysis purposes. It should be converted into a real date before we can use them.</p>
<p>Let us try one or two conversion examples.</p>
<p>Example-1: mmddyyyy</p>
<p>x = 07092011 or x=”07092011”</p>
<p>y = July 09, 2011 (internal representation of the actual date number is 40733)</p>
<p>Conversion expression:</p>
<p>y = DateSerial(Right(x,4),Left(x,2),Mid(x,3,2))</p>
<p>OR</p>
<p>y = DateValue(Left(x,2) &amp; &quot;-&quot; &amp; Mid(x,3,2) &amp; &quot;-&quot; &amp; Right(x,4))</p>
<p>Depending on the input date format (Asian, USA or ANSI) usage order of <strong>Left(), Right()</strong> and <strong>Mid()</strong> functions in the <strong>DateSerial()</strong> or <strong>DateValue() </strong>Functions will change.&#160; But, writing the above expressions every time when we put the data into <a href="http://www.msaccesstips.com/2008/02/union-query/">Queries</a> is not advisable and time consuming too.&#160; The easiest way to overcome this is to create User-defined functions with the above expressions and call the function from the Query <a href="http://www.msaccesstips.com/2008/07/column-chart-and-vba/">Column</a> or from anywhere these date numbers are involved in calculations or comparisons etc.</p>
<p>Let us create the following simple <a href="http://www.msaccesstips.com/2007/09/useful-report-functions/">Functions</a> that will make our life easier with these numbers on the long run.</p>
<p>Function: <strong>DMY_N2D(ByVal ddmmyyyy as Variant) As Date</strong>&#160;</p>
<p>Converts from date number in ddmmyyyy format into a real date number.&#160; The input number can be in Long Number format (09072011 or 9072011) or in text format “09072011”.&#160; _N2D stands for <em>Number to Date.&#160; </em>The first three characters of the function name DMY indicates the order of Day, Month &amp; Year elements of the input date number.</p>
<pre>Public Function DMY_N2D(ByVal ddmmyyyy As Variant) As Date
&#39;------------------------------------------------------------------
&#39;Converts Numbers (in ddmmyyyy format) 09072011 into a Date Number
&#39;Author : a.p.r.pillai
&#39;Date   : Sept. 1999
&#39;Rights : All Rights Reserved by www.msaccesstips.com
&#39;------------------------------------------------------------------
Dim strN2D As String

On Error GoTo DMY_N2D_Err

strN2D = Format(ddmmyyyy, &quot;00000000&quot;) ' add 0 at the left side, if 7 digit number

DMY_N2D = DateSerial(Right(strN2D, 4), Mid(strN2D, 3, 2), Left(strN2D, 2))

DMY_N2D_Exit:
Exit Function

DMY_N2D_Err:
MsgBox Err.Description,, &quot;DMY_N2D()&quot;
Resume DMY_N2D_Exit
End Function</pre>
<p>When the input Number is in mmddyyyy format:</p>
<pre>Public Function MDY_N2D(ByVal mmddyyyy As Variant) As Date
&#39;------------------------------------------------------------------
&#39;Converts Numbers (in mmddyyyy format) 07092011 into a Date Number
&#39;Author : a.p.r.pillai
&#39;Date&#160;&#160; : Sept. 1999
&#39;Rights : All Rights Reserved by www.msaccesstips.com
&#39;------------------------------------------------------------------
Dim strN2D As String 

On Error GoTo MDY_N2D_Err 

strN2D = Format(mmddyyyy, &quot;00000000&quot;) ' add 0 at the left side, if 7 digit number

MDY_N2D = DateSerial(Right(strN2D, 4), Left(strN2D, 2), Mid(strN2D, 3, 2)) 

MDY_N2D_Exit:
Exit Function 

MDY_N2D_Err:
MsgBox Err.Description,, &quot;MDY_N2D()&quot;
Resume MDY_N2D_Exit
End Function</pre>
<p>When the date number is in yyyymmdd (ANSI) format: </p>
<pre>Public Function YMD_N2D(ByVal yyyymmdd As Variant) As Date
&#39;------------------------------------------------------------------
&#39;Converts Numbers (in yyyymmdd format) 20110709 into a Date Number
&#39;Author : a.p.r.pillai
&#39;Date   : Sept. 1999
&#39;Rights : All Rights Reserved by www.msaccesstips.com
&#39;------------------------------------------------------------------
Dim strN2D As String

On Error GoTo YMD_N2D_Err

YMD_N2D = DateSerial(Left(strN2D, 4),Mid(strN2D, 5, 2),Right(strN2D, 2))

DMY_N2D_Exit:
Exit Function

YMD_N2D_Err:
MsgBox Err.Description,, &quot;YMD_N2D()&quot;
Resume YMD_N2D_Exit
End Function</pre>
<hr />
<ul>
<li><a href="http://msaccesstips.com/2011/01/memo-field-text-formatting/">Memo Field Text Formatting</a> </li>
<li><a href="http://msaccesstips.com/2011/01/sub-query-in-query-column-expressions/">Sub-Query in Query Column Expression</a> </li>
<li><a href="http://msaccesstips.com/2010/12/getrows-function-and-exporting-data/">GetRows() Function and Exporting Data</a> </li>
<li><a href="http://msaccesstips.com/2010/12/create-menus-with-macros-2/">Create Menus with Macros-2</a> </li>
<li><a href="http://msaccesstips.com/2010/11/create-menus-with-macros/">Create Menus with Macros</a> </li>
</ul>
<hr />
]]></content:encoded>
			<wfw:commentRss>http://msaccesstips.com/2011/07/iseries-date-in-imported-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

