<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-34083602</atom:id><lastBuildDate>Thu, 11 Mar 2010 04:59:24 +0000</lastBuildDate><title>LEARN MS-ACCESS TIPS AND TRICKS</title><description>Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.</description><link>http://www.msaccesstips.com/</link><managingEditor>noreply@blogger.com (a.p.r. pillai)</managingEditor><generator>Blogger</generator><openSearch:totalResults>185</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-716492860328059285</guid><pubDate>Sun, 07 Mar 2010 16:00:00 +0000</pubDate><atom:updated>2010-03-07T20:22:34.962+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>security advanced</category><title>Users Group and Permissions</title><description>&lt;br /&gt;&lt;br /&gt;When you create a new &lt;a href="http://www.msaccesstips.com/2006/11/convert-oldversion-workgroup-file.shtml"&gt;Workgroup Information File&lt;/a&gt;, as part of the &lt;a href="http://www.msaccesstips.com/2006/11/microsoft-access-security.shtml"&gt;Microsoft Access Security&lt;/a&gt; implementation, it is important that the following two steps you follow immediately after creating the new Workgroup Information File (&lt;b&gt;.mdw&lt;/b&gt;) file on priority basis:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a new Administrator UserID (say &lt;b&gt;myAdmin&lt;/b&gt; or whatever name you like) for you and join yourself as a member of the &lt;b&gt;Admins&lt;/b&gt; Group Account.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Remove the default &lt;b&gt;Admin&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account.shtml"&gt;User Account&lt;/a&gt; from the &lt;b&gt;Admins&lt;/b&gt; Group.  If this is not done then your database is not secured and anybody can open and use it when MS-Office Software is re-installed.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;From now on you must use the new UserID &lt;b&gt;myAdmin&lt;/b&gt; to login as Administrator of the Databases that uses this new common Workgroup Information File. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One more thing, the databases that you create after login with the new User Name &lt;b&gt;myAdmin&lt;/b&gt;, this User Account will be the &lt;b&gt;&lt;a href="http://www.msaccesstips.com/2006/11/view-or-transfer-ownership.shtml"&gt;Owner&lt;/a&gt;&lt;/b&gt; of those Databases and other Objects within it. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Remember the &lt;b&gt;Owner&lt;/b&gt; of the &lt;b&gt;Database&lt;/b&gt; has full authority on all Objects including Administrative Authority (like a member of the &lt;b&gt;Admins&lt;/b&gt; Group) to assign permissions to Database Objects and to transfer Ownership of Objects to other Users as well.  When the ownership of a particular Object is given to an ordinary User, he has full authority on that object to &lt;b&gt;Run, Modify&lt;/b&gt; or &lt;b&gt;Delete&lt;/b&gt; that object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You must implement Object-wise access rights to &lt;a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account.shtml"&gt;User Groups&lt;/a&gt; before you install your Project for public use.  This is done manually from &lt;b&gt;Tools - -&gt;Security - -&gt;User and Group Permissions…&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This procedure also has a first priority step, like the above two steps I have mentioned about the Workgroup Information File.  That is to remove &lt;b&gt;All Permissions&lt;/b&gt; of &lt;b&gt;all Objects&lt;/b&gt; for the &lt;b&gt;Users&lt;/b&gt; Group Account. Without this step whatever permission settings you assign to the Objects (Forms, Report and so on) will have no effect and Users will have full authority for Design Changes or whatever they want to do with them.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is done manually and takes some time to go through all groups of Objects to remove all permissions of &lt;b&gt;Users&lt;/b&gt; Group Account.  Since, this step is required for all new Projects I thought it is better to automate it and here it is for you to try it out.  This program is written purely on my own experience with the VBA based procedures and you may use it at your own risk&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the following Program into a Standard Module and save it.&lt;/li&gt; &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function DefaultUsersGrp(ByVal DatabasePathName As String) As Boolean&lt;br /&gt;'----------------------------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date     : March-2010&lt;br /&gt;'Purpose: Remove All Permissions from Users Group Security Account&lt;br /&gt;'All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'----------------------------------------------------------------------------&lt;br /&gt;Dim wsp As Workspace, db As Database, ctr As Container&lt;br /&gt;Dim GroupName As String, doc As Document&lt;br /&gt;Dim L4 As String&lt;br /&gt;&lt;br /&gt;Const DB_FULLNO = &amp;H60000&lt;br /&gt;Const OBJS_FULLNO = &amp;H2FE01&lt;br /&gt;&lt;br /&gt;'Remove All Permissions on Containers &amp; documents&lt;br /&gt;'for USERS Group&lt;br /&gt;&lt;br /&gt;On Error GoTo DefaultUsersGrp_Err&lt;br /&gt;&lt;br /&gt;Set wsp = DBEngine.Workspaces(0)&lt;br /&gt;Set db = wsp.OpenDatabase(DatabasePathName)&lt;br /&gt;&lt;br /&gt;wsp.Groups.Refresh&lt;br /&gt;&lt;br /&gt;GroupName = &amp;quot;Users&amp;quot;&lt;br /&gt;&lt;br /&gt;Set ctr = db.Containers(&amp;quot;Databases&amp;quot;)&lt;br /&gt;Set doc = ctr.Documents(&amp;quot;MSysDb&amp;quot;)&lt;br /&gt;doc.UserName = GroupName&lt;br /&gt;doc.Permissions = DB_FULLNO&lt;br /&gt;&lt;br /&gt;Set ctr = db.Containers(&amp;quot;Tables&amp;quot;)&lt;br /&gt;GoSub SetPermission&lt;br /&gt;&lt;br /&gt;Set ctr = db.Containers(&amp;quot;Forms&amp;quot;)&lt;br /&gt;GoSub SetPermission&lt;br /&gt;&lt;br /&gt;Set ctr = db.Containers(&amp;quot;Reports&amp;quot;)&lt;br /&gt;GoSub SetPermission&lt;br /&gt;&lt;br /&gt;Set ctr = db.Containers(&amp;quot;Scripts&amp;quot;)&lt;br /&gt;GoSub SetPermission&lt;br /&gt;&lt;br /&gt;Set ctr = db.Containers(&amp;quot;Modules&amp;quot;)&lt;br /&gt;GoSub SetPermission&lt;br /&gt;&lt;br /&gt;DefaultUsers_Grp = False&lt;br /&gt;&lt;br /&gt;DefaultUsers_Grp_Exit:&lt;br /&gt;   Set db = Nothing&lt;br /&gt;   Set wsp = Nothing&lt;br /&gt;Exit Function&lt;br /&gt;&lt;br /&gt;SetPermission:&lt;br /&gt;For Each doc In ctr.Documents&lt;br /&gt;    doc.UserName = GroupName&lt;br /&gt;    If ctr.Name = &amp;quot;Tables&amp;quot; Then&lt;br /&gt;        L4 = Left$(docName, 4)&lt;br /&gt;        If L4 = &amp;quot;MSys&amp;quot; Or L4 = &amp;quot;~sq_&amp;quot; Then&lt;br /&gt;          GoTo nextloopxxx&lt;br /&gt;        End If&lt;br /&gt;    End If&lt;br /&gt;    doc.Permissions = OBJS_FULLNO&lt;br /&gt;nextloopxxx:&lt;br /&gt;Next&lt;br /&gt;Return&lt;br /&gt;&lt;br /&gt;DefaultUsersGrp_Err:&lt;br /&gt;MsgBox Err &amp; &amp;quot;: &amp;quot; &amp;amp; Err.Description&lt;br /&gt;DefaultUsersGrp = True&lt;br /&gt;Resume DefaultUsersGrp_Exit&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Remember this Program is run for an external Database that you would like to remove &lt;b&gt;All Permissions&lt;/b&gt; of all Objects for the &lt;b&gt;Users&lt;/b&gt; Group Account.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Before you run this Program, open the Database that you are targeting and check the current permission settings of all Objects for the &lt;b&gt;Users&lt;/b&gt; Group Account.  Try the program on a copy of the original Database you are targeting.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the Database with the above Code, if you have closed it.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Press &lt;b&gt;Alt+F11&lt;/b&gt; to display the &lt;b&gt;VBA&lt;/b&gt; Editing Window and press &lt;b&gt;Ctrl+G&lt;/b&gt; to display the &lt;b&gt;Debug Window&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Type the following and press &lt;b&gt;Enter&lt;/b&gt; Key:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class=”colrgreen”&gt;DefaultUsersGrp &amp;quot;C:\My Documents\myTest.mdb&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Replace the database Pathname in quotes with your own database name.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;You may run the Program from a &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Button&lt;/a&gt; Click &lt;b&gt;Event Procedure&lt;/b&gt; from a Form.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open your Test Database and check the current status of the permissions settings of &lt;b&gt;Users&lt;/b&gt; Group Account. The check marks from all the permission options you will find disappeared.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/03/users-group-and-permissions.shtml&amp;amp;title=Users+Group+and+Permissions"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-716492860328059285?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/03/users-group-and-permissions.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-3710310878206175494</guid><pubDate>Mon, 01 Mar 2010 12:25:00 +0000</pubDate><atom:updated>2010-03-01T17:12:12.379+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>security advanced</category><title>Create Security Group Account with VBA</title><description>Last week we have learned how to create a &lt;a href="http://www.msaccesstips.com/2006/11/microsoft-access-security.shtml"&gt;Microsoft Access Security&lt;/a&gt; &lt;b&gt;User Account&lt;/b&gt;(SMITHJOHN) with VBA and learned how to join him as a member of the default &lt;a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account.shtml"&gt;Group Account&lt;/a&gt; &lt;b&gt;Users&lt;/b&gt;.  The &lt;b&gt;Users&lt;/b&gt; and &lt;b&gt;Admins&lt;/b&gt; Group Accounts are already present in the default &lt;b&gt;Workgroup Information File&lt;/b&gt; (Sytem.mdw) or in the new &lt;a href="http://www.msaccesstips.com/2006/11/convert-oldversion-workgroup-file.shtml"&gt;Workgroup Information File&lt;/a&gt; that you create separately.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we need to group Users under different categories (like MANAGERS, SUPERVISORS, DATA ENTRY OPERATORS, EDITORS and so on) so that their access rights to different objects can be defined differently at group level and any number of Users can be joined to these groups.  Once we clearly define group level access rights all Users joined to that group will inherit the privileges assigned to that Group.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One User can be joined to more than one Group as well.  A sample image of the &lt;b&gt;User and Group Accounts&lt;/b&gt; control is given below and we will examine how the User &lt;b&gt;SMITHJOHN&lt;/b&gt;&amp;#39;s Security credentials are appearing in the Control.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/usergrp-715313.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 298px;" src="http://www.msaccesstips.com/uploaded_images/usergrp-715308.jpg" border="0" alt="image showing User SMITHJOHN in the User and Group Account Control" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;In the User &lt;b&gt;Name&lt;/b&gt; control SMITHJOHN is selected. The Group Account name &lt;b&gt;Users&lt;/b&gt; is appearing under the label &lt;b&gt;Member of&lt;/b&gt; indicating that he belongs to that Group Account only. If you look under the &lt;b&gt;Available Group&lt;/b&gt; List you can see that the &lt;b&gt;Users &lt;/b&gt;Group Account is appearing there also.  Unlike the &lt;b&gt;Users&lt;/b&gt; Group Account other Group Accounts shown there are created manually for different Group of Users.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we want to make the User SMITHJOHN as a member of the VEHGRP then all we have to do is to select the VEHGRP under the &lt;b&gt;Available Groups&lt;/b&gt; List and click on the &lt;b&gt;Add&gt;&gt;&lt;/b&gt; Command Button to copy that name into the &lt;b&gt;Member of: &lt;/b&gt; List.  Whatever Access Privileges we have assigned to the &lt;b&gt;VEHGRP&lt;/b&gt; will be automatically available to the selected User in the &lt;b&gt;User Name&lt;/b&gt; control above.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At the end part of last week&amp;#39;s main program &lt;b&gt;CreateUser()&lt;/b&gt; the following code segment is doing exactly what we did manually in the above paragraph: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=”alt3”&gt;&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;   With wsp&lt;br /&gt;     Set tempGrp = .Users(UsrName).CreateGroup(&amp;quot;Users&amp;quot;)&lt;br /&gt;         .Users(UsrName).Groups.Append tempGrp&lt;br /&gt;         .Users.Refresh&lt;br /&gt;   End With&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But, to do that first we must create the Group Account VEHGRP by going through the same procedure like creating a new User Account from the &lt;b&gt;Groups&lt;/b&gt; Tab on the Control above.  So, the VEHGRP Account was created at some point of time earlier. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here, we will learn: &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;How to create a Microsoft Access Security Group Account &lt;b&gt;MANAGER &lt;/b&gt; with VBA.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;How to join the User SMITHJOHN to the MANAGER Group Account with VBA.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt; The User and Group Accounts are not case sensitive. Here they are given in Upper Case for legibility only.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following Program creates the MANAGER Group Account in the &lt;b&gt;Available Groups&lt;/b&gt; List:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CreateUserGrp()&lt;br /&gt;'---------------------------------------------------------------------&lt;br /&gt;'Creating a Security Group Account&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : March-2010&lt;br /&gt;'All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'---------------------------------------------------------------------&lt;br /&gt;Dim newGrp As Group, wsp As Workspace&lt;br /&gt;Dim tempGrp As Group&lt;br /&gt;Dim grpName As String, grpID As String&lt;br /&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;&lt;br /&gt;Set wsp = DBEngine.Workspaces(0)&lt;br /&gt;&lt;br /&gt;    grpName = &amp;quot;MANAGER&amp;quot;&lt;br /&gt;    grpID = &amp;quot;MGR13579&amp;quot;&lt;br /&gt;  &lt;br /&gt;With wsp&lt;br /&gt;    Set newGrp = .CreateGroup(grpName, grpID)&lt;br /&gt;               .Groups.Append newGrp&lt;br /&gt;               &lt;br /&gt;    If Err = 3390 Then&lt;br /&gt;      MsgBox &amp;quot;Group Name : &amp;quot; &amp;amp; grpName &amp;amp; vbCr &amp;amp; vbCr &amp;amp; &amp;quot;Group PID     : &amp;quot; &amp;amp; grpID &amp;amp; vbCr &amp;amp; vbCr &amp;amp; &amp;quot;Account Name already Exists..! &amp;quot;&lt;br /&gt;      Err.Clear&lt;br /&gt;    End If&lt;br /&gt;    &lt;br /&gt;      .Groups.Refresh&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the above program into a Standard Module.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click somewhere in the middle of the Code and press &lt;b&gt;F5&lt;/b&gt; Key to Run the Code and to create the MANAGER Group Account.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;You may select &lt;b&gt;Tools - -&gt; Security - -&gt; User and Group Accounts…(from the Database Window).&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select SMITHJOHN in the User Name List.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Check for the name MANAGER in the &lt;b&gt;Available Groups&lt;/b&gt; List and you will find it there.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/usergrp1-759093.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 297px;" src="http://www.msaccesstips.com/uploaded_images/usergrp1-759081.jpg" border="0" alt="image showing MANAGER Group Account created" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;But, the User SMITHJOHN is not yet added to the MANAGER Group Account and this is where we need to add the code-segment, given at the top of this page, to the main program.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The revised VBA Code given below to create the MANAGER Group Account and to add the User SMITHJOHN to this Group Account.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CreateUserGrp()&lt;br /&gt;'---------------------------------------------------------------------&lt;br /&gt;'Creating a Security Group Account&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : March-2010&lt;br /&gt;'All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'---------------------------------------------------------------------&lt;br /&gt;Dim newGrp As Group, wsp As Workspace&lt;br /&gt;Dim tempGrp As Group&lt;br /&gt;Dim grpName As String, grpID As String&lt;br /&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;&lt;br /&gt;Set wsp = DBEngine.Workspaces(0)&lt;br /&gt;&lt;br /&gt;    grpName = &amp;quot;MANAGER&amp;quot;&lt;br /&gt;    grpID = &amp;quot;MGR13579&amp;quot;&lt;br /&gt;  &lt;br /&gt;With wsp&lt;br /&gt;    Set newGrp = .CreateGroup(grpName, grpID)&lt;br /&gt;               .Groups.Append newGrp&lt;br /&gt;               &lt;br /&gt;    If Err = 3390 Then&lt;br /&gt;      MsgBox &amp;quot;Group Name : &amp;quot; &amp;amp; grpName &amp;amp; vbCr &amp;amp; vbCr &amp;amp; &amp;quot;Group PID     : &amp;quot; &amp;amp; grpID &amp;amp; vbCr &amp;amp; vbCr &amp;amp; &amp;quot;Account Name already Exists..! &amp;quot;&lt;br /&gt;      Err.Clear&lt;br /&gt;    End If&lt;br /&gt;    &lt;br /&gt;      .Groups.Refresh&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;'Add the User SMITHJOHN to the MANAGER Group Account&lt;br /&gt;usrName = &amp;quot;SMITHJOHN&amp;quot;&lt;br /&gt;&lt;br /&gt;   With wsp&lt;br /&gt;     Set tempGrp = .Users(usrName).CreateGroup(grpName)&lt;br /&gt;         .Users(usrName).Groups.Append tempGrp&lt;br /&gt;         .Users.Refresh&lt;br /&gt;   End With&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you run the revised Code again it will show an Error Message saying that the MANAGER Group Account already exists, because you have already run this code once. But, the remaining part of the code will run.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you open the &lt;b&gt;User and Group Accounts&lt;/b&gt; control now and select SMITHJOHN in the &lt;b&gt;User Name&lt;/b&gt; Control you can see that MANAGER group name is now appearing under the &lt;b&gt;Member of&lt;/b&gt; List indicating that the User is a member of the MANAGER Group Account.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See the sample image given below.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/usergrp2-707959.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 296px;" src="http://www.msaccesstips.com/uploaded_images/usergrp2-707953.jpg" border="0" alt="image with User is added to the MANAGER Group Account" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/03/create-security-group-account-with-vba.shtml&amp;amp;title=Create+Security+Group+Account+with+VBA"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/11/ms-access-and-data-processing.shtml"&gt;MS-Access and Data Processing&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-3.shtml"&gt;Form Bookmarks and Data Editing-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml"&gt;Form Bookmarks and Data Editing-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml"&gt;Form Bookmarks and Data Editing&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml"&gt;Run Slide-show when Form is idle&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-3710310878206175494?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/03/create-security-group-account-with-vba.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-1890644257014068315</guid><pubDate>Mon, 22 Feb 2010 12:36:00 +0000</pubDate><atom:updated>2010-02-22T17:25:00.943+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>security advanced</category><title>Creating User-Account with VBA</title><description>For creating a Microsoft Access User-Account manually in the Workgroup Information File (&lt;b&gt;.mdw&lt;/b&gt;) we go through &lt;b&gt;Tools - -&gt; Security - -&gt; User and Group Accounts - -&gt;User Name&lt;/b&gt; Option.  There, we need to provide a unique &lt;b&gt;User Name&lt;/b&gt; and a &lt;b&gt;Personal ID&lt;/b&gt; to create a User-Account.&lt;br /&gt;&lt;br /&gt;We have seen this procedure in the &lt;a href="http://www.msaccesstips.com/2006/11/microsoft-access-security.shtml"&gt;Security&lt;/a&gt; Main Menu.  The &lt;b&gt;UserID&lt;/b&gt;s, &lt;b&gt;PersonalID&lt;/b&gt;s, &lt;b&gt;Work-GroupID&lt;/b&gt;s and &lt;b&gt;Passwords&lt;/b&gt; of Users are maintained in the Workgroup Information File (a database with &lt;b&gt;.mdw&lt;/b&gt; extension and the &lt;b&gt;Default Workgroup Information File&lt;/b&gt; is &lt;b&gt;System.mdw&lt;/b&gt;).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Access privileges to Database Objects are stored within the database itself. Both these two parts of the Combination-Lock (&lt;b&gt;UserID&lt;/b&gt; with &lt;b&gt;PersonalID&lt;/b&gt; in &lt;a href="http://www.msaccesstips.com/2006/11/convert-oldversion-workgroup-file.shtml"&gt;Workgroup Information File&lt;/a&gt; and access rights to individual objects for each User/Group maintained within database) works together. Individual User gets access to Objects with the right UserID, Password and PersonalID. PersonalId is a very important element of the User-Profile and we need it again, if we ever need to recreate a Workgroup Information File, when the existing one is corrupted or lost.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;UserIDs and GroupIDs can be created and managed only by Administrators (a member of the &lt;b&gt;Admins&lt;/b&gt; Group with Administrator privileges) of the Database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First, let us create a test User Account manually.  Go through the following procedure for creating a User Account manually and see how it is done?&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;User Name:  &lt;b&gt;JOHNSMITH&lt;/b&gt; (maximum 20 characters)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Personal ID:  &lt;b&gt;JS123456&lt;/b&gt;   (4 to 20 Alphanumeric characters)&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Visit the Page: &lt;a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account.shtml"&gt;Create MS-Access User-Account&lt;/a&gt; for more details.&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Tools - -&gt; Security - -&gt; User and Group Accounts&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click &lt;b&gt;New…&lt;/b&gt; in the &lt;b&gt;Users&lt;/b&gt; Tab.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Type &lt;b&gt;JOHNSMITH&lt;/b&gt; in the &lt;b&gt;Name&lt;/b&gt; control.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Type &lt;b&gt;JS123456&lt;/b&gt; in the &lt;b&gt;Personal ID&lt;/b&gt; control.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click &lt;b&gt;OK&lt;/b&gt; to complete the procedure.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;By default all Users will be members of the &lt;b&gt;Users&lt;/b&gt; Group.  If the User is going to be part of any other &lt;a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account.shtml"&gt;User-Groups&lt;/a&gt; then that &lt;b&gt;Group Name&lt;/b&gt; must be selected from the &lt;b&gt;Available Groups&lt;/b&gt; List and &lt;b&gt;Add&lt;/b&gt; it to the &lt;b&gt;Member of&lt;/b&gt; list at the right hand side.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us see how to create a User-Account with VBA, except the procedure explained for joining the User to a particular Group.  We will examine the procedure for joining the User to a Group later, after learning to create a Group Account with VBA.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following VBA Code creates a User Account with the User Name: &lt;b&gt;SMITHJOHN&lt;/b&gt;, with the Personal ID: &lt;b&gt;SJ78901&lt;/b&gt; and with an initial Password: &lt;b&gt;SMITHJOHN&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;Public Function CreateUsers()&lt;br /&gt;'---------------------------------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : Feb-2010&lt;br /&gt;'All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'Other Ref: http://www.msaccesstips.com/2006/11/create-msaccess-user-account.shtml&lt;br /&gt;'---------------------------------------------------------------------------------&lt;br /&gt;Dim wsp As Workspace&lt;br /&gt;Dim newUser As User, tempGrp As Group&lt;br /&gt;Dim UsrName As String, PersonalID As String&lt;br /&gt;Dim Password As String&lt;br /&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;&lt;br /&gt;Set wsp = DBEngine.Workspaces(0)&lt;br /&gt;&lt;br /&gt;    UsrName = &amp;quot;SMITHJOHN&amp;quot; ' 1 to 20 characters.&lt;br /&gt;    PersonalID = &amp;quot;SJ78901&amp;quot; 'upto 4 to 20 alphaumeric characters&lt;br /&gt;    Password = &amp;quot;SMITHJOHN&amp;quot; 'upto 14 characters except NULL&lt;br /&gt;    &lt;br /&gt;'Create User Account with personalID&lt;br /&gt;   Set newUser = wsp.CreateUser(UsrName, PersonalID, Password)&lt;br /&gt;   wsp.Users.Append newUser&lt;br /&gt;   &lt;br /&gt;   If Err = 3390 Then&lt;br /&gt;      MsgBox &amp;quot;User Name : &amp;quot; &amp;amp; UsrName &amp;amp; vbCr &amp;amp; vbCr &amp;amp; &amp;quot;User PID    : &amp;quot; &amp;amp; PersonalID &amp;amp; vbCr &amp;amp; vbCr &amp;amp; &amp;quot;Account Name already Exists..! &amp;quot;&lt;br /&gt;      Err.Clear&lt;br /&gt;      Exit Function&lt;br /&gt;   End If&lt;br /&gt;   wsp.Users.Refresh&lt;br /&gt;   &lt;br /&gt;'Users Group must be created and joined the&lt;br /&gt;'User to it. When created manually this step&lt;br /&gt;'(for Users Group)is done automatically.&lt;br /&gt;   With wsp&lt;br /&gt;     Set tempGrp = .Users(UsrName).CreateGroup(&amp;quot;Users&amp;quot;)&lt;br /&gt;         .Users(UsrName).Groups.Append tempGrp&lt;br /&gt;         .Users.Refresh&lt;br /&gt;   End With&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When we create a User-ID manually we can only set a password for the User after opening a new MS-Access Application window and by going through the Menu &lt;b&gt;Tools- -&gt;Security- -&gt;User and Group Accounts- - &gt;&lt;/b&gt; and log-in without a password and select &lt;b&gt;Change Logon Password&lt;/b&gt; Tab of the Dialog Control and set a new Password. &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the above Code into a Standard Module and save it.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click somewhere in the middle of the Code and press &lt;b&gt;F5&lt;/b&gt; to Run the Code and create the User Account in the active Workgroup Information File.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Tools - -&gt;Security- -&gt;User and Group Accounts&lt;/b&gt; and check for the User Name &lt;b&gt;SMITHJOHN&lt;/b&gt; in the list.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;The User-Names are in alphabetical order.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can check for the presence of a particular &lt;b&gt;User Name&lt;/b&gt; in the active Workgroup Information File with the following VBA Code:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function Check4UserAccount(ByVal strUsrName As String) As Boolean&lt;br /&gt;'------------------------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : Feb-2010&lt;br /&gt;'All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;Dim WS As Workspace, msg As String&lt;br /&gt;Dim UsrName As String, K As User, Flag As Boolean&lt;br /&gt;&lt;br /&gt;Set WS = DBEngine.Workspaces(0)&lt;br /&gt;&lt;br /&gt;'All the Users belong to the Common Group 'Users'&lt;br /&gt;Flag = False&lt;br /&gt;With WS.Groups(&amp;quot;Users&amp;quot;)&lt;br /&gt;        For Each K In .Users&lt;br /&gt;                  If K.Name = strUsrName Then&lt;br /&gt;                          Flag = True&lt;br /&gt;                          Exit For&lt;br /&gt;                  End If&lt;br /&gt;        Next&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;If flag Then&lt;br /&gt;     MsgBox &amp;quot;User Name: &amp;quot; &amp;amp; strUsrName &amp;amp; &amp;quot; Already Exists! &amp;quot;&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Check4UserAccount = flag&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Type the following in the Debug Window (Immediate Window) and press &lt;b&gt;Enter&lt;/b&gt; Key to run the above Code:&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;Check4UserAccount &amp;quot;SMITHJOHN&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;If you have not run the first program to create the User Account &lt;b&gt;SMITHJON&lt;/b&gt; then to test the second Program, Call the above function with the &lt;b&gt;Admin&lt;/b&gt; User Name. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Type the following in the Debug Window (Immediate Window) and press &lt;b&gt;Enter&lt;/b&gt; Key:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;Check4UserAccount &amp;quot;Admin&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/02/creating-user-account-with-vba.shtml&amp;amp;title=Creating+User-Account+with+VBA"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-3.shtml"&gt;Form Bookmarks and Data Editing-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml"&gt;Form Bookmarks and Data Editing-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml"&gt;Form Bookmarks and Data Editing&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml"&gt;Run Slide-show when Form is idle&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml"&gt;Filter Function Output in ListBox-2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-1890644257014068315?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/02/creating-user-account-with-vba.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-1973238291728572798</guid><pubDate>Sun, 14 Feb 2010 05:29:00 +0000</pubDate><atom:updated>2010-02-14T10:00:20.267+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Microsoft Date Time Picker Control</title><description>We have learned how to use Calendar Control for easy entry of Date Values into Fields on &lt;a href="http://www.msaccesstips.com/2007/10/ms-access-and-mail-merge.shtml"&gt;Form&lt;/a&gt; through the earlier Article: &lt;a href="http://www.msaccesstips.com/2007/07/animated-floating-calendar.shtml"&gt;Animated Floating Calendar&lt;/a&gt;.  We have used a single Calendar Control for several Date Fields by moving the Calendar Control automatically near the selected Date Field with unfolding animation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have used this method to save space on the Form otherwise we need to place several Calendar Controls linked to each date field on the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now we have a better ActiveX Control – &lt;b&gt;Microsoft Date Time Picker&lt;/b&gt; – a Calendar Control that almost looks like a &lt;a href="http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml"&gt;Combo Box&lt;/a&gt; on Form and easy to use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us get into a simple example to learn how to use this Calendar for a Date Field on a Form.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Import the following Objects from &lt;font class=”colrgreen”&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; sample database:&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Table: &lt;b&gt;Employees&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Form:  &lt;b&gt;Employees&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;Employees&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form.shtml"&gt;Form&lt;/a&gt; in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the &lt;b&gt;Company Info&lt;/b&gt; Tab.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;ActiveX Control…&lt;/b&gt; from &lt;b&gt;Insert&lt;/b&gt; Menu.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Microsoft Date and Timer Picker Control&lt;/b&gt; from the displayed list and click &lt;b&gt;OK&lt;/b&gt; to create a control on the Form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Move the control near the &lt;b&gt;HireDate&lt;/b&gt; Field and resize it as shown on the sample design of the Form given below:&lt;/li&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/datetimepicker-738119.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 232px;" src="http://www.msaccesstips.com/uploaded_images/datetimepicker-738115.jpg" border="0" alt="Date Time Picker: Design View" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;We must know few simple rules that go with this Control to use it with Date Fields.&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;We can set the &lt;b&gt;Control Source&lt;/b&gt; Property of &lt;b&gt;Date Time Picker&lt;/b&gt; to &lt;b&gt;HireDate&lt;/b&gt; and remove the existing HireDate Field. &lt;br /&gt;&lt;li&gt;The &lt;b&gt;HireDate&lt;/b&gt; field cannot be blank.  When you make a record current with HireDate Field blank or attempt to add a new record the &lt;b&gt;Date Time Picker&lt;/b&gt; will show an Error Message: &lt;b&gt;&lt;i&gt;Can&amp;#39;t set value to NULL when CheckBox Property=FALSE. &lt;/i&gt;&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/datetimepicker1-798737.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 233px;" src="http://www.msaccesstips.com/uploaded_images/datetimepicker1-798734.jpg" border="0" alt="Date Time Picker: Calendar View" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The Error message indicates that HireDate field cannot be left blank or you cannot remove Date Value from a field and make it blank unless you set the &lt;b&gt;CheckBox Property&lt;/b&gt; of the Date and Time Picker Control to &lt;b&gt;Yes&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;So, first thing first, ensure that the Date Time Picker Control you have added to the Form is in selected state or click to select it, display the Property Sheet (&lt;b&gt;View - -&gt; Properties&lt;/b&gt; or &lt;b&gt;Alt+Enter&lt;/b&gt;) of the Calendar &lt;a href="http://www.msaccesstips.com/2007/06/control-screen-design.shtml"&gt;Control&lt;/a&gt; and change the &lt;b&gt;Control Source&lt;/b&gt; Property Value to &lt;b&gt;HireDate&lt;/b&gt; and change the &lt;b&gt;CheckBox&lt;/b&gt; Property Value to &lt;b&gt;Yes&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;When you move to a particular record the Calendar will automatically move to the date earlier recorded in the &lt;b&gt;HireDate&lt;/b&gt; Field.  If you want to change the existing &lt;b&gt;HireDate&lt;/b&gt; then move the &lt;a href="http://www.msaccesstips.com/2007/07/calendar-and-toolbars.shtml"&gt;Calendar&lt;/a&gt; to the desired Year and Month and click on the required date.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;When you move to a record with &lt;b&gt;HireDate&lt;/b&gt; Field value &lt;b&gt;NULL&lt;/b&gt; the Check-Mark disappears and the &lt;b&gt;HireDate&lt;/b&gt; field looks like &lt;b&gt;disabled&lt;/b&gt; indicating that it is empty but the field shows the date value of last record accessed.  If you click on the drop down control of the Calendar to open it then the date value, shown from last accessed record will be entered into the &lt;b&gt;HireDate&lt;/b&gt; field immediately, whether you want it or not. You can remove the &lt;b&gt;CheckMark&lt;/b&gt; to empty the field or select correct date from the Calendar to overwrite the wrong value.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;If you prefer to set Date by incrementing or decrementing individual segment (day/month/year) of the Date value, like you do on a Digital Clock, then you may change the &lt;b&gt;UpDown&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Property&lt;/a&gt; Value to Yes. This will change the Drop-down control of the Calendar to a Spin Button &lt;a href="http://www.msaccesstips.com/2007/06/control-screen-menu-design.shtml"&gt;Control&lt;/a&gt; and the normal Calendar View will not be available.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;You may click on the &lt;b&gt;Day&lt;/b&gt; Segment of the Date value and use the Spin Button Control of the &lt;b&gt;Date Time Picker&lt;/b&gt; to increase or decrease the value to the desired level.  Use the same method for &lt;b&gt;Month&lt;/b&gt; and &lt;b&gt;Year&lt;/b&gt; Values.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;You may experiment with the Date Time Picker Control, keeping those points I have mentioned above, to understand the behavior of the Calendar control better.&lt;/li&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/datetimepicker2-739796.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 209px;" src="http://www.msaccesstips.com/uploaded_images/datetimepicker2-739793.jpg" border="0" alt="Date Time Picker: Time Format" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;li&gt;If you want to enter &lt;b&gt;Time&lt;/b&gt; rather than Date into a field from the &lt;b&gt;Date Time Picker&lt;/b&gt; then change the &lt;b&gt;Format&lt;/b&gt; Property Value to &lt;b&gt;2&lt;/b&gt;.  This will automatically change the &lt;b&gt;UpDown&lt;/b&gt; Control to &lt;b&gt;Yes&lt;/b&gt; and the Spin Button control appear in place of the drop-down control and these can be used to set each segment (hh:mm:ss AM/PM) of the Time Value individually as explained above for date.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/02/microsoft-date-time-picker-control.shtml&amp;amp;title=Microsoft+Date+and+Time+Picker"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml"&gt;Form Bookmarks and Data Editing-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml"&gt;Form Bookmarks and Data Editing&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml"&gt;Run Slide-show when Form is idle&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml"&gt;Filter Function Output in ListBox-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml"&gt;Filter Function Output in ListBox&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-1973238291728572798?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/02/microsoft-date-time-picker-control.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-788428438321648519</guid><pubDate>Fri, 05 Feb 2010 07:25:00 +0000</pubDate><atom:updated>2010-02-05T12:17:50.886+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess reports</category><title>Form and Report Open Arguments</title><description>While opening a &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Report&lt;/a&gt; or Form we can pass several Optional Values as Run-Time Arguments to control the output on the Report or to change the &lt;a href="http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml"&gt;Form&lt;/a&gt; Open Mode depending on the User&amp;#39;s Profile.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;For example: &lt;/b&gt; If the Current User belongs to a particular &lt;a href="http://www.msaccesstips.com/2006/11/add-users-to-security-groups.shtml"&gt;Users&lt;/a&gt; Group, in the &lt;a href="http://www.msaccesstips.com/2006/11/microsoft-access-security.shtml"&gt;Security&lt;/a&gt; Workgroups, who has only enough privilege to view the data and not to Add or &lt;a href="http://www.msaccesstips.com/2008/11/data-editing-and-security-issues.shtml"&gt;Edit&lt;/a&gt; then we can open the Form in Read-only mode otherwise in Normal Mode, when the Current User attempts to open the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The following Code checks whether the Current User belongs to a particular User Group.  The following Code of &lt;b&gt;CheckGroup()&lt;/b&gt; Function must be copied into a Standard Module in your Database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CheckGroup(ByVal strUsr As String, grpName As String) As String&lt;br /&gt;'-----------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : Feb-2010&lt;br /&gt;'URL    : www.msaccesstips.com&lt;br /&gt;'Remarks: All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'-----------------------------------------------------&lt;br /&gt;Dim wsp As Workspace&lt;br /&gt;Dim GrpArray() As Variant, grpcnt As Integer&lt;br /&gt;Dim GrpOut As Variant, j As Integer&lt;br /&gt;&lt;br /&gt;Set wsp = DBEngine.Workspaces(0)&lt;br /&gt;&lt;br /&gt;grpcnt = wsp.Users(strUsr).Groups.Count - 1&lt;br /&gt;ReDim GrpArray(0 To grpcnt) As Variant&lt;br /&gt;&lt;br /&gt;'User may belong to more than one User Group&lt;br /&gt;'Create an Array of Group Names&lt;br /&gt;For j = 0 To grpcnt&lt;br /&gt;    GrpArray(j) = wsp.Users(strUsr).Groups(j).Name&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;'Compare Admins with the Array List&lt;br /&gt;'if matches then 'Admins' will be output in grpout Array&lt;br /&gt;GrpOut = Filter(GrpArray(), grpName, True)&lt;br /&gt;&lt;br /&gt;CheckGroup = GrpOut(0)&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;b&gt;CheckGroup()&lt;/b&gt; Function must be called from a &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; Click Event Procedure (we will do this at the end of this Article) as shown below to check and returns the &lt;a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account.shtml"&gt;User Group&lt;/a&gt; Name to open the &lt;a href="http://www.msaccesstips.com/2007/12/find-or-filter-data-on-form.shtml"&gt;Form&lt;/a&gt; in a particular Mode.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=”alt3”&gt;&lt;br /&gt;Private Sub cmdOpenForm_Click()&lt;br /&gt;Dim strGrp&lt;br /&gt;&lt;br /&gt;strGrp = CheckGroup(CurrentUser, &amp;quot;Admins&amp;quot;)&lt;br /&gt;&lt;br /&gt;If strGrp = &amp;quot;Admins&amp;quot; Then&lt;br /&gt;    DoCmd.OpenForm &amp;quot;Products&amp;quot;, acNormal, , , acFormReadOnly&lt;br /&gt;Else&lt;br /&gt;    DoCmd.OpenForm &amp;quot;Products&amp;quot;, acNormal&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;CheckGroup()&lt;/b&gt; program creates an &lt;a href="http://www.msaccesstips.com/2008/11/sum-min-max-avg-paramarray.shtml"&gt;Array&lt;/a&gt; of Work Groups of the User and checks whether the User belongs to &lt;b&gt;Admins&lt;/b&gt; Group and returns the result.  If the result value is &lt;b&gt;Admins&lt;/b&gt; then the &lt;b&gt;Products&lt;/b&gt; Form is open in Read-Only Mode otherwise in Normal Mode. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Workgroups Array creation is necessary because a particular User can belong to one or more Workgroups, like &lt;b&gt;Admins, Users&lt;/b&gt; (default), &lt;b&gt;Supervisor, Manager, Editor&lt;/b&gt; or any other group in the &lt;b&gt;Workgroup Information File&lt;/b&gt;(database.mdw), which he/she has been joined to. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Filter()&lt;/b&gt; Function compares the text &amp;quot;Admins&amp;quot; in the array elements and if found it is output into the &lt;b&gt;GrpOut(0) &lt;/b&gt; element. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We cannot use the &lt;b&gt;Filter()&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/12/rounding-function-mround-of-excel.shtml"&gt;Function&lt;/a&gt; in Form Module Sub-Rotuine, because it will clash with the Form &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Property&lt;/a&gt; name &lt;b&gt;Filter&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Coming back to the Open Arguments of Form and Reports we can pass the name of a &lt;a href="http://www.msaccesstips.com/2008/07/opening-dbase-files-directly.shtml"&gt;Query&lt;/a&gt; as &lt;b&gt;Filter&lt;/b&gt; Argument or a WHERE condition without the word &lt;b&gt;WHERE&lt;/b&gt;. But, there is another parameter known as &lt;b&gt;Open Argument (OpenArgs) &lt;/b&gt; through which you can pass a value to the Report or Form and read it back in the Class Module of Report or Form from the same variable &lt;b&gt;OpenArgs&lt;/b&gt; and use it for whatever purpose you passed it. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We try a simple example to learn the usage of this parameter.  We need few objects from the &lt;font class=”colrgreen”&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; sample database.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Import the following from the Northwind.mdb sample database:&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Table: &lt;b&gt;Products&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Table: &lt;b&gt;Categories&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Query: &lt;b&gt;Products by Category&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Report: &lt;b&gt;Products by Category&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Open a new Form and create a Combo Box with the &lt;b&gt;Category Name&lt;/b&gt; alone from the &lt;b&gt;Categories&lt;/b&gt; Table. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt; A sample Form image is given below for reference.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/openargs-744089.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 201px;" src="http://www.msaccesstips.com/uploaded_images/openargs-744086.jpg" border="0" alt="Open Arguments Form Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Select the Combo Box and display its Property Sheet (&lt;b&gt;View - -&gt; Properties&lt;/b&gt; or press &lt;b&gt;Alt+Enter&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt;  Property value to &lt;b&gt;cboCategory&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a Command Button and change its &lt;b&gt;Name&lt;/b&gt; Property value to &lt;b&gt;cmdOpen&lt;/b&gt; and the &lt;b&gt;Caption&lt;/b&gt; Property Value to &lt;b&gt;Open Report&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;EventProcedure&lt;/b&gt; in the &lt;b&gt;On Click&lt;/b&gt; Event Property and click on the build (&lt;b&gt;…&lt;/b&gt;) button to open the Class Module of the Form with the empty Sub-Routine lines.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the following VBA Code overwriting the existing line or copy and paste the middle line alone:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=”alt1”&gt;&lt;br /&gt;Private Sub cmdOPen_Click()&lt;br /&gt;   DoCmd.OpenReport &amp;quot;Products by Category&amp;quot;, acViewPreview, , , , Nz(Me!cboCategory, &amp;quot;&amp;quot;)&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save the Form with the name &lt;b&gt;Open Argument Demo&lt;/b&gt; or any other name you prefer.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Products by Category&lt;/b&gt; Report in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Class Module (&lt;b&gt;View - -&gt; Code&lt;/b&gt;)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following Code into the Class Module:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Private Sub Report_Open(Cancel As Integer)&lt;br /&gt;Dim strFilter As String&lt;br /&gt;&lt;br /&gt;If IsNull([OpenArgs]) Then&lt;br /&gt;   Exit Sub&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Report.Title.Caption = Report.Title.Caption &amp;amp; &amp;quot; (&amp;quot; &amp;amp; [OpenArgs] &amp;amp; &amp;quot;)&amp;quot;&lt;br /&gt;&lt;br /&gt;strFilter = &amp;quot;CategoryName = '&amp;quot; &amp;amp; [OpenArgs] &amp;amp; &amp;quot;'&amp;quot;&lt;br /&gt;Report.Filter = strFilter&lt;br /&gt;Report.FilterOn = True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save the Report with the Code.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;Open Argument Demo&lt;/b&gt; Form in Normal View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select a Product Category Name (say &lt;b&gt;Beverages&lt;/b&gt;) in the Combo Box.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the &lt;b&gt;Open Report&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Products by Category&lt;/b&gt; Report will open with only &lt;b&gt;Beverages&lt;/b&gt; items on the Report and the heading label modified to show the Product category Name.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Make the Combo box value empty by deleting the current value and click on the &lt;b&gt;Open Report&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Button&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;This time all the Products by Category will appear on the Report and the heading will remain without any change. We are testing the presence of some values in the &lt;b&gt;OpenArgs&lt;/b&gt; Variable in the Report Open Event Procedure, if it is &lt;b&gt;Null&lt;/b&gt; then terminate the Sub-Routine. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Do the following to try the first two Programs given on the top of this page:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;Open Argument Demo&lt;/b&gt; Form in Design View. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a second Command Button on the Form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Property Sheet of the Command Button (&lt;b&gt;View - -&gt; Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt; Property value to &lt;b&gt;cmdOpenForm&lt;/b&gt; and change the &lt;b&gt;Caption&lt;/b&gt; Property Value as &lt;b&gt;Open Form&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Class Module (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the second Program from the top into the Module and save the &lt;b&gt;Open Argument Demo&lt;/b&gt; Form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a Tabular type Form for Products Table and name the Form as &lt;b&gt;Products&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;Open Argument Demo&lt;/b&gt; Form and click on the &lt;b&gt;Open Form&lt;/b&gt; Command Button.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If you have not implemented Microsoft Access Security, you are by default the &lt;b&gt;Admin&lt;/b&gt; User, a member of the &lt;b&gt;Admins&lt;/b&gt; Group, and the &lt;b&gt;Products&lt;/b&gt; Form will open in &lt;b&gt;Read-Only&lt;/b&gt; mode.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/02/form-and-report-open-arguments.shtml&amp;amp;title=Form+and+Report+Open+Arguments"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml"&gt;Form Bookmarks and Data Editing&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml"&gt;Run Slide-show when Form is idle&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml"&gt;Filter Function Output in ListBox-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml"&gt;Filter Function Output in ListBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;Dynamic List Box Contents&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-788428438321648519?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/02/form-and-report-open-arguments.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-4450439274668995205</guid><pubDate>Thu, 28 Jan 2010 13:47:00 +0000</pubDate><atom:updated>2010-01-28T18:16:40.309+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccessprocess</category><title>Indexing and Sorting with VBA</title><description>A Table is normally created with a &lt;b&gt;Primary Key&lt;/b&gt; or &lt;b&gt;Index&lt;/b&gt; to arrange the records into certain order to view or process.  &lt;b&gt;Primary Key&lt;/b&gt; or &lt;b&gt;Index&lt;/b&gt; can have one or more fields, in order to make the Key Values Unique, if this is not possible with a single field.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you open the Employees Table from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; sample Database in design view  you can see that the &lt;b&gt;EmployeeID&lt;/b&gt; Field is defined as Primary Key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To create an Index manually and to define it as Primary Key:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Open the Table in design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click at the left side of the Field Name to select it.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the Indexes Toolbar Button.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;You may give any suitable name in the &lt;b&gt;Index Name&lt;/b&gt; Field replacing  &lt;b&gt;PrimaryKey&lt;/b&gt;, if you would like to do so.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;If the Record Values in the selected field are not unique then you can select more data fields (up to a maximum of ten Fields) to form Unique Key for the Primary Key.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You may click and drag over the Fields to select them (if they are adjoining fields) or click on each field by holding the &lt;b&gt;Ctrl&lt;/b&gt; Key to select fields randomly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above procedure is for creating a PrimaryKey Index for the Table.  We can create more than one Index for a Table.   But, only one Index can be active at one time.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can activate an existing Index of a Table or create new Index through VBA and use it for data processing.  We will learn here how to create a new Index with the name &lt;b&gt;myIndex&lt;/b&gt; for a Table through VBA, activate it and use it for data processing and delete it at the end of the process.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; We must validate the presence of &lt;b&gt;myIndex&lt;/b&gt; in the Indexes collection of the Table, if found then activate it, otherwise create &lt;b&gt;myIndex&lt;/b&gt; and activate it for data processing.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will use &lt;b&gt;Orders&lt;/b&gt; and &lt;b&gt;Order details&lt;/b&gt; Table from &lt;b&gt;Northwind.mdb&lt;/b&gt; sample database.  We will organize the &lt;b&gt;Order Details&lt;/b&gt; Table in Order Number  sequence so that Order-wise&lt;b&gt; Total Value&lt;/b&gt; of all items can be calculated and updated on the same Order record in &lt;b&gt;Orders&lt;/b&gt; Table.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Following are the data processing steps which we follow in the VBA Routine to update the &lt;b&gt;Orders&lt;/b&gt; Table with order-wise Total Value from &lt;b&gt;Order details&lt;/b&gt; Table:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Orders&lt;/b&gt; Table for Update Mode.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Orders Details&lt;/b&gt; Table for &lt;b&gt;Input&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Check for the presence of &lt;b&gt;myIndex&lt;/b&gt; in the &lt;b&gt;Order Details&lt;/b&gt; Table, if found then activate it, otherwise create &lt;b&gt;myIndex&lt;/b&gt; and activate it as current Index.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Initialize &lt;b&gt;Total&lt;/b&gt; to Zero.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Read the first record from the &lt;b&gt;Order details&lt;/b&gt; Table.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Calculate Total Value of the item using the Expression: &lt;font class=”colrgreen”&gt;Quantity * ((1-Discount%)*UnitPrice)&lt;/font&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Add the Value to the &lt;b&gt;Total&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Read the next record and compare with the earlier Order Number, if same then repeat &lt;b&gt;step-6&lt;/b&gt; and &lt;b&gt;7&lt;/b&gt; until the Order Number changes or no more records to process from &lt;b&gt;Order Details&lt;/b&gt; Table.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Find the record with the Order Number in &lt;b&gt;Orders&lt;/b&gt; Table.&lt;/li&gt; &lt;br /&gt;&lt;li&gt;If found then edit and update&lt;b&gt;Total&lt;/b&gt; into the &lt;b&gt;TotalValue&lt;/b&gt; Field in &lt;b&gt;Orders&lt;/b&gt; Table.&lt;/li&gt; &lt;br /&gt;&lt;li&gt;Check for &lt;b&gt;E&lt;/b&gt;nd &lt;b&gt;O&lt;/b&gt;f &lt;b&gt;F&lt;/b&gt;ile (&lt;b&gt;EOF&lt;/b&gt;) condition of &lt;b&gt;Order Details&lt;/b&gt; Table.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If &lt;b&gt;False&lt;/b&gt; then repeat the Process from &lt;b&gt;Step-4&lt;/b&gt; onwards, otherwise Close files and stop Run.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;To try the above method Import &lt;b&gt;Orders&lt;/b&gt; and &lt;b&gt;Order Details&lt;/b&gt; Tables from &lt;font class=”colrgreen”&gt; C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; (Access 2003) or &lt;font class=”colrgreen”&gt;C:\Users\User\My documents\Northwind 2007.accdb&lt;/font&gt; (Access 2007, if not available then you must create from &lt;b&gt;Local Templates&lt;/b&gt;)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Orders&lt;/b&gt; Table in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Add a new Field with the name &lt;b&gt;TotalValue&lt;/b&gt; with &lt;b&gt;Numeric (Double) &lt;/b&gt; data Type in &lt;b&gt;Orders&lt;/b&gt; Table.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;You may display the Index List of this Table to view its PrimaryKey Index on &lt;b&gt;Order ID&lt;/b&gt; field.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save the &lt;b&gt;Orders&lt;/b&gt; Table.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the VBA Editing Window (&lt;b&gt;Alt+F11&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a new Standard Module from &lt;b&gt;Insert&lt;/b&gt; Menu.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following VBA Routine and save the Module.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CreateIndex()&lt;br /&gt;Dim db As Database, fld As Field, tbldef As TableDef&lt;br /&gt;Dim idx As Index, rst As Recordset, PreviousOrderID As Long&lt;br /&gt;Dim CurrentOrderID As Long&lt;br /&gt;Dim xQuantity As Long, xUnitPrice As Double&lt;br /&gt;Dim xDiscount As Double, Total As Double, rst2 As Recordset&lt;br /&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;&lt;br /&gt;Set db = CurrentDb&lt;br /&gt;Set rst = db.OpenRecordset(&amp;quot;Order Details&amp;quot;, dbOpenTable)&lt;br /&gt;'Check for presence of myIndex, if found set as current&lt;br /&gt;rst.Index = &amp;quot;myIndex&amp;quot;&lt;br /&gt;If Err = 3800 Then&lt;br /&gt;'myIndex not found&lt;br /&gt;    Err.Clear&lt;br /&gt;    GoSub myNewIndex&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;On Error GoTo CreateIndex_Err&lt;br /&gt;&lt;br /&gt;Set rst2 = db.OpenRecordset(&amp;quot;Orders&amp;quot;, dbOpenTable)&lt;br /&gt;rst2.Index = &amp;quot;PrimaryKey&amp;quot;&lt;br /&gt;PreviousOrderID = rst![Order ID]&lt;br /&gt;CurrentOrderID = PreviousOrderID&lt;br /&gt;Do Until rst.EOF&lt;br /&gt;    Total = 0&lt;br /&gt;    Do While CurrentOrderID = PreviousOrderID&lt;br /&gt;        xQuantity = rst![quantity]&lt;br /&gt;        xUnitPrice = rst![unit price]&lt;br /&gt;        xDiscount = rst![discount]&lt;br /&gt;        &lt;br /&gt;        Total = Total + (xQuantity * ((1 - xDiscount) * xUnitPrice))&lt;br /&gt;        rst.MoveNext&lt;br /&gt;        PreviousOrderID = CurrentOrderID&lt;br /&gt;        If Not rst.EOF Then&lt;br /&gt;            CurrentOrderID = rst![Order ID]&lt;br /&gt;        Else&lt;br /&gt;            Exit Do&lt;br /&gt;        End If&lt;br /&gt;    Loop&lt;br /&gt;    rst2.Seek &amp;quot;=&amp;quot;, PreviousOrderID&lt;br /&gt;    If Not rst2.NoMatch Then&lt;br /&gt;        rst2.Edit&lt;br /&gt;        rst2![totalvalue] = Total&lt;br /&gt;        rst2.Update&lt;br /&gt;    End If&lt;br /&gt;    PreviousOrderID = CurrentOrderID&lt;br /&gt;Loop&lt;br /&gt;&lt;br /&gt;rst.Close&lt;br /&gt;rst2.Close&lt;br /&gt;&lt;br /&gt;'Delete temporary Index&lt;br /&gt;Set tbldef = db.TableDefs(&amp;quot;Order details&amp;quot;)&lt;br /&gt;tbldef.Indexes.Delete &amp;quot;myIndex&amp;quot;&lt;br /&gt;&lt;br /&gt;CreateIndex_Exit:&lt;br /&gt;Exit Function&lt;br /&gt;&lt;br /&gt;myNewIndex:&lt;br /&gt;rst.Close&lt;br /&gt;Set tbldef = db.TableDefs(&amp;quot;Order Details&amp;quot;)&lt;br /&gt;Set idx = tbldef.CreateIndex(&amp;quot;myIndex&amp;quot;)&lt;br /&gt;&lt;br /&gt;Set fld = tbldef.CreateField(&amp;quot;Order ID&amp;quot;, dbLong)&lt;br /&gt;idx.Fields.Append fld&lt;br /&gt;Set fld = tbldef.CreateField(&amp;quot;Product ID&amp;quot;, dbLong)&lt;br /&gt;idx.Fields.Append fld&lt;br /&gt;tbldef.Indexes.Append idx&lt;br /&gt;tbldef.Indexes.Refresh&lt;br /&gt;Set rst = db.OpenRecordset(&amp;quot;Order Details&amp;quot;, dbOpenTable)&lt;br /&gt;rst.Index = &amp;quot;myIndex&amp;quot;&lt;br /&gt;Return&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;CreateIndex_Err:&lt;br /&gt;MsgBox Err.Description, , &amp;quot;CreateIndex()&amp;quot;&lt;br /&gt;Resume CreateIndex_Exit&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click somewhere in the middle of the VBA Routine and press &lt;b&gt;F5&lt;/b&gt; or click &lt;b&gt;Run&lt;/b&gt; Command Button to execute the Code and update the Orders Table.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;At  the beginning part of the Code we are attempting to make one of the Indexes (&lt;b&gt;myIndex&lt;/b&gt;) of &lt;b&gt;Order Details&lt;/b&gt; Table active.  Since,  &lt;b&gt;myIndex&lt;/b&gt; is not yet created on the Table this action runs into an Error condition.  we are trapping this Error Code and passes control to the Sub-Routine to create &lt;b&gt;myIndex&lt;/b&gt; and to add it to the &lt;b&gt;Indexes&lt;/b&gt; collection. The new Index is activated in preparation for data processing.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next steps calculate Order-wise Total Values and updates on Orders Table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At the end of the process &lt;b&gt;myIndex&lt;/b&gt; is deleted from the &lt;b&gt;Indexes&lt;/b&gt; Collection of &lt;b&gt;Order Details&lt;/b&gt; Table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/01/indexing-and-sorting-with-VBA.shtml&amp;amp;title=Indexing+and+Sorting+with+VBA"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-4450439274668995205?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/01/indexing-and-sorting-with-vba.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-5365656516525521009</guid><pubDate>Tue, 12 Jan 2010 15:47:00 +0000</pubDate><atom:updated>2010-01-12T20:24:40.823+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Process Controls</category><title>Data Upload Controls</title><description>In some Projects we have to upload data regularly from external data sources like dBase, Excel, flat files like CSV, Text and so on. The external file can remain linked to the Project and the data from them can be added into the local MS-Access Table for preparing Reports&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example, let us say we have an MS-Access Application that prepares monthly &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Reports&lt;/a&gt; on Profitability of Businesses and to do this we must upload raw data on Revenue and Expenses received every month in one of the file Formats mentioned above. If our Application is designed in a such way that when the existing linked file is replaced with new data file with the same name then the Application must be able to identify the presence of new data in the attached file and allow the User to upload the new records into the master file. But, before this action is allowed it become our responsibility as a developer to see that the data once uploaded is not allowed into the System again.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To do this we must install a procedure that will check for the presence of new data in the attached File. If found then enable a &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; that will allow the User to click and upload the new data into the System. Otherwise keep the &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; disabled till such time fresh data is detected in the attached file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So, how do we detect the presence of fresh data in the attached file? Depending on the type of file we can use different approaches to determine the presence of fresh data in the attached file by checking continuity of some Control Number like &lt;b&gt;Invoice Number&lt;/b&gt; or the &lt;b&gt;Last Receipt Date&lt;/b&gt;, or any other set of unique values that you can depend on from the last uploaded data, and compare them with those Values of the attached file. If the compared values on both files are same then we can assume that the attached file contents are already uploaded earlier, otherwise prepare to upload fresh data. For this kind of checking we may prepare few Queries to filter the set of values from both files and read those values into a VBA routine to compare and control the flow of action.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, I use a simple method to check the presence of new data in the attached file. Before going into that we have to consider few other issues. If the attached external file is on the local drive of each User and all of them are allowed to run the upload action then it is difficult to keep control of this action and the data can go wrong as well. If the attached file is kept on Server and only one authorized User is allowed to execute the Upload action then there can be some control over the procedure. Depending on all these considerations we have to device a method to upload the data correctly into the database.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have several Applications that upload data from &lt;a href="http://www.msaccesstips.com/2008/06/linking-with-ibm-as400-tables.shtml"&gt;AS400&lt;/a&gt;, &lt;a href="http://www.msaccesstips.com/2008/07/opening-dbase-files-directly.shtml"&gt;dbase&lt;/a&gt;, &lt;a href="http://www.msaccesstips.com/2008/08/ms-access-live-data-in-excel.shtml"&gt;Excel&lt;/a&gt; and AS400 Report Spool Files too. I have tried out several methods to detect the presence of fresh information in those files using Queries with control data from tables within the Database and from linked tables. Perhaps, you may wonder what I did for AS400 Report Spool Files. This File cannot be kept attached with the database because it doesn’t have the correct data table format except the Detail Lines.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have developed programs that will read the spool file line by line and discard unwanted lines like Header, Footer, underlines, blank lines etc. and to take only data lines cut into text fields in a Table initially before converting each field values into their respective data types and write it out into a new table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, the question remains as how do I keep track of the presence of new Report Spool File that cannot be kept attached to the Database at all.  It is a simple trick.  At the end of the upload action of the current file I will make a copy of first 50 lines of the Spool File and create a second control file.  Whenever the Application is open by the User a program is run to open both files and do a line by line comparison. If there is no difference in the first 50 lines of both files then the data was already uploaded into the System otherwise the System is prepared to upload fresh data from new file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After trying several methods with different file types I thought we need a simple method that should work for all kind of files (attached to the system or not) and created one, which is presented below for your use, if needed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We need a small table with the following Fields: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table width="501" borader="1" cellspacing="0" cellpadding="5" bgcolor="#eeeeee"&gt;&lt;br /&gt;&lt;tr&gt;&lt;th width="34%"&gt;Field Name&lt;/th&gt;&lt;th width="33%"&gt;Data Type&lt;/th&gt;&lt;th width="33%"&gt;Field Size&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td width="34%"&gt;FileLength&lt;/td&gt;&lt;td width="33%"&gt;Long Integer&lt;/td&gt;&lt;td width="33%"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td width="34%"&gt;FileDateTime&lt;/td&gt;&lt;td width="33%"&gt;Date/Time&lt;/td&gt;&lt;td width="33%"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td width="34%"&gt;UserName&lt;/td&gt;&lt;td width="33%"&gt;Text&lt;/td&gt;&lt;td width="33%"&gt;25&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td width="34%"&gt;UploadDate&lt;/td&gt;&lt;td width="33%"&gt;Date/Time&lt;/td&gt;&lt;td width="33%"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;td width="34%"&gt;FilePath&lt;/td&gt;&lt;td width="33%"&gt;Text&lt;/td&gt;&lt;td width="33%"&gt;255&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;The sample table in Datasheet View:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/uploadctrl-777362.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 79px;" src="http://www.msaccesstips.com/uploaded_images/uploadctrl-777359.jpg" border="0" alt="Upload Control Table" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The idea works something like this. When we upload the file contents we will save some basic information of the attached file, like &lt;b&gt;File-Size&lt;/b&gt; in number of bytes and the &lt;b&gt;last modified date and time&lt;/b&gt; of the file. Besides that, the name of the &lt;a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account.shtml"&gt;User&lt;/a&gt; (if the database is implemented with &lt;a href="http://www.msaccesstips.com/2006/11/microsoft-access-security.shtml"&gt;Microsoft Access Security&lt;/a&gt;) who is authorized to run the upload action and the date of last upload event took place. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can read the attached File-Size in bytes with the Function: &lt;b&gt;FileLen(PathName)&lt;/b&gt; and the File&amp;#39;s last modified Date and Time can be obtained with the Function &lt;b&gt;FileDateTime(PathName)&lt;/b&gt;.  After the upload action these values can be updated into the above table to cross-check with the values of the external file to determine the presence of new data.  If needed we can set the attached file&amp;#39;s &lt;b&gt;Read-Only&lt;/b&gt; attribute &lt;b&gt;ON&lt;/b&gt; with the Function &lt;b&gt;SetAttr(PathName,vbReadOnly)&lt;/b&gt; so that the file can be protected from inadvertent changes. It can be reset to &lt;b&gt;Normal&lt;/b&gt; with &lt;b&gt;SetAttr(PathName,vbNormal)&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A program must be run immediately after the &lt;a href="http://www.msaccesstips.com/2007/06/control-screen-design.shtml"&gt;Main Switchboard Form&lt;/a&gt; is open and cross check the &lt;b&gt;File-size&lt;/b&gt; and the &lt;b&gt;File Date/Time&lt;/b&gt; recorded in the table with the attached file&amp;#39;s attributes and if found different then we can be sure that new data have arrived and enable the Command Button so that the User can click and upload new data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; But, if the User kept the Application open and replaced the attached file with new one then the Button will remain disabled because the status checking program runs only when the Main Switchboard opens. Instead of asking the user to close and open the Application again, as a standard procedure in these circumstances, we can create another Command Button with &lt;b&gt;Refresh&lt;/b&gt; Caption so that when the User clicks on this Button we can run the above procedure and enable the Upload Button if the file attributes indicates the presence of new file.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;A sample VBA Routine is given below that reads the information from the table and cross checks with the attributes of the attached file and Enable/Disable the Upload &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt; &lt;br /&gt;Public Function UploadControl(ByVal frmName As String)&lt;br /&gt;'------------------------------------------------------&lt;br /&gt;'Author   : a.p.r. pillai&lt;br /&gt;'Date     : January-2010&lt;br /&gt;'Remarks  : Data Upload control Routine&lt;br /&gt;'         : All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'------------------------------------------------------&lt;br /&gt;Dim frm As Form, lnglastFileSize, dtlastModified, txtFilePath&lt;br /&gt;Dim lngExternalFileSize, dtExternalModified, authUser&lt;br /&gt;Dim tblControl As String, cmdCtrl As CommandButton&lt;br /&gt;&lt;br /&gt;tblControl = &amp;quot;UploadCtrl&amp;quot;&lt;br /&gt;authUser = &amp;quot;LizzaMinnelli&amp;quot;&lt;br /&gt;Set frm = Forms(frmName)&lt;br /&gt;Set cmdCtrl = frm.Controls(&amp;quot;cmdUpload&amp;quot;)&lt;br /&gt;&lt;br /&gt;'Read last recorded information from the Control Table&lt;br /&gt;lnglastFileSize = DLookup(&amp;quot;FileLen&amp;quot;, tblControl)&lt;br /&gt;dtlastModified = DLookup(&amp;quot;FileDateTime&amp;quot;, tblControl)&lt;br /&gt;txtFilePath = DLookup(&amp;quot;FilePath&amp;quot;, tblControl)&lt;br /&gt;&lt;br /&gt;'Get the External File information&lt;br /&gt;lngExternalFileSize = FileLen(txtFilePath)&lt;br /&gt;dtExternalModified = FileDateTime(txtFilePath)&lt;br /&gt;&lt;br /&gt;If (lngExternalFileSize &amp;lt;&amp;gt; lnglastFileSize) And (dtlastModified &amp;lt;&amp;gt; dtExternalModified) Then&lt;br /&gt;    If CurrentUser = authUser Then&lt;br /&gt;        cmdCtrl.Enabled = True&lt;br /&gt;    Else&lt;br /&gt;        cmdCtrl.Enabled = False&lt;br /&gt;    End If&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The Main SwitchBoard, that has a Command Button with the name &lt;b&gt;cmdUpload&lt;/b&gt;,  should call the above Program through the &lt;b&gt;Form_Current()&lt;/b&gt; Event Procedure of the Form passing the Form Name as Parameter like the following example:&lt;br /&gt;&lt;pre class=”alt1”&gt;&lt;br /&gt;Private Sub Form_Current()&lt;br /&gt;    UploadControl Me.Name&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If Uploading authority is assigned to a particular User then the Current User&amp;#39;s UserID (retrieved with the function &lt;b&gt;CurrentUser&lt;/b&gt;) also can be checked with the UserName Field Value before enabling the Command Button &lt;b&gt;cmdUpload&lt;/b&gt;..&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/01/data-upload-controls.shtml&amp;amp;title=Data+Upload+Controls"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml"&gt;Run Slide-show when Form is idle&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml"&gt;Filter Function Output in ListBox-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml"&gt;Filter Function Output in ListBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;Dynamic List Box Contents&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml"&gt;Office Assistant and MsgBox Menus-3&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-5365656516525521009?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/01/data-upload-controls.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-8018013867169385997</guid><pubDate>Mon, 04 Jan 2010 16:37:00 +0000</pubDate><atom:updated>2010-01-04T21:24:34.001+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccessQuery</category><title>Auto Numbering In Query Column</title><description>&lt;br /&gt;&lt;br /&gt;We know how to create an Auto-number Field in a Table to generate Unique Sequence numbers automatically for the records added to the Table. We know how to create Sequence Numbers for data lines on &lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Reports&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;On Reports, create a Text Box in Detail Section of the &lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Report&lt;/a&gt;, write the expression &lt;b&gt;=1&lt;/b&gt; in the &lt;b&gt;Control Source&lt;/b&gt; Property and change the &lt;b&gt;Running Sum&lt;/b&gt; Property Value to &lt;b&gt;Over All&lt;/b&gt; or &lt;b&gt;Over Group&lt;/b&gt;. If you need sequence numbers for each &lt;a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account.shtml"&gt;Group&lt;/a&gt; separately, depending on the &lt;b&gt;Sorting and Grouping&lt;/b&gt; settings on the Report, then the &lt;b&gt;Over Group&lt;/b&gt; option must be set in the &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Property&lt;/a&gt; otherwise &lt;b&gt;Over All&lt;/b&gt; for continuous numbers from start of the Report to the End.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to create &lt;b&gt;Running Sum&lt;/b&gt; value of a Field, like &lt;b&gt;Quantity&lt;/b&gt; or &lt;b&gt;Total Price&lt;/b&gt;, then set the &lt;b&gt;Running Sum&lt;/b&gt; Property value as explained above.  For more details on Running Sum as well as creating &lt;b&gt;Page-wise Totals&lt;/b&gt; on Access Reports visit the Page with the Title: &lt;a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals.shtml"&gt;MS-Access Report and Page Totals&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;But, Auto-numbering in Queries looks somewhat strange to ask for unless you want to use the Query result for display purposes or the output created from that should have sequence numbers for some reason. Any way this requirement was raised by a participant in a &lt;b&gt;MS-Access Forum&lt;/b&gt; on the Net and nobody (including me) could give a clear cut solution except some alternatives. I chipped in with a solution of my own, even though I was not happy with that either.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The Access User who has raised the question in the Forum made direct contact by sending an E-mail to me asking for a solution.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This made me thinking again on that topic and did few trial runs of few simple methods. Finally I could come up with a Function that can do the trick and I am presenting it here so that you can also use it, if you really need it. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;It is important to know the usage of the &lt;b&gt;QrySeq()&lt;/b&gt; Function in Queries in a new Column to create Sequence Numbers.  The Function must be called with few Parameter Values using the values from the Query itself. So, before presenting the VBA Code of the Function I will give some details of the Parameters.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Usage of the &lt;a href="http://www.msaccesstips.com/2008/12/rounding-function-mround-of-excel.shtml"&gt;Function&lt;/a&gt; in the Query Column is as shown below:&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;font class="colrgreen"&gt;SRLNO: QrySeq(&lt;b&gt;[ORDERID]&lt;/b&gt;,&lt;b&gt;&amp;quot;[ORDERID]&amp;quot;&lt;/b&gt;,&lt;b&gt;&amp;quot;QUERY4&amp;quot;&lt;/b&gt;)&lt;/font&gt;&lt;br /&gt; &lt;br /&gt;The &lt;b&gt;QrySeq()&lt;/b&gt; Function need three Parameters. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;The &lt;b&gt;First Parameter&lt;/b&gt; must be &lt;b&gt;Unique Values&lt;/b&gt; available from any Field in the Query. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;b&gt;Second Parameter&lt;/b&gt; is the &lt;b&gt;Column Name&lt;/b&gt; of the first parameter in Quotes.&lt;/li&gt; &lt;br /&gt;&lt;li&gt;&lt;b&gt;Third Parameter&lt;/b&gt; is the &lt;b&gt;Name of the Query&lt;/b&gt; from where you call the  Function.&lt;/li&gt; &lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;The Query, from where the &lt;b&gt;QrySeq()&lt;/b&gt; Function is called should have a column of Unique Values, like &lt;b&gt;Autonumber&lt;/b&gt; or &lt;b&gt;Primary Key&lt;/b&gt; Field. If this is not readily available then create a Column by joining two or more existing fields (like &lt;b&gt;NewColumn:&lt;/b&gt;(&lt;i&gt;[OrderlD] &amp;amp; [ShippName] &amp;amp; [RequiredDate] &amp;amp; [Quantity]&lt;/i&gt; from the existing column values and ensure that this will form Unique values in all records and pass this Column value (&lt;b&gt;[NewColumn]&lt;/b&gt;) as first Parameter.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The first Parameter &lt;b&gt;Column Name&lt;/b&gt; must be passed to the Function in Quotes (&lt;b&gt;&amp;quot;[NewColumn]&amp;quot;&lt;/b&gt;) as second parameter.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The &lt;b&gt;Name of the Query&lt;/b&gt; must be passed as third parameter.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt; Ensure that you save the &lt;a href="http://www.msaccesstips.com/2008/02/percentage-on-total-query.shtml"&gt;Query&lt;/a&gt; first, after every change to the design of the Query, before opening it in Normal View, with the &lt;a href="http://www.msaccesstips.com/2007/09/useful-report-functions.shtml"&gt;Function&lt;/a&gt; in place, to create the Sequence Numbers correctly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, the simple Rules are in place it is time to try out the Function.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following VBA Code into a Standard Module in your Database:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Option Compare Database&lt;br /&gt;Option Explicit&lt;br /&gt;&lt;br /&gt;Dim varArray() As Variant, i As Long&lt;br /&gt;&lt;br /&gt;Public Function QrySeq(ByVal fldvalue, ByVal fldName As String, ByVal QryName As String) As Long&lt;br /&gt;'-------------------------------------------------------------------&lt;br /&gt;'Purpose: Create Sequence Numbers in Query in a new Column&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date : Dec. 2009&lt;br /&gt;'All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'-------------------------------------------------------------------&lt;br /&gt;'Parameter values&lt;br /&gt;'-------------------------------------------------------------------&lt;br /&gt;'1 : Column Value - must be unique Values from the Query&lt;br /&gt;'2 : Column Name  - the Field Name from Unique Value Taken&lt;br /&gt;'3 : Query Name   - Name of the Query this Function is Called from&lt;br /&gt;'-------------------------------------------------------------------&lt;br /&gt;'Limitations - Function must be called with a Unique Field Value&lt;br /&gt;'            - as First Parameter&lt;br /&gt;'            - Need to Save the Query after change before opening&lt;br /&gt;'            - in normal View.&lt;br /&gt;'-------------------------------------------------------------------&lt;br /&gt;Dim k As Long&lt;br /&gt;On Error GoTo QrySeq_Err&lt;br /&gt;restart:&lt;br /&gt;If i = 0 Or DCount(&amp;quot;*&amp;quot;, QryName) &lt;&gt; i Then&lt;br /&gt;Dim j As Long, db As Database, rst As Recordset&lt;br /&gt;    i = DCount(&amp;quot;*&amp;quot;, QryName)&lt;br /&gt;ReDim varArray(1 To i, 1 To 3) As Variant&lt;br /&gt;Set db = CurrentDb&lt;br /&gt;Set rst = db.OpenRecordset(QryName, dbOpenDynaset)&lt;br /&gt;For j = 1 To i&lt;br /&gt;    varArray(j, 1) = rst.Fields(fldName).Value&lt;br /&gt;    varArray(j, 2) = j&lt;br /&gt;    varArray(j, 3) = fldName&lt;br /&gt;    rst.MoveNext&lt;br /&gt;Next&lt;br /&gt;rst.Close&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;If varArray(1, 3) &amp;amp; varArray(1, 1) &amp;lt;&amp;gt; (fldName &amp;amp; DLookup(fldName, QryName)) Then&lt;br /&gt;    i = 0&lt;br /&gt;    GoTo restart&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;For k = 1 To i&lt;br /&gt;If varArray(k, 1) = fldvalue Then&lt;br /&gt;    QrySeq = varArray(k, 2)&lt;br /&gt;    Exit Function&lt;br /&gt;End If&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;QrySeq_Exit:&lt;br /&gt;Exit Function&lt;br /&gt;&lt;br /&gt;QrySeq_Err:&lt;br /&gt;MsgBox Err &amp;amp; &amp;quot; : &amp;quot; &amp;amp; Err.Description, , &amp;quot;QrySeqQ&amp;quot;&lt;br /&gt;Resume QrySeq_Exit&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Import the &lt;b&gt;Orders&lt;/b&gt; Table from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; sample database.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following SQL String into the SQL Editing View of a New Query and save the Query with the Name: &lt;b&gt;AutoNumberQuery&lt;/b&gt;:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT Orders.*, QrySeq([OrderID],&amp;quot;OrderID&amp;quot;,&amp;quot;AutoNumberQuery&amp;quot;) AS SRLNO&lt;br /&gt;FROM Orders;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Save&lt;/b&gt; from &lt;b&gt;File&lt;/b&gt; Menu or click on the &lt;b&gt;Save&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars.shtml"&gt;Toolbar&lt;/a&gt; Button.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the Query in normal view.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;Check the &lt;b&gt;SRLNO&lt;/b&gt; Column for Sequence Numbers.&lt;br /&gt;&lt;br /&gt;Here, the &lt;b&gt;OrderID&lt;/b&gt; in the &lt;b&gt;Orders&lt;/b&gt; Table have unique field values and we could easily get away with the Sequence Numbers correctly in &lt;b&gt;SRLNO&lt;/b&gt; Column.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us pretend for a moment that we don&amp;#39;t have a single field with Unique Values in the &lt;a href="http://www.msaccesstips.com/2008/02/union-query.shtml"&gt;Query&lt;/a&gt;.  We must create a &lt;a href="http://www.msaccesstips.com/2008/07/column-chart-and-vba.shtml"&gt;Column&lt;/a&gt; with Unique Values by joining two or more Columns available in the Query and pass it to the &lt;b&gt;QrySeq()&lt;/b&gt; Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us try such an example with the &lt;b&gt;Orders&lt;/b&gt; Table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following SQL String into a new Query and &lt;b&gt;Save&lt;/b&gt; the Query with the name &lt;b&gt;AutoNumberQuery2&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT Orders.*, &lt;b&gt;[ShipName] &amp;amp; [RequiredDate] AS NewColumn,&lt;/b&gt; &lt;br /&gt;QrySeq([NewColumn],&amp;quot;NewColumn&amp;quot;,&amp;quot;AutoNumberQuery2&amp;quot;) AS SRLNO&lt;br /&gt;FROM Orders;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Open the Query in normal View to check whether the Serial Numbers were created correctly or not.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;When there are several records it is difficult to check whether the Column Values we have passed to the Function are really unique and the Serial Numbers generated have no duplicates in them by manually checking through the records.  Instead, we will take a Count of Serial Numbers appearing more than once in the Records, if any, with the use of a &lt;b&gt;Total Query&lt;/b&gt; using &lt;b&gt;AutoNumberQuery2&lt;/b&gt; as Source.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a new Query using the following SQL String and name the new Query as &lt;b&gt;DuplicatesCheckQ&lt;/b&gt;:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT AutoNumberQuery2.SRLNO, Count(AutoNumberQuery2.SRLNO) AS CountOfSRLNO&lt;br /&gt;FROM AutoNumberQuery2&lt;br /&gt;GROUP BY AutoNumberQuery2.SRLNO&lt;br /&gt;HAVING (((Count(AutoNumberQuery2.SRLNO))&gt;1));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;DuplicatesCheckQ&lt;/b&gt; Query in Normal View.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;You will find the following result showing &lt;b&gt;SRLNO&lt;/b&gt; Column having the same number appearing more than once in the records indicating that the Unique &lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;Column Values&lt;/a&gt; we have created for the Function are not really Unique and have duplicates in them.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/qryduplist-775370.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 170px; height: 202px;" src="http://www.msaccesstips.com/uploaded_images/qryduplist-775363.jpg" border="0" alt="Duplicate Serial Numbers in Query Column" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;This can be rectified only by adding more Column Values to the &lt;b&gt;NewColumn&lt;/b&gt; expression to eliminate the chance of ending up with duplicates.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This method is only an alternative in the absence of an &lt;b&gt;AutoNumber&lt;/b&gt; or &lt;b&gt;Primary Key&lt;/b&gt; field Values and not with 100% percent success rate because when you add more records to the Source Table it is likely that it can fail again. In this case the only solution is to join more fields to the expression in &lt;b&gt;NewColumn&lt;/b&gt; so that we can reduce the chance of failures.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, to correct the above Query add the &lt;b&gt;[Freight] Value&lt;/b&gt; Column also to the &lt;b&gt;NewColumn&lt;/b&gt; expression.  Or Copy and paste the following SQL String into the &lt;b&gt;AutoNumberQuery2&lt;/b&gt; Query overwriting the earlier SQL string in there and save the Query.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;&lt;br /&gt;SELECT Orders.*, &lt;b&gt;[ShipName] &amp;amp; [RequiredDate] &amp;amp; [Freight] AS NewColumn, &lt;/b&gt;&lt;br /&gt;QrySeq([NewColumn],&amp;quot;NewColumn&amp;quot;;,&amp;quot;AutoNumberQuery2&amp;quot;) AS SRLNO&lt;br /&gt;FROM Orders;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Open the &lt;b&gt;DuplicatesCheckQ&lt;/b&gt; Query again to check for duplicates. If the result is empty then the Sequence Numbers generated will be correct.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you have a different solution to this problem, then share it with me too.  I don&amp;#39;t need a refined version of the above Code or method but a different approach to arrive at the same or better result.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2010/01/auto-numbering-in-query-column.shtml&amp;amp;title=Auto+Numbering+in+Query+Column"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml"&gt;Filter Function Output in ListBox-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml"&gt;Filter Function Output in ListBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;Dynamic List Box Contents&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml"&gt;Office Assistant and MsgBox Menus-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml"&gt;Office Assistant and MsgBox Menus-2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-8018013867169385997?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2010/01/auto-numbering-in-query-column.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>4</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-2616480463990277743</guid><pubDate>Mon, 28 Dec 2009 02:42:00 +0000</pubDate><atom:updated>2009-12-28T18:59:23.030+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Web Browsing within Access Form</title><description>Browsing the World Wide Web is nothing new to us. But, how about organizing the Web Addresses of frequently visiting Websites in a Table and browse the Web from within an Access Form?&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/webbrowse-751019.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 232px;" src="http://www.msaccesstips.com/uploaded_images/webbrowse-751014.jpg" border="0" alt="Form with Web Browser Control" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;Not only Internet Sites, you can browse the &lt;font class="colrgreen"&gt;Intranet&lt;/font&gt;  Website within your Local Area Network - Corporate LAN) too. All you have to do is to create an Access Form with a &lt;b&gt;Microsoft Web Browser&lt;/b&gt; Control and a few lines of VBA Code.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;For example, the following VBA Code will open the GMail Web Site &lt;font class="colrgreen"&gt;http://www.gmail.com/ &lt;/font&gt; automatically when you open the Form with the Web Browser Control, as shown in the above image.:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt; &lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;Dim strURL As String&lt;br /&gt;&lt;br /&gt;      strURL = &amp;quot;http://www.gmail.com/&amp;quot;&lt;br /&gt;      Me.WebBrowser0.Navigate strURL&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;Don&amp;#39;t know how to do it? Try the following: &lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Open a new Form in Design View. &lt;/li&gt; &lt;br /&gt;&lt;li&gt;Click somewhere on the Detail Section of the &lt;a href="http://www.msaccesstips.com/2009/02/synchronized-floating-popup-form.shtml"&gt;Form&lt;/a&gt; to select that area. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;ActiveX Control... &lt;/b&gt; from &lt;b&gt;Insert&lt;/b&gt; Menu. &lt;/li&gt; &lt;br /&gt;&lt;li&gt;Look for the name &lt;b&gt;Microsoft Web Browser&lt;/b&gt; in the displayed list of &lt;b&gt;ActiveX Controls&lt;/b&gt; and select it. &lt;/li&gt; &lt;br /&gt;&lt;li&gt;Click &lt;b&gt;OK&lt;/b&gt; to insert a &lt;b&gt;Web Browser Control&lt;/b&gt; on the Form. &lt;/li&gt; &lt;br /&gt;&lt;li&gt;While the Control is still in selected state drag the right-bottom-corner sizing control to make it big enough on the Form so that you can view the Web Pages properly. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Property Sheet of the Browser Control (&lt;b&gt;View - -&gt;Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Property&lt;/a&gt; Value to &lt;b&gt;WebBrowserO&lt;/b&gt; to match with the name used in the above VBA Code. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Code&lt;/b&gt; from &lt;b&gt;View&lt;/b&gt; Menu to display the VBA Code Module of the Form. &lt;/li&gt; &lt;br /&gt;&lt;li&gt;Copy and Paste the above Code into the Module. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Save and Close the Form with the name &lt;b&gt;myWebBrowser&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Connect your PC to the Internet. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;myWebBrowser&lt;/b&gt; Form in normal View. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Wait for few seconds to load the Web Page into the Control and to display. &lt;/li&gt; &lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;We have used the Website Address directly in the Code. But, if you create a Table with the list of all the Website addresses that you visit very often then with a &lt;a href="http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml"&gt;Combo Box&lt;/a&gt; on the Form we can select the Web address to go to that site quickly. We need to make few changes in the above Code to make it flexible.&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a Table with a single field with the following details: &lt;/li&gt; &lt;br /&gt;&lt;br /&gt;Table Name: &lt;b&gt;WebSites&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Field Name : &lt;b&gt;WebAddress&lt;/b&gt; Data Type : &lt;b&gt;Text&lt;/b&gt; Field Size: &lt;b&gt;255&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save the Table Structure and open it in Datasheet View. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Add few records with Web URLs that you visits frequently, save and close the Table. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Make a Copy of the Form &lt;b&gt;myWebBrowser&lt;/b&gt; and name the copy as &lt;b&gt;myWebBrowser2&lt;/b&gt;.&lt;/li&gt; &lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;myWebBrowser2&lt;/b&gt; in Design View. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Display the &lt;a href="http://www.msaccesstips.com/2009/03/positioning-pop-up-forms.shtml"&gt;Form&lt;/a&gt; Header Section (&lt;b&gt;View - -&gt; Form Header/Footer&lt;/b&gt;), if it is not already Visible. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Expand the Form Header Section with enough height to create a Combo Box Control. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a Combo Box using the &lt;b&gt;WebSites&lt;/b&gt; Table. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;While the &lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;Combo Box&lt;/a&gt; is still in selected state display the Property Sheet (&lt;b&gt;View - -&gt; Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Change the following &lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Property&lt;/a&gt; Values of the Combo Box: &lt;/li&gt;&lt;br /&gt;&lt;br /&gt; &lt;pre class="alt2"&gt;&lt;br /&gt;Name : &lt;b&gt;cboWeb&lt;/b&gt; &lt;br /&gt;Width : &lt;b&gt;5&amp;quot;&lt;/b&gt; &lt;br /&gt;Default Value : &lt;b&gt;&amp;quot;http://www.gmail.com/&amp;quot;&lt;/b&gt; or any other Website Address Value you prefer.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Select the child label attached to the Combo box and change the &lt;b&gt;Caption&lt;/b&gt; Property Value to &lt;b&gt;Web Address&lt;/b&gt;:&lt;/li&gt; &lt;br /&gt;&lt;li&gt;Display the Code Module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt; &lt;br /&gt;&lt;li&gt;Copy and Paste the following Code into the Module replacing the existing lines. &lt;/li&gt; &lt;br /&gt;&lt;br /&gt;&lt;pre&gt; &lt;br /&gt;Option Compare Database&lt;br /&gt;Option Explicit&lt;br /&gt;&lt;br /&gt;Dim WebObj As WebBrowser&lt;br /&gt;Dim varURL As Variant&lt;br /&gt;&lt;br /&gt;Private Sub cboWeb_Click()&lt;br /&gt;     GotoSite&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub cboWebLostFocus()&lt;br /&gt;     GotoSite&lt;br /&gt;End Sub&lt;br /&gt; &lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;     Set WebObj = Me.WebBrowser0.Object&lt;br /&gt;GotoSite&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Function GotoSite()&lt;br /&gt;    varURL = Me!cboWeb&lt;br /&gt;If Len(Nz(varURL, &amp;quot;&amp;quot;)) = 0 Then&lt;br /&gt;    Exit Function&lt;br /&gt;End If&lt;br /&gt; &lt;br /&gt;WebObj.Navigate varURL&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;li&gt;Save the Form and open it in Normal View. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;The Website address that you have inserted into the &lt;b&gt;Default Value&lt;/b&gt; Property of the Combo Box will open up in the Browser Control. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Select one of the other Website addresses you have added to the Table from the Combo Box. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;The Browser Window will open the new Website. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;If we open other Web Pages by clicking on the Links from the displayed pages then we can navigate (go &lt;b&gt;Back&lt;/b&gt; or &lt;b&gt;Forward&lt;/b&gt;) between pages by adding few more lines of Code.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;But, first let us have a look at the above Code to see what is happening there. We have declared a &lt;b&gt;Web Browser&lt;/b&gt; Object Variable and a &lt;b&gt;Variant&lt;/b&gt; Variable at the Global declaration area of the Module.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Created a separate Function &lt;b&gt;GotoSite()&lt;/b&gt; to respond to different &lt;b&gt;Events&lt;/b&gt; (Actions) on the Form without duplicating the Code everywhere.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;For example: when we open the Form the &lt;b&gt;GotoSite()&lt;/b&gt; Function opens the &lt;b&gt;Default Value&lt;/b&gt; URL, we set in the Combo Box Property, through the &lt;b&gt;Form_Load()&lt;/b&gt; Event Procedure.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;When you select a URL from the Combo Box the &lt;b&gt;cboWeb_Click()&lt;/b&gt; Event Procedure calls this Function to open the selected Web Page.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;If you type a URL in the &lt;b&gt;Web Address&lt;/b&gt; Control &lt;b&gt;cboWeb&lt;/b&gt; and moves the Cursor out of the control the &lt;b&gt;Lost_Focus()&lt;/b&gt; Event Procedure runs the Function to open the URL you typed on the Address Control.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;We will create few &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Buttons&lt;/a&gt; on the Header of the Form, as shown to the right of the Combo box Control on the above design and write Subroutines with some simple &lt;b&gt;Browser Object&lt;/b&gt; Commands to navigate between Web Pages, which we may open from the displayed Web Pages.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Open &lt;b&gt;myWebBrowser2&lt;/b&gt; Form in Design View. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Display the Toolbox (if it is not visible then select &lt;b&gt;Toolbox&lt;/b&gt; from &lt;b&gt;View&lt;/b&gt; Menu. &lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Create five Command Buttons to the right of the Combo Box. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Display the Property Sheet of the first &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; and change the &lt;b&gt;Name&lt;/b&gt; Property and &lt;b&gt;Caption&lt;/b&gt; Property Values to &lt;b&gt;Home&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Similarly, change the &lt;b&gt;Name&lt;/b&gt; and &lt;b&gt;Caption&lt;/b&gt; Property Values of the other &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Buttons&lt;/a&gt; with the values given below. &lt;/li&gt;&lt;br /&gt;&lt;ul&gt; &lt;br /&gt;&lt;li&gt;Back&lt;/li&gt; &lt;br /&gt;&lt;br /&gt;&lt;li&gt;Forward&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Refresh&lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;li&gt;Stop&lt;/li&gt; &lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Display the Code Module of the Form (&lt;b&gt;View - -&gt;Code&lt;/b&gt;), copy and paste the following Code into the VBA Module, below the existing Code lines. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt; &lt;br /&gt;Private Sub Home_Click()&lt;br /&gt;On Error Resume Next&lt;br /&gt;    WebObj.GoHome&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Back_Click()&lt;br /&gt;On Error Resume Next&lt;br /&gt;    WebObj.GoBack&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Forward_Click()&lt;br /&gt;On Error Resume Next&lt;br /&gt;    WebObj.GoForward&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Refresh_Click()&lt;br /&gt;On Error Resume Next&lt;br /&gt;    WebObj.Refresh&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Stop_Click()&lt;br /&gt;On Error Resume Next&lt;br /&gt;     WebObj.Stop&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;The &lt;font class="colrgreen"&gt;On Error Resume Next&lt;/font&gt; Statement prevents the Subroutines running into Error, when there are no Web Pages to Navigate to.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To test these Buttons you must click on few links on the displayed Web Page to open other Pages from the same Website and then use these Buttons to navigate between those opened pages.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The &lt;b&gt;Home&lt;/b&gt; Button will open the &lt;b&gt;Default Home page&lt;/b&gt; you set in the &lt;font class="colrgreen"&gt;Internet Explorer&amp;#39;s&lt;/font&gt; Tools - -&gt; Internet Options&amp;hellip; Home Page - -&gt; Address Control, not the default Value you set in the Combo Box.&lt;br /&gt; &lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/12/web-browsing-within-access-form.shtml&amp;amp;title=Web+Browsing+within+Access+Form"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml"&gt;Filter Function Output in ListBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;Dynamic List Box Contents&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml"&gt;Office Assistant and MsgBox Menus-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml"&gt;Office Assistant and MsgBox Menus-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-2616480463990277743?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/12/web-browsing-within-access-form.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-2566803255937553871</guid><pubDate>Sun, 20 Dec 2009 17:27:00 +0000</pubDate><atom:updated>2009-12-27T22:27:34.948+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Process Controls</category><title>Text Search Filter Web Style</title><description>How to search for several pieces of information across all the fields and in all the records of a Table?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example, when we search for something on the Web we give several piece of text separated with &lt;b&gt;,&lt;/b&gt; or &lt;b&gt;+&lt;/b&gt; symbol to match any of the given text anywhere within the Web Pages and display the matching links on the screen. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;&lt;b&gt;Search text example1 :&lt;/b&gt; ms-access, forms, reports, Queries&lt;br /&gt;&lt;br /&gt;Or&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Search text example2 :&lt;/b&gt; ms-access+forms+reports+queries&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;In the same way we can create filter to display records from a table that matches several piece of Text/numbers/Phrases across in any field in any record. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Last week we have learned the usage of &lt;b&gt;&lt;a href="http://www.msaccesstips.com/2009/12/filter-with-buildcriteria-function.shtml"&gt;BuildCriteria()&lt;/a&gt;&lt;/b&gt; Function to filter data using only one field. &lt;b&gt;BuildCriteria()&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/11/sum-min-max-avg-paramarray.shtml"&gt;Function&lt;/a&gt; can accept only one Field as its first Parameter. We will be using this Function here also. But, we will pull a trick for using this Function for all the fields in a Table.&lt;br /&gt;&lt;br /&gt;So let us do this with a simple Query and a Tabular &lt;a href="http://www.msaccesstips.com/2009/04/animating-label-on-search-success.shtml"&gt;Form&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Import &lt;b&gt;Customers&lt;/b&gt; Table from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Offce\Office11\Samples\Northwind.mdb&lt;/font&gt; sample database.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a Query using the &lt;b&gt;Customers&lt;/b&gt; Table with all the fields and by adding a new Column with the name &lt;b&gt;FilterField&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Write the following expression in the new column to join all the Text and Numeric Field values together into a single Column:&lt;/li&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;FilterField: [CUstomerID] &amp;" " &amp; [CompanyName] &amp;" " &amp; [ContactName] &amp; ... &lt;/font&gt; etc. and join all the fields this way except &lt;b&gt;HyperLinks, Objects&lt;/b&gt; and &lt;b&gt;Yes/No&lt;/b&gt; Field Types. Save the Query with the name &lt;b&gt;myQuery&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;This task you can automate with the following Program after creating a Query manually with at least one field from the Source Table and naming the Query as &lt;b&gt;myQuery&lt;/b&gt;. You may modify the Program where the reference to &lt;b&gt;myQuery&lt;/b&gt; name appears to implement your own preferred name, if needed. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CombineData(ByVal tblName As String)&lt;br /&gt;'----------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : December 2009&lt;br /&gt;'Rights : All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'----------------------------------------------------------&lt;br /&gt;Dim strsql1 As String, db As Database, qrydef As QueryDef&lt;br /&gt;Dim fldName As String, k As Integer, j As Integer&lt;br /&gt;Dim tbldef As TableDef, strjoin As String&lt;br /&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;&lt;br /&gt;strsql1 = &amp;quot;SELECT &amp;quot; &amp;amp; tblName &amp;amp; &amp;quot;.*, &amp;quot;&lt;br /&gt;Set db = CurrentDb&lt;br /&gt;Set qrydef = db.QueryDefs(&amp;quot;myQuery&amp;quot;)&lt;br /&gt;&lt;br /&gt;Set tbldef = db.TableDefs(tblName)&lt;br /&gt;k = tbldef.Fields.Count - 1&lt;br /&gt;&lt;br /&gt;strjoin = &amp;quot;&amp;quot;&lt;br /&gt;For j = 0 To k&lt;br /&gt;    If tbldef.Fields(j).Type &amp;lt;&amp;gt; 1 And tbldef.Fields(j).Type &amp;lt;&amp;gt; 11 And tbldef.Fields(j).Type &amp;lt;&amp;gt; 12 Then&lt;br /&gt;        If Len(strjoin) = 0 Then&lt;br /&gt;            strjoin = &amp;quot;[&amp;quot; &amp;amp; tbldef.Fields(j).Name &amp;amp; &amp;quot;] &amp;quot;&lt;br /&gt;        Else&lt;br /&gt;            strjoin = strjoin &amp;amp; &amp;quot; &amp;amp; &amp;quot; &amp;amp; Chr$(34) &amp;amp; &amp;quot; &amp;quot; &amp;amp; Chr$(34) &amp;amp; &amp;quot; &amp;amp;  [&amp;quot; &amp;amp; tbldef.Fields(j).Name &amp;amp; &amp;quot;] &amp;quot;&lt;br /&gt;        End If&lt;br /&gt;    End If&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;strsql1 = strsql1 &amp;amp; &amp;quot;(&amp;quot; &amp;amp; strjoin &amp;amp; &amp;quot;) AS FilterField FROM &amp;quot; &amp;amp; tblName &amp;amp; &amp;quot;;&amp;quot;&lt;br /&gt;qrydef.SQL = strsql1&lt;br /&gt;db.QueryDefs.Refresh&lt;br /&gt;&lt;br /&gt;Set tbldef = Nothing&lt;br /&gt;Set qrydef = Nothing&lt;br /&gt;Set db = Nothing&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the following VBA Code into a Standard Module and save it.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the VBA Debug Window (&lt;b&gt;Ctrl+G&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Run the Program from the Debug Window by typing the following statement and pressing Enter Key:&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;CombineData &amp;quot;Customers&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This will modify the design of &lt;b&gt;myQuery&lt;/b&gt; by joining all the fields, except &lt;b&gt;HyperLink, Object, Yes/No&lt;/b&gt; and &lt;b&gt;Memo&lt;/b&gt; Fields, from &lt;b&gt;Customers&lt;/b&gt; Table, or any other Table that you use, and will create a new column with the name &lt;b&gt;FilterField&lt;/b&gt;. If you need &lt;b&gt;Memo&lt;/b&gt; Field contents too then you must add that Field manually in Query design. The &lt;b&gt;CombineData()&lt;/b&gt; Program will not do this because &lt;b&gt;HyperLinks, Object&lt;/b&gt; &amp;amp; &lt;b&gt;Memo&lt;/b&gt; fields falls into the same field Type category and the validation check bypasses it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sample Datasheet view image of the FilterField in &lt;b&gt;myQuery&lt;/b&gt; is given below:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/FilterField-774348.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 77px;" src="http://www.msaccesstips.com/uploaded_images/FilterField-774314.jpg" border="0" alt="Image of FilterField Contents" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;li&gt;Create a Tabular &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Form&lt;/a&gt; (continuous form) using &lt;b&gt;myQuery&lt;/b&gt; as Record Source and save the Form with the name &lt;b&gt;frmMyQuery&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the form &lt;b&gt;frmMyQuery&lt;/b&gt; in Design view.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the &lt;b&gt;FilterField&lt;/b&gt; Column and display its &lt;a href="http://www.msaccesstips.com/2009/02/synchronized-floating-popup-form.shtml"&gt;Property&lt;/a&gt; Sheet (&lt;b&gt;View - -&gt;Properties&lt;/b&gt;)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Visible&lt;/b&gt; Property Value to &lt;b&gt;No&lt;/b&gt;. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Make the &lt;b&gt;FilterField&lt;/b&gt; column size very small on the Form (it is not visible on normal view) and resize other &lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;Columns&lt;/a&gt; to view their contents properly.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Remove the columns like &lt;b&gt;Region, Fax&lt;/b&gt; etc. or any other column that you feel not required for our Test Runs, so that all the required columns will fit on one Screen properly.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Expand the Form Header Section and drag the column headings down so that we will get enough space to draw a &lt;a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins.shtml"&gt;Text Box&lt;/a&gt; and a &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; beside it.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a Text Box above the column headings. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Property Sheet of the Text Box (&lt;b&gt;View - -&gt;Properties&lt;/b&gt;). &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the following Property Values as given below: &lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Name  =      txtSearch&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Width   =      3&amp;quot;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Caption&lt;/b&gt; of the &lt;b&gt;Child Label&lt;/b&gt; of the Text Box to &lt;b&gt;Search Text&lt;/b&gt; (delimiter: , or +):&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; to the right of the Text Box and change the following Property Values: &lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Name =     cmdGo&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Caption = GO&amp;gt; &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Display the Code module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following VBA Code into the Module. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Private Sub cmdGo_Click()&lt;br /&gt;'----------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : December 2009&lt;br /&gt;'Rights : All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'----------------------------------------------------------&lt;br /&gt;Dim x_Filter, j As Integer&lt;br /&gt;Dim Y_Filter, Xchar As String, flag&lt;br /&gt;&lt;br /&gt;x_Filter = Nz(Me![txtSearch], &amp;quot;&amp;quot;)&lt;br /&gt;&lt;br /&gt;If Len(x_Filter) = 0 Then&lt;br /&gt;    Me.FilterOn = False&lt;br /&gt;    Exit Sub&lt;br /&gt;End If&lt;br /&gt;'Code segment that tests and removes extra spaces'&lt;br /&gt;'between coma and next search text item.&lt;br /&gt;&lt;br /&gt;'--Extra space removal Segment start-&lt;br /&gt;Y_Filter = &amp;quot;&amp;quot;&lt;br /&gt;For j = 1 To Len(x_Filter)&lt;br /&gt;    Xchar = Mid(x_Filter, j, 1)&lt;br /&gt;' Test for presence of , or + and leading spaces&lt;br /&gt;    If (Xchar = &amp;quot;,&amp;quot; Or Xchar = &amp;quot;+&amp;quot;) And Mid(x_Filter, j + 1, 1) = &amp;quot; &amp;quot; Then&lt;br /&gt;            flag = True&lt;br /&gt;    ElseIf Xchar &amp;lt;&amp;gt; &amp;quot; &amp;quot; And flag Then&lt;br /&gt;            flag = False&lt;br /&gt;            Y_Filter = Trim(Y_Filter)&lt;br /&gt;    End If&lt;br /&gt;    Y_Filter = Y_Filter &amp;amp; Xchar&lt;br /&gt;Next&lt;br /&gt;x_Filter = Y_Filter&lt;br /&gt;&lt;br /&gt;'--Extra space removal Segment End-&lt;br /&gt;&lt;br /&gt;Y_Filter = &amp;quot;*&amp;quot;&lt;br /&gt;For j = 1 To Len(x_Filter)&lt;br /&gt;        Xchar = Mid(x_Filter, j, 1)&lt;br /&gt;      'Validation check&lt;br /&gt;      If Xchar = &amp;quot;(&amp;quot; Or Xchar = &amp;quot;)&amp;quot; Then&lt;br /&gt;                MsgBox &amp;quot;Invalid Characters () in expression, aborted... &amp;quot;&lt;br /&gt;                Exit Sub&lt;br /&gt;     End If&lt;br /&gt;If Xchar = &amp;quot;,&amp;quot; Or Xchar = &amp;quot;+&amp;quot; Then 'test for presence of ,+&lt;br /&gt;     Xchar = &amp;quot;* OR *&amp;quot;&lt;br /&gt;End If&lt;br /&gt;Y_Filter = Y_Filter &amp;amp; Xchar&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;Y_Filter = Y_Filter &amp;amp; &amp;quot;*&amp;quot;&lt;br /&gt;Me.FilterOn = False&lt;br /&gt;Y_Filter = BuildCriteria(&amp;quot;FilterField&amp;quot;, dbText, Y_Filter)&lt;br /&gt;Me.Filter = Y_Filter&lt;br /&gt;Me.FilterOn = True&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt; &lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Save the Form and open it in Normal View. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Type some Text/Numbers/Phrases separated with comas (&lt;b&gt;,&lt;/b&gt;) or plus symbol (&lt;b&gt;+&lt;/b&gt;), which can match in any part of any Field(s) or in different Record(s), in the Text Box.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Example1: FRANK, Elizabeth Brown, Brazil&lt;br /&gt;&lt;br /&gt;Example2: FRANK+Elizabeth Brown+Brazil&lt;br /&gt;&lt;br /&gt;Example3: frank+ Elizabeth Brown, Brzail&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt; Do not use brackets '&lt;b&gt;()&lt;/b&gt;' in the search text. These will run into errors when used in the &lt;b&gt;BuildCriteria()&lt;/b&gt; Function. Users may type &lt;b&gt;extra spaces&lt;/b&gt; between the text separator character &lt;b&gt;,&lt;/b&gt; or + symbol and the next search text item and these spaces will be removed by the program before going in for search and filter operations. Embedded spaces in phrases will be left alone in the search text.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click on the &lt;b&gt;GO&amp;gt;&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Button&lt;/a&gt; to search for the given text in fields/records and filter those records on the Form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;You may inspect the filtered records to ensure that one or more of the search text you have entered into the Text Control appears in all the filtered records. They can appear in any field or fields in any Record, but all the records filtered will have these text/number/phrases on them. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/12/text-search-filter-web-style.shtml&amp;amp;title=Text+Search+Filter+Web+Style"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;Dynamic List Box Contents&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml"&gt;Office Assistant and MsgBox Menus-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml"&gt;Office Assistant and MsgBox Menus-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in MsgBox&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-2566803255937553871?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/12/text-search-filter-web-style.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-258607063638157084</guid><pubDate>Mon, 14 Dec 2009 19:16:00 +0000</pubDate><atom:updated>2009-12-15T00:00:36.204+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Process Controls</category><title>Filter with BuildCriteria Function</title><description>Any method that helps to find data quickly on a Form is always welcome by Users. There are several options available when you are in Form View Mode.&lt;br /&gt;When you Right-click on a Field a &lt;b&gt;Shortcut Menu&lt;/b&gt; will popup showing four data filter options as shown on the sample image given below.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/ShortcutFilter-724757.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 203px; height: 289px;" src="http://www.msaccesstips.com/uploaded_images/ShortcutFilter-724746.jpg" border="0" alt="Form Shortcut Menu Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The third option &lt;b&gt;Filter For&lt;/b&gt; can accept a Criteria Expression like &lt;b&gt;&amp;gt;10200 AND &amp;lt;=10300&lt;/b&gt; or similar to filter a Range of Values from the selected field.&lt;br /&gt;&lt;br /&gt;If you would like to see more options then point on &lt;b&gt;Filter&lt;/b&gt; option in &lt;b&gt;Record&lt;/b&gt; Menu. There you can find two new Options: &lt;b&gt;Filter by Form&lt;/b&gt; and &lt;b&gt;Advance Filter/Sort&lt;/b&gt;. Filter by &lt;a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard.shtml"&gt;Form&lt;/a&gt; allows you to set up Criteria in more than one field to select records based on Form fields.&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Advance Filter/Sort&lt;/b&gt; will open up Filter Design (&lt;a href="http://www.msaccesstips.com/2008/02/crosstab-union-queries-for-charts.shtml"&gt;Query&lt;/a&gt; Design) Window with the Source Table/Query of the &lt;a href="http://www.msaccesstips.com/2008/01/progress-counter.shtml"&gt;Form&lt;/a&gt; with whatever criteria you have entered into the &lt;b&gt;Filter for&lt;/b&gt; or &lt;b&gt;Filter by Form&lt;/b&gt; Options earlier, if any. You can further modify the filter conditions and Sorting Order and select &lt;b&gt;Apply Filter&lt;/b&gt; from the &lt;b&gt;Records&lt;/b&gt; Menu to view the result.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, if you would like to build a Custom Filter Option for the &lt;a href="http://www.msaccesstips.com/2006/11/remove-users-from-security-groups.shtml"&gt;User&lt;/a&gt;; based on a particular Field on the &lt;a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form.shtml"&gt;Form&lt;/a&gt; then you can use the built-in Function &lt;b&gt;BuildCriteria()&lt;/b&gt; and write a VBA Sub-Routine around this Function to filter the data. Run the Sub-Routine on a Button Click &lt;b&gt;Event Procedure&lt;/b&gt; and let the User input the Filter Criteria in various ways as he likes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Usage of the &lt;a href="http://www.msaccesstips.com/2008/04/days-in-month-function.shtml"&gt;Function&lt;/a&gt; is very simple. Let us try few examples of the Function directly in the Debug Window (Immediate Window) to understand how it works.&lt;br /&gt;&lt;OL&gt;&lt;br /&gt;&lt;li&gt;Press &lt;b&gt;Alt+F11&lt;/b&gt; to display the Visual Basic Editing Window.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Press &lt;b&gt;Ctrl+G&lt;/b&gt; to display the Debug window.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Type the following example expressions and press &lt;b&gt;Enter key&lt;/b&gt; to display the output:&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;? BuildCriteria(&amp;quot;OrderID&amp;quot;,dblong,&amp;quot;10200&amp;quot;) &lt;br /&gt;&lt;br /&gt;Result: &lt;font class="colrgreen"&gt;OrderID=10200&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;BuildCriteria()&lt;/b&gt; Function needs three Function Parameters. &lt;b&gt;OrderID&lt;/b&gt; is the Data Field Name, &lt;b&gt;dbLong&lt;/b&gt; indicates that OrderID is a Numeric Field with values of &lt;b&gt;Long Integer&lt;/b&gt; Type and the last Value &lt;b&gt;10200&lt;/b&gt; is OrderID Criteria value for selecting records. The &lt;b&gt;OrderID&lt;/b&gt; Field Name will be inserted in appropriate locations in the Criteria expression by the &lt;b&gt;BuildCriteria()&lt;/b&gt; Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The last parameter value we can use in several ways depending on how we want the result. Let us see few more examples before we implement this method on a Form. Type the following expressions in the Debug Window to see how it works:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;? BuildCriteria(&amp;quot;OrderID&amp;quot;,dblong, &amp;quot;&amp;gt;=10200 AND &amp;lt;10300&amp;quot;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Result: &lt;font class="colrgreen"&gt;OrderID&amp;gt;=10200 And OrderID&amp;lt;10300&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;? BuildCriteria(&amp;quot;OrderID&amp;quot;,dblong,&amp;quot;&amp;gt;=10200 AND &amp;lt;10300 OR &amp;gt;=10400 AND &amp;lt;10500&amp;quot;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   Result: &lt;font class="colrgreen"&gt;OrderID&amp;gt;=10200 And OrderID&amp;lt;10300 Or OrderID&amp;gt;=10400 And OrderID&amp;lt;10500&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Try changing the data type to dbText, for example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;? BuildCriteria(&amp;quot;OrderID&amp;quot;,dbText,&amp;quot;10200&amp;quot;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Result: &lt;font class="colrgreen"&gt;OrderID=&amp;quot;10200&amp;quot;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;? BbuildCriteria(&amp;quot;OrderDate&amp;quot;,dbDate,&amp;quot;&amp;gt;10/15/2009 and &amp;lt;=10/31/2009&amp;quot;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Result: &lt;font class="colrgreen"&gt;OrderDate&amp;gt;#10/15/2009# And OrderDate&amp;lt;=#10/31/2009#&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After getting the result text from the &lt;b&gt;BuildCriteria()&lt;/b&gt; Function all we have to do is to insert it into the Filter Property of the Form and turn &lt;b&gt;ON&lt;/b&gt; the Filter action.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us design a simple Form to Run our example straight away.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Import the &lt;b&gt;Orders&lt;/b&gt; Table from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office\Officell\Samples\Northwind.mdb&lt;/font&gt; sample database.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on &lt;b&gt;Orders&lt;/b&gt; Table to Select it and select &lt;b&gt;Form&lt;/b&gt; from &lt;b&gt;Insert&lt;/b&gt; Menu. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Auto Form:Tabular&lt;/b&gt; to create a &lt;a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form.shtml"&gt;Form &lt;/a&gt;and save it with the name &lt;b&gt;Orders&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the Orders Form in Design View. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Expand the &lt;b&gt;Form Header&lt;/b&gt; Area and drag all the Field Headings down to get enough room to create a &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; above the Field Headings.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the &lt;b&gt;ToolBox&lt;/b&gt;, if it is not visible (&lt;b&gt;View - -&gt;Toolbox&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; Tool and create a Command Button on the Header of the Form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;While the Command Button is still in selected state display its &lt;a href="http://www.msaccesstips.com/2008/09/source-connect-str-property-and-odbc.shtml"&gt;Property&lt;/a&gt; Sheet (&lt;b&gt;View --&gt; Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt; Property Value to &lt;b&gt;cmdFilter&lt;/b&gt; and change the &lt;b&gt;Caption&lt;/b&gt; Property Value to &lt;b&gt;OrderID Filter&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the &lt;b&gt;Code&lt;/b&gt; Module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;). &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following VBA Code into the Module.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Private Sub cmdFilter_Click()&lt;br /&gt;Dim txtCondition, txtFilter As String&lt;br /&gt;&lt;br /&gt;txtCondition = InputBox(&amp;quot;OrderID Value/Range of Values&amp;quot;)&lt;br /&gt;&lt;br /&gt;If Len(txtCondition) = 0 Then&lt;br /&gt;    Me.FilterOn = False&lt;br /&gt;    Exit Sub&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;txtFilter = BuildCriteria(&amp;quot;OrderID&amp;quot;, dbLong, txtCondition)&lt;br /&gt;&lt;br /&gt;Me.FilterOn = False&lt;br /&gt;Me.Filter = txtFilter&lt;br /&gt;Me.FilterOn = True&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Save and Close the Form. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;You may click on the &lt;b&gt;OrderID Filter&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; and enter any of the examples (except the one with Date) criteria expressions we have entered as third Parameter into the &lt;b&gt;BuildCriteria()&lt;/b&gt; Function above, when prompted for the Filter Condition.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;If you don&amp;#39t like to use &lt;b&gt;InputBox()&lt;/b&gt; to prompt for Criteria Values then you may create a Text Box on the Form where Users can enter the Criteria expression before hitting on the Command Button.&lt;br /&gt;&lt;br /&gt;The limitation of the &lt;b&gt;BuildCriteria()&lt;/b&gt; Function is that it can accept only one field as first parameter. But, there is a way to use more than one field for the Filter condition on the Form. Ask the &lt;a href="http://www.msaccesstips.com/2006/11/delete-msaccess-security-user-account.shtml"&gt;User&lt;/a&gt; to enter conditions for two different fields separately and run the &lt;b&gt;BuildCriteria()&lt;/b&gt; Function also separately to obtain the results. Join both results with &lt;b&gt;AND/OR&lt;/b&gt; Logical operators to filter the data.&lt;br /&gt;&lt;br /&gt;The following example Code uses &lt;b&gt;OrderID&lt;/b&gt; and &lt;b&gt;ShipName&lt;/b&gt; field values to Filter data on the &lt;b&gt;Orders&lt;/b&gt; Form.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a Copy of the &lt;b&gt;Orders&lt;/b&gt; Form and name the Form as &lt;b&gt;Orders2&lt;/b&gt;&lt;/li&gt;.&lt;br /&gt;&lt;li&gt;Open the Form in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Code Module of the Form ( &lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following Code into the Module replacing the existing Code:&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Private Sub cmdFilter_Click()&lt;br /&gt;Dim txtOrderNumber, txtOrderfilter As String&lt;br /&gt;Dim txtShipName, txtShipNameFilter As String&lt;br /&gt;Dim msg As String, resp, txtFilter As String&lt;br /&gt;&lt;br /&gt;txtOrderNumber = InputBox(&amp;quot;OrderID Value/Range of Values to Filter&amp;quot;)&lt;br /&gt;txtShipName = InputBox(&amp;quot;ShipName/Partial Text to Match&amp;quot;)&lt;br /&gt;&lt;br /&gt;If Len(txtOrderNumber) &gt; 0 Then&lt;br /&gt;txtOrderfilter = BuildCriteria(&amp;quot;OrderID&amp;quot;, dbLong, txtOrderNumber)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;If Len(txtShipName) &gt; 0 Then&lt;br /&gt;    txtShipNameFilter = BuildCriteria(&amp;quot;ShipName&amp;quot;, dbText, txtShipName)&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;If Len(txtOrderfilter) &gt; 0 And Len(txtShipNameFilter) &gt; 0 Then&lt;br /&gt;    msg = &amp;quot;1. Filter items-that matches both filter conditions&amp;quot; &amp;amp; vbCr &amp;amp; vbCr&lt;br /&gt;    msg = msg &amp;amp; &amp;quot;2. Matches either one or Both conditions&amp;quot; &amp;amp; vbCr &amp;amp; vbCr&lt;br /&gt;    msg = msg &amp;amp; &amp;quot;3. Cancel&amp;quot;&lt;br /&gt;    Do While resp &amp;lt;&amp;gt; 1 And resp &amp;lt;&amp;gt; 2 And resp &amp;lt;&amp;gt; 3&lt;br /&gt;        resp = InputBox(msg)&lt;br /&gt;    Loop&lt;br /&gt;    Select Case resp&lt;br /&gt;        Case 3&lt;br /&gt;            Exit Sub&lt;br /&gt;        Case 1&lt;br /&gt;            txtFilter = txtOrderfilter &amp;amp; &amp;quot; AND &amp;quot; &amp;amp; txtShipNameFilter&lt;br /&gt;        Case 2&lt;br /&gt;            txtFilter = txtOrderfilter &amp;amp; &amp;quot; OR &amp;quot; &amp;amp; txtShipNameFilter&lt;br /&gt;    End Select&lt;br /&gt;Else&lt;br /&gt;    txtFilter = txtOrderfilter &amp;amp; txtShipNameFilter&lt;br /&gt;    If Len(Trim(txtFilter)) = 0 Then&lt;br /&gt;       Exit Sub&lt;br /&gt;    End If&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Me.FilterOn = False&lt;br /&gt;If Len(Trim(txtFilter)) &amp;gt; 0 Then&lt;br /&gt;    Me.Filter = txtFilter&lt;br /&gt;    Me.FilterOn = True&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The first two &lt;b&gt;InputBox()&lt;/b&gt; Functions collects the Filter Criteria for &lt;b&gt;OrderID&lt;/b&gt; and &lt;b&gt;ShipName&lt;/b&gt; Field values separately. Next steps Validates the User responses and Builds the criteria strings in &lt;b&gt;txtOrderFilter&lt;/b&gt; and &lt;b&gt;txtShipNameFilter&lt;/b&gt; Variables.&lt;br /&gt;&lt;br /&gt;If both Variables have filter conditions in them then the User response is collected to check whether he/she needs the result set that meets both conditions (&lt;b&gt;AND&lt;/b&gt;) or result set that meets any one of the conditions or both (&lt;b&gt;OR&lt;/b&gt;).&lt;br /&gt;&lt;br /&gt;The Filter Strings are joined accordingly to obtain the intended result. It is not necessary that the User should always provide both set of Criteria Values (for &lt;b&gt;Orderld&lt;/b&gt; and &lt;b&gt;ShipName&lt;/b&gt;) all the time. They can use only one Field for entering Criteria and ignore the other.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/12/filter-with-buildcriteria-function.shtml&amp;amp;title=Filter+with+BuildCriteria+Function"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml"&gt;Office Assistant and MsgBox Menus-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml"&gt;Office Assistant and MsgBox Menus-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in MsgBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/microsoft-excel-power-in-ms-access.shtml"&gt;Microsoft Excel Power in Access&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-258607063638157084?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/12/filter-with-buildcriteria-function.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-6772139524909564592</guid><pubDate>Sun, 06 Dec 2009 15:37:00 +0000</pubDate><atom:updated>2009-12-06T20:15:56.309+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Process Controls</category><title>Save User Specific Parameter values</title><description>&lt;br /&gt;Last week we have prepared a Report &lt;a href="http://www.msaccesstips.com/2009/11/creating-using-form-custom-property.shtml"&gt;Parameter Control Form&lt;/a&gt; for concurrent usage on Network without clashing with other User’s &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Report&lt;/a&gt; Data Filter Parameter Values, while preparing different Versions of the same Report. To do this we have discarded the usage of a Parameter Table as Record Source to the Parameter &lt;a href="http://www.msaccesstips.com/2009/04/form-background-with-gradient-color.shtml"&gt;Form &lt;/a&gt;and created two Unbound Text Boxes for keying in Parameter Values for setting Filter condition in the Report Source Query. Besides that we have seen how to save the Parameter Values in the &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Custom Properties&lt;/a&gt; of the Form, when the Form is closed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The sample image of the &lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Report&lt;/a&gt; Parameter Form: &lt;b&gt;RptParameter&lt;/b&gt; is given below for reference:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/RptParameter-733059.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 312px;" src="http://www.msaccesstips.com/uploaded_images/RptParameter-733056.jpg" border="0" alt="Report Parameter Screen" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;Last week we have used the Parameter Control&amp;#39;s &lt;a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins.shtml"&gt;Text Box&lt;/a&gt; Names &lt;b&gt;FromDate&lt;/b&gt; and &lt;b&gt;ToDate&lt;/b&gt; for entering Date-Range values as Criteria for filtering Data in Report Source Query. The Custom Property Names we have created giving slight change to the Text Box Names, like &lt;b&gt;DateFrom&lt;/b&gt; and &lt;b&gt;DateTo&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;One Question we have raised last week was; is it possible to &lt;b&gt;Save&lt;/b&gt; and &lt;b&gt;Retrieve&lt;/b&gt; the &lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Report&lt;/a&gt; Parameter Values set by each User on the &lt;b&gt;fromDate&lt;/b&gt; and &lt;b&gt;toDate&lt;/b&gt; Text Box Controls, in different instances of the same Form, without getting overwritten by somebody else value.  In last week&amp;#39;s example the survivor of the values written to the &lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Custom Properties&lt;/a&gt; are the values of the last User who closes the Parameter Form.&lt;br /&gt;&lt;br /&gt;The solution is simple; create Custom Properties on the Form for each &lt;a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account.shtml"&gt;User&lt;/a&gt; and save the value set by him/her when their side instance of the Parameter Form is closed.  To identify each User&amp;#39;s value; add the &lt;b&gt;User-Name&lt;/b&gt; along with the TextBox Name and create the Custom Property Name with that combined text value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;pre class="alt3"&gt;&lt;br /&gt; User-Name               :  JSmith&lt;br /&gt;&lt;br /&gt;        Parameter TextBox Name1 :  fromDate&lt;br /&gt;        Parameter TextBox Name2 :  toDate&lt;br /&gt;&lt;br /&gt;        Custom Property Name1   :  JSmithDateFrom&lt;br /&gt;        Custom Property Name2   :  JSmithDateTo&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can get the User Name of the current instance of the Form with the Function &lt;b&gt;CurrentUser()&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When the User-Name is prefixed to the Custom Property Names we can easily save and retrieve individual User&amp;#39;s parameter values and use on their instance of the same &lt;a href="http://www.msaccesstips.com/2007/06/startup-screen-design.shtml"&gt;Form&lt;/a&gt; as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another point we have to keep in mind is that new Users may be added to the same &lt;a href="http://www.msaccesstips.com/2006/11/msaccess-security-group-account.shtml"&gt;Workgroup&lt;/a&gt; and this method should work for them also, when they start using the &lt;b&gt;RptParameter&lt;/b&gt; Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We must write the VBA Routines in such a way that whenever a new User starts working with the &lt;b&gt;RptParameter&lt;/b&gt; Form; the User must be identified as a new comer and Custom Properties for that User must be created automatically, rather than creating it manually as we did in the earlier example.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;The modified Custom Properties creation Program is given below. Copy and Paste the Code into a Standard Module of your Database.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CreateCustom_Property(ByVal frmName As String, ByVal usrName As String)&lt;br /&gt;‘-------------------------------------------------------------------------&lt;br /&gt;‘ Author : a.p.r. pillai&lt;br /&gt;‘ Date   : November-2009&lt;br /&gt;‘ All Rights Reserved by www.msaccesstips.com&lt;br /&gt;‘-------------------------------------------------------------------------&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;Dim prp As Property, getPrpValue&lt;br /&gt;Dim fld1 As String, fld2 As String&lt;br /&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;&lt;br /&gt;fld1 = usrName &amp;amp; &amp;quot;DateFrom&amp;quot;&lt;br /&gt;fld2 = usrName &amp;amp; &amp;quot;DateTo&amp;quot;&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(frmName)&lt;br /&gt;&lt;br /&gt;'check whether the Property of the current user exists&lt;br /&gt;getPrpValue = doc.Properties(fld1).Value&lt;br /&gt;&lt;br /&gt;If Err = 3270 Then ' referenced Property doesn't exist&lt;br /&gt;    Err.Clear&lt;br /&gt;    'create Property for new User&lt;br /&gt;    Set prp = doc.CreateProperty(fld1, dbDate, Date)&lt;br /&gt;    doc.Properties.Append prp&lt;br /&gt;    Set prp = doc.CreateProperty(fld2, dbDate, Date)&lt;br /&gt;    doc.Properties.Append prp&lt;br /&gt;    doc.Properties.Refresh&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Set prp = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Create a Copy of the &lt;b&gt;RptParameter&lt;/b&gt; Form with the name &lt;b&gt;RptParameter2&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;RptParameter2&lt;/b&gt; Form in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the VBA Module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following Sub-Routines into the VBA Module overwriting the earlier Code:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;Dim fld1 As String, fld2 As String&lt;br /&gt;&lt;br /&gt;fld1 = CurrentUser &amp;amp; &amp;quot;DateFrom&amp;quot;&lt;br /&gt;fld2 = CurrentUser &amp;amp; &amp;quot;DateTo&amp;quot;&lt;br /&gt;&lt;br /&gt;'Validate Current User's Status&lt;br /&gt;'If, necessary create Custom Properties for new User&lt;br /&gt;CreateCustom_Property Me.Name, CurrentUser&lt;br /&gt;&lt;br /&gt;DoCmd.Restore&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(Me.Name)&lt;br /&gt;&lt;br /&gt;Me![fromDate] = doc.Properties(fld1).Value&lt;br /&gt;Me![toDate] = doc.Properties(fld2).Value&lt;br /&gt;&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Private Sub Form_Close()&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;Dim fld1 As String, fld2 As String&lt;br /&gt;&lt;br /&gt;fld1 = CurrentUser &amp;amp; &amp;quot;DateFrom&amp;quot;&lt;br /&gt;fld2 = CurrentUser &amp;amp; &amp;quot;DateTo&amp;quot;&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(Me.Name)&lt;br /&gt;&lt;br /&gt;doc.Properties(fld1).Value = Me![fromDate]&lt;br /&gt;doc.Properties(fld2).Value = Me![toDate]&lt;br /&gt;&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save and Close the Form.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;As you can see from the &lt;b&gt;Form_Load()&lt;/b&gt; Event Procedure that the Custom Property Creation Program &lt;b&gt;CreateCustom_Property()&lt;/b&gt; is called only when the User (New or existing) opens the &lt;b&gt;RptParameter2&lt;/b&gt; Form. So, the Custom properties are not created for all the Users of the Database if their activity doesn&amp;#39;t involve this particular Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Report&lt;/a&gt; Parameter Form must be tested from different machines at the same time by different Users and set their own values in the Parameter Control Text Boxes: &lt;b&gt;fromDate&lt;/b&gt; and &lt;b&gt;toDate&lt;/b&gt; to try out the procedure. When the Form is open by the same Users next time the values set by them in the earlier session should appear in &lt;b&gt;fromDate&lt;/b&gt; and &lt;b&gt;toDate&lt;/b&gt; Text Box Controls.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt;  The above Procedure is not extensively tested to trap Bugs or side effects and you may use it at your own risk.  If you find any Bugs or issues please share it with me too.  The procedure assumes that the Database is implemented with &lt;a href="http://www.msaccesstips.com/2006/11/microsoft-access-security.shtml"&gt;Microsoft Access Security&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Visit the Page: &lt;a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log.shtml"&gt;Unsecured Database and Users Log&lt;/a&gt; to find out how to get User&amp;#39;s Name when the shared database is an Un-secured one.  In un-secured databases the &lt;b&gt;CurrentUser()&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2007/09/useful-report-functions.shtml"&gt;Function&lt;/a&gt; will always return the User Name as  &lt;b&gt;Admin&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/12/save-user-specific-parameter-values.shtml&amp;amp;title=Save+User+Specific+Parameter+Values"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml"&gt;Office Assistant and MsgBox Menus-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in MsgBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/microsoft-excel-power-in-ms-access.shtml"&gt;Microsoft Excel Power in Access&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log.shtml"&gt;Un-secured Database and Users-Log&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-6772139524909564592?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/12/save-user-specific-parameter-values.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-8421066706586401580</guid><pubDate>Sun, 29 Nov 2009 18:11:00 +0000</pubDate><atom:updated>2009-11-29T22:36:26.061+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Process Controls</category><title>Creating Using Form Custom Property</title><description>&lt;br /&gt;&lt;br /&gt;Parameter Controls are provided to the Users for entering data Filter criteria values for preparing MS-Access Reports.  A reference to the parameter control fields can be set in the criteria row of the Report Source Query directly to filter the data. A sample image of such a Parameter Control is given below. &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/RptParameter-733059.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 312px;" src="http://www.msaccesstips.com/uploaded_images/RptParameter-733056.jpg" border="0" alt="Report Parameter Screen" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The above &lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Report&lt;/a&gt; Parameter Control gives flexibility to the User to set a &lt;b&gt;Date Range&lt;/b&gt; in the fields provided on the screen before opening one of two Report Options provided.  When the User Clicks on the &lt;b&gt;Preview&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Button&lt;/a&gt; the Report will be opened with data filtered using the Parameter Control &lt;b&gt;Date Range&lt;/b&gt; values set as Criteria on the Source Query. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;To record the Date Range values (&lt;b&gt;Date From&lt;/b&gt; and &lt;b&gt;Date To&lt;/b&gt;) a small Table with two fields is created with a single record and used as &lt;b&gt;Record Source&lt;/b&gt; to the above Form. The idea behind the use of a Table is to preserve the last used Report Parameter Values in the Table. Next time when we open the Form we will know for which period we have prepared the Report earlier. The parameter table can also be used in the Query to link with the Data Table or use its value as criteria in the criteria Row of the Report Source Query. The following two &lt;b&gt;Form Property&lt;/b&gt; Values must be set as shown below to prevent adding new Records to the Table and not to delete the existing one: &lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;Allow Additions = No&lt;br /&gt;Allow Deletion = No&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;This method works fine when the Database is a Single User one. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, when the database is shared on a Network there is a problem to this method. Different Users may open the same Parameter Screen at the same time to prepare their version of the same Report. They will attempt to change the parameter values at the same time.  This action will end up with a record edit lock error or the values set can cross over and the Report printed can go wrong too. Even though the Users can open different instances of the same &lt;a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars.shtml"&gt;Form&lt;/a&gt; on their machines the Record Source Table is same. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We are focusing on this particular aspect to see how we can safely provide the above Parameter Control to the Users to work safely without clashing each other. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Perhaps, you have the right solution to this problem by now.  Yes, do not use the Parameter Table to store the Report criteria values; instead create two Unbound Text Boxes on the Form, as you have rightly guessed.  This will ensure that all Users will work independently on their own instances of the Report Parameter Form and no chance of clashing with each other&amp;#39;s values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There is only a minor draw back in this method; you cannot store the last used Report Parameter Value anywhere so that it will be displayed next time when you open the Form. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;At least one set of value is required when you open the Form next time. If these controls remain empty and if you run the Preview option without setting the parameter values then the Report will be empty and will end up showing &lt;b&gt;#Error&lt;/b&gt; in all controls with expressions created for Summary Values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;I have already published an Article on this topic earlier as how to open the Report without this Error condition when the Report Source Query or Table is empty. &lt;a href="http://www.msaccesstips.com/2008/09/no-data-and-report-error.shtml"&gt;Click here&lt;/a&gt; to find out.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can save the values, from the Unbound Text Box controls, on the Parameter Form itself in &lt;b&gt;Custom Properties&lt;/b&gt;, which we can create on the Form.  Managing data in Custom Properties can be done only through VBA and these &lt;b&gt;Property Names&lt;/b&gt; and their Values are not visible on the &lt;b&gt;Property Sheets&lt;/b&gt; that we normally work with. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Click here&lt;/a&gt; to find out more details on Custom Properties and a method that we have used earlier to open the Form with last edited record as current on the Form.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have to go through the following procedure to manage the User data on the Form itself without the use of a Table as Record Source: &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Create two Custom Properties on the Form with the names &lt;b&gt;DateFrom&lt;/b&gt; and &lt;b&gt;DateTo&lt;/b&gt; with the Data Type &lt;b&gt;Date/Time&lt;/b&gt; and with an initial Value.&lt;/li&gt;&lt;br /&gt; This is required only once. A small VBA Program is required in the Standard Module to create the Custom Properties on the Form. In the Program the Parameter Form &lt;b&gt;Name&lt;/b&gt; is required for reference.  Not necessary to keep the Form in Design View to create the Custom Properties.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;When the Parameter Form is closed after normal use the values set on the Unbound Text Boxes are &lt;b&gt;Saved&lt;/b&gt; into the Custom Properties during the Form Close Event.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;The saved values are &lt;b&gt;loaded&lt;/b&gt; back into the Unbound Text Boxes from the &lt;b&gt;Custom Properties&lt;/b&gt; when the Report Parameter Form is open next time.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;To try out this method, open a new Form and create two Unbound Text Boxes.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the first Text Box and display its Property Sheet (&lt;b&gt;View - -&gt; Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt; Property Value to &lt;b&gt;fromDate&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt; Property Value of the second Text Box to &lt;b&gt;toDate&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Close and save the Form with the name &lt;b&gt;RptParameter&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Display the VBA Editing Window (&lt;b&gt;Alt+F11&lt;/b&gt;), copy and paste the following VBA Code into the Standard Module. If necessary, create a new Module (&lt;b&gt;Insert - -&gt; Module&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function CreateCustomProperty()&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;Dim prp As Property&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(&amp;quot;RptParameter&amp;quot;)&lt;br /&gt;&lt;br /&gt;Set prp = doc.CreateProperty(&amp;quot;DateFrom&amp;quot;, dbDate, Date)&lt;br /&gt;doc.Properties.Append prp&lt;br /&gt;&lt;br /&gt;Set prp = doc.CreateProperty(&amp;quot;DateTo&amp;quot;, dbDate, Date)&lt;br /&gt;doc.Properties.Append prp&lt;br /&gt;&lt;br /&gt;doc.Properties.Refresh&lt;br /&gt;&lt;br /&gt;Set prp = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click somewhere within the pasted VBA Code and press &lt;b&gt;F5&lt;/b&gt; to Run the Code and create two Custom Properties with the Names &lt;b&gt;DateFrom&lt;/b&gt; and &lt;b&gt;DateTo&lt;/b&gt; with the Data Type &lt;b&gt;Date/Time&lt;/b&gt; and with the initial value of System Date.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;How do you know whether these Properties are created or not? Try running the Program again and this will tell you that these Property names already exist on the Form.&lt;br /&gt;&lt;br /&gt;If you want to &lt;b&gt;Delete&lt;/b&gt; these Properties from the Form then Run the following Code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function DeleteCustomProperty()&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;Dim prp As Property&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(&amp;quot;RptParameter&amp;quot;)&lt;br /&gt;&lt;br /&gt;doc.Properties.Delete &amp;quot;DateFrom&amp;quot;&lt;br /&gt;doc.Properties.Delete &amp;quot;DateTo&amp;quot;&lt;br /&gt;doc.Properties.Refresh&lt;br /&gt;&lt;br /&gt;Set prp = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;RptParameter&lt;/b&gt; Form in Desgin View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the VBA Code Module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following two Sub-Routines into the Form Module and save the Form:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Private Sub Form_Close()&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(&amp;quot;RptParameter&amp;quot;)&lt;br /&gt;&lt;br /&gt;doc.Properties(&amp;quot;DateFrom&amp;quot;).Value = Me![fromDate]&lt;br /&gt;doc.Properties(&amp;quot;DateTo&amp;quot;).Value = Me![toDate]&lt;br /&gt;&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;Dim cdb As Database, doc As Document&lt;br /&gt;&lt;br /&gt;DoCmd.Restore&lt;br /&gt;&lt;br /&gt;Set cdb = CurrentDb&lt;br /&gt;Set doc = cdb.Containers(&amp;quot;Forms&amp;quot;).Documents(&amp;quot;RptParameter&amp;quot;)&lt;br /&gt;&lt;br /&gt;Me![fromDate] = doc.Properties(&amp;quot;DateFrom&amp;quot;).Value&lt;br /&gt;Me![toDate] = doc.Properties(&amp;quot;DateTo&amp;quot;).Value&lt;br /&gt;&lt;br /&gt;Set cdb = Nothing&lt;br /&gt;Set doc = Nothing&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;RptParameter&lt;/b&gt; Form in Normal View and enter some Date Range values into &lt;b&gt;fromDate&lt;/b&gt; and &lt;b&gt;toDate&lt;/b&gt; Unbound Text Boxes.&lt;/li&gt;&lt;br /&gt;&lt;/li&gt;Close the Form and open it again in Normal View.  The date values you have entered earlier will appear in both Unbound Text Boxes.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;Even after implementing this method I am not fully happy with it. Because, it will preserve only one of the Values, set by different Users working with the Form at the same time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What I would like to see as a User is that the last value that I set on the Report Parameter Field is appearing on the &lt;a href="http://www.msaccesstips.com/2008/10/wave-shaped-reminder-ticker.shtml"&gt;Form&lt;/a&gt; again when I open the Form next time, not the value set by someone else. Is it possible? Yes, it is possible. We will see how to do this next week.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/11/creating-using-form-custom-property.shtml&amp;amp;title=Creating +Using+Form+Custom+Property"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in MsgBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/microsoft-excel-power-in-ms-access.shtml"&gt;Microsoft Excel Power in Access&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log.shtml"&gt;Un-secured Database and Users-Log&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals.shtml"&gt;MS-Access Report and Page Total&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-8421066706586401580?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/11/creating-using-form-custom-property.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-3559471420887368069</guid><pubDate>Sun, 22 Nov 2009 17:21:00 +0000</pubDate><atom:updated>2009-12-06T20:14:28.835+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccessprocess</category><title>MS-Access And Data Processing-2</title><description>&lt;br /&gt;&lt;br /&gt;This is the continuation of earlier Article published on this subject last week. &lt;a href="http://www.msaccesstips.com/2009/11/ms-access-and-data-processing.shtml"&gt;Click here&lt;/a&gt; to visit that Page.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Last week we have explored the sample data processing methods and tried to approach the same problem in different ways to arrive at the same result. Reports are the main output component that goes to the User with critical information for analysis of business activities and for making serious business decisions. Transforming raw data into meaningful form and providing them on Reports is a real challenge of any Project.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you attain some working knowledge of different types of Queries available in MS-Access you can do most of these tasks without touching the VBA Code. Depending upon the complexity of processing steps you can use several Queries, create intermediate temporary Tables and use those tables as source for other Queries to overcome issues that may arise as hurdles in the processing steps.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will look into such an issue here so that you will know what I meant by hurdles in creating the final Report.  Such complex data processing steps can be automated by sequencing each step in a Macro and run that Macro from a Command Button Click or from VBA Sub-Routines.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It is absolutely necessary to create and maintain Flow Charts of process that involves several Queries and Tables for Reports. You may create hundreds of Queries in a Database for different Reports.  After some time we may forget what we did for a particular Report.  If the User points out any flaw in the output then we can easily back track the steps using the Flow Chart and debug the problem.&lt;br /&gt;&lt;br /&gt;Last week I have raised a question as how we will show &lt;b&gt;Revenue, Expenses&lt;/b&gt; and &lt;b&gt;Profit/Loss&lt;/b&gt; month-wise if the sample data are added with &lt;b&gt;Year&lt;/b&gt; and &lt;b&gt;Month&lt;/b&gt; Fields.  The image of the sample Table (&lt;b&gt;Transactions2&lt;/b&gt;) Source data is given below:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DP2Table1-788444.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 222px; height: 320px;" src="http://www.msaccesstips.com/uploaded_images/DP2Table1-788437.jpg" border="0" alt="Transaction2 Table with Year and Month" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;The image of the Report Output Created and presented to you last week is shown below:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable7-787934.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 51px;" src="http://www.msaccesstips.com/uploaded_images/DPTable7-787926.jpg" border="0" alt="Transaction with Year and Month" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;We can transform the sample data given in the first image above into the &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Report&lt;/a&gt; output form in the second image in two steps.  The numbers appearing as Suffix to the Column headings represents the Month Value. For example, &lt;b&gt;Revenue1&lt;/b&gt; is &lt;b&gt;January Revenue&lt;/b&gt; and &lt;b&gt;Profit/Loss2&lt;/b&gt; is of February.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can arrive at the above result in two steps and the SQL String of those two Queries are given below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Query Name: &lt;b&gt;Method2_1&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;TRANSFORM Sum(Transactions2.Amount) AS SumOfAmount&lt;br /&gt;SELECT Transactions2.Location, Transactions2.Year&lt;br /&gt;FROM Transactions2&lt;br /&gt;GROUP BY Transactions2.Location, Transactions2.Year&lt;br /&gt;PIVOT IIf([type]=&amp;quot;R&amp;quot;,&amp;quot;Revenue&amp;quot;,&amp;quot;Expenses&amp;quot;) &amp;amp; [Month];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the above SQL String into the SQL Editing Window of a new Query and save it with the name &lt;b&gt;Method2_1. &lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the Query and view the output as how it is transformed with the Cross-Tab Query.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Query Name: &lt;b&gt;Method2_2&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT Method2_1.Location, Method2_1.Year, &lt;br /&gt;Method2_1.Revenue1, Method2_1.Expenses1,&lt;br /&gt; [Revenue1]-[Expenses1] AS [Profit/Loss1],&lt;br /&gt; Method2_1.Revenue2, Method2_1.Expenses2,&lt;br /&gt; [Revenue2]-[Expenses2] AS [Profit/Loss2]&lt;br /&gt;FROM Method2_1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the above SQL String into the SQL Editing Window of a new Query and save it with the name &lt;b&gt;Method2_2&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;We are using the first &lt;a href="http://www.msaccesstips.com/2008/10/multiple-parameters-for-query.shtml"&gt;Query&lt;/a&gt; as input to the second Query for the final &lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Report&lt;/a&gt; output.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Method2_2&lt;/b&gt; Query and view the output.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;Even though we could arrive at the sample result with the above two Queries we have to modify the second Query every time to create &lt;b&gt;Profit/Loss&lt;/b&gt; Column when new data records are added for subsequent months. The P &amp;amp; L Report if created using the second Query then that also has to undergo changes to add &lt;b&gt;Revenue, Expenses&lt;/b&gt; and &lt;b&gt;Profit&lt;/b&gt; Columns for the new period.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This cannot be a good method when we are expected to automate every process in the Database so that the User can prepare Reports with the click of a Button.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can automate this data processing task permanently with the following few simple steps:&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a second Report Table with &lt;b&gt;Revenue&lt;/b&gt; and &lt;b&gt;Expenses&lt;/b&gt; Fields for all twelve months.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the second Query created above (&lt;b&gt;Method2_2&lt;/b&gt;) as an append query and add the output data of available months into the Report Table.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a SELECT Query using the Report Table as source to calculate &lt;b&gt;Profit/Loss&lt;/b&gt; Values for all twelve months only once. This is possible because we have all twelve month&amp;#39;s data fields in the Report Table, even if some of them will have only zero values till December.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Design the &lt;b&gt;P&amp;amp;L Report&lt;/b&gt; with all twelve months &lt;b&gt;Revenue, Expenses&lt;/b&gt;&amp;amp;&lt;b&gt;Profit/Loss&lt;/b&gt; Fields using the Query created in &lt;b&gt;Step-3&lt;/b&gt; as source.&lt;br /&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;Once you implement this method you don&amp;#39;t have to make any changes to the Queries or &lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Report&lt;/a&gt; when new data records are added in the Source Table.   All you have to do is to automate this process, like deleting the old data (for this action we will need a &lt;b&gt;Delete&lt;/b&gt; type Query) from the Report Table and bringing in fresh Report data from source table &lt;b&gt;Transactions2&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So, let us get to work and do it.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a Table with the following Field Structure and save it with the name &lt;b&gt;PandLReportTable&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;The Data Fields &lt;b&gt;R1&lt;/b&gt; to &lt;b&gt;R12&lt;/b&gt; and &lt;b&gt;E1&lt;/b&gt; to &lt;b&gt;E12&lt;/b&gt; will hold &lt;b&gt;Revenue&lt;/b&gt; and &lt;b&gt;Expenses&lt;/b&gt; Values respectively for the period from &lt;b&gt;January&lt;/b&gt; to &lt;b&gt;December&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB: &lt;/b&gt; Don&amp;#39;t forget to set the &lt;b&gt;Default Value&lt;/b&gt; Property of all &lt;b&gt;Number&lt;/b&gt; Fields with &lt;b&gt;0&lt;/b&gt; values as shown in the &lt;b&gt;Property Sheet&lt;/b&gt; below the Field Structure.  This will prevent from adding data fields with &lt;b&gt;Null&lt;/b&gt; Values when data is not available for those fields. Remember, when you write expressions using Numeric Fields with &lt;b&gt;Null&lt;/b&gt; values combined with fields with values; the end result will be &lt;b&gt;Null&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/RptStructure-706280.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 197px; height: 320px;" src="http://www.msaccesstips.com/uploaded_images/RptStructure-706276.jpg" border="0" alt="Report Table Structure" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;We have modified the first Query given above for simplifying the data field names. &lt;br /&gt;  &lt;br /&gt;&lt;li&gt;Copy and paste the following SQL String into a new Query&amp;#39;s SQL Editing Window and save it with the name &lt;b&gt;Method3_l&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;TRANSFORM Sum(Transactions2.Amount) AS SumOfAmount&lt;br /&gt;SELECT Transactions2.Location, Transactions2.Year&lt;br /&gt;FROM Transactions2&lt;br /&gt;GROUP BY Transactions2.Location, Transactions2.Year&lt;br /&gt;PIVOT [type]&amp;amp;[Month];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the SQL string given below into a new Query and save it with the name &lt;b&gt;Method3_2&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;INSERT INTO PandLReportTable&lt;br /&gt;SELECT Method3_1.*&lt;br /&gt;FROM Method3_1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the following SQL String into a new Query and save it with the name &lt;b&gt;PandLReportQ&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;SELECT PandLReportTable.Location, PandLReportTable.Year, &lt;br /&gt;PandLReportTable.R1, PandLReportTable.E1, [R1]-[E1] AS P1,&lt;br /&gt; PandLReportTable.R2, PandLReportTable.E2, [R2]-[E2] AS P2, &lt;br /&gt;PandLReportTable.R3, PandLReportTable.E3, [R3]-[E3] AS P3, &lt;br /&gt;PandLReportTable.R4, PandLReportTable.E4, [R4]-[E4] AS P4, &lt;br /&gt;PandLReportTable.R5, PandLReportTable.E5, [R5]-[E5] AS P5,&lt;br /&gt; PandLReportTable.R6, PandLReportTable.E6, [R6]-[E6] AS P6,&lt;br /&gt; PandLReportTable.R7, PandLReportTable.E7, [R7]-[E7] AS P7, &lt;br /&gt;PandLReportTable.R8, PandLReportTable.E8, [R8]-[E8] AS P8, &lt;br /&gt;PandLReportTable.R9, PandLReportTable.E9, [R9]-[E9] AS P9, &lt;br /&gt;PandLReportTable.R10, PandLReportTable.E10, [R10]-[E10] AS P10, &lt;br /&gt;PandLReportTable.R11, PandLReportTable.E11, [R11]-[E11] AS P11, &lt;br /&gt;PandLReportTable.R12, PandLReportTable.E12, [R12]-[E12] AS P12&lt;br /&gt;FROM PandLReportTable;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Design a Report using &lt;b&gt;PandLReportQ&lt;/b&gt; as Source File, like the sample design image given below.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;The sample image shows Columns of &lt;b&gt;January&lt;/b&gt; and &lt;b&gt;February&lt;/b&gt; only.   But, you may design the Report for all twelve months in similar way. The Value from &lt;b&gt;Year&lt;/b&gt; field is used for creating Headings so that it automatically changes when the Report is printed next year without modification to the Report.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/PLSDesign-747138.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 96px;" src="http://www.msaccesstips.com/uploaded_images/PLSDesign-747135.jpg" border="0" alt="P and L Report Design Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The above Report in Print Preview is given below.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/PLStatement-777040.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 63px;" src="http://www.msaccesstips.com/uploaded_images/PLStatement-777034.jpg" border="0" alt="P and L Statement in Print Preview" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;We will automate the P&amp;amp;L Report preparation procedure to get updated data on the &lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Report&lt;/a&gt; when new data of &lt;b&gt;Revenue&lt;/b&gt; and &lt;b&gt;Expenses&lt;/b&gt; are added to the Source Table.   As part of the automation procedure we need a &lt;b&gt;Delete Query&lt;/b&gt; to remove the earlier data from the &lt;b&gt;PandLReportTable&lt;/b&gt; before adding revised data into it.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Create a new Query with the following SQL String and name the Query as &lt;b&gt;PandLReportTable_Init&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;DELETE PandLReportTable.*&lt;br /&gt;FROM PandLReportTable;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Isn&amp;#39;t it easy enough to prepare the P&amp;amp;L Report with the above simple Queries and with a supporting Report Table for any number of Locations that you add to your main Source Table &lt;b&gt;Transactions2&lt;/b&gt;.  As you can see now you don&amp;#39;t need any complicated programs to prepare this Report.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you look at the &lt;a href="http://www.msaccesstips.com/2008/02/union-query.shtml"&gt;Queries&lt;/a&gt; we have created we can see that there are only two &lt;b&gt;Action Queries&lt;/b&gt; among them (&lt;b&gt;Delete&lt;/b&gt; and &lt;b&gt;Append&lt;/b&gt; Queries).  We can put these two Queries into a Macro to automate the P&amp;amp;L Report preparation easily. But first, let us examine the logical arrangement of this Report preparation procedure with a Process Flow Chart.&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DP2Flow-732210.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 261px;" src="http://www.msaccesstips.com/uploaded_images/DP2Flow-732203.jpg" border="0" alt="Data Processing Flow Chart" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;In &lt;b&gt;Step-1&lt;/b&gt; the &lt;b&gt;PandLReportTable_Init &lt;/b&gt; Query removes earlier Report Data from the &lt;b&gt;PandLReportTable&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In &lt;b&gt;Step-3&lt;/b&gt; the Append Query (&lt;b&gt;Method3_2&lt;/b&gt;) takes the Cross-Tab Query output from &lt;b&gt;Step-2&lt;/b&gt; and adds them to the Report Table &lt;b&gt;PandLReportTable&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have already written expressions in &lt;b&gt;PandLReportQ&lt;/b&gt; &lt;b&gt;SELECT&lt;/b&gt; Query to calculate &lt;b&gt;Profit/Loss&lt;/b&gt; Values.  The Report will automatically get all available data from this Query and other Columns on the Report will remain empty till fresh data Records are added in the Source Table &lt;b&gt;Transactions2&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we can add both the &lt;b&gt;Action Queries&lt;/b&gt; into a &lt;b&gt;Macro&lt;/b&gt; (or VBA Subroutine) then the User can click on a &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; to run it every month to create the Report with added data within seconds.&lt;br /&gt;The sample image of the Macro with the Action Queries in sequence is given below for reference:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPMacro-789787.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 171px;" src="http://www.msaccesstips.com/uploaded_images/DPMacro-789780.jpg" border="0" alt="Process Automation Macro Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;If you can further simplify this procedure please share that idea with me too?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/11/ms-access-and-data-processing-2.shtml&lt;br /&gt;&amp;amp;title=MS-Access+and+Data+Processing-2"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in MsgBox&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/microsoft-excel-power-in-ms-access.shtml"&gt;Microsoft Excel Power in Access&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log.shtml"&gt;Un-secured Database and Users-Log&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals.shtml"&gt;MS-Access Report and Page Total&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Detail and Summary from Same Report&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-3559471420887368069?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/11/ms-access-and-data-processing-2.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>4</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-9219891714526163685</guid><pubDate>Sun, 15 Nov 2009 16:41:00 +0000</pubDate><atom:updated>2009-11-15T21:43:15.308+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccessprocess</category><title>MS-Access and Data Processing</title><description>&lt;br /&gt;&lt;br /&gt;Designing &lt;a href="http://www.msaccesstips.com/2009/04/form-background-with-gradient-color.shtml"&gt;Forms&lt;/a&gt; or &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Reports&lt;/a&gt; can be learned quickly by mastering the usage of Design Tools available in MS-Access, keeping aside the programming aspects.  But, data processing is something that demands diversity in each Project and cannot be standardized. The data Table design is very important and these must be carefully planned and created for easier retrieval of information as well as to avoid duplication.  Proper relationships must be established between Tables to join related information together.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ignoring the importance of these considerations, designing with casual approach and filling up data in them like you do in Microsoft Excel will land you in trouble when you attempt to prepare reports out of them.&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;You can see a good example of database design in the &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office11\Samples\Northwind.mdb&lt;/font&gt; sample Database.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Open this sample database and select &lt;b&gt;Relationships&lt;/b&gt; from &lt;b&gt;Tools&lt;/b&gt; Menu to view the structure of various Tables and how they are organized and related one another.  Use it as a reference point and guide when you plan for a new Project.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Each Field Name in bold is defined as &lt;b&gt;Primary Key&lt;/b&gt; in their respective Table and established &lt;b&gt;One-to-many&lt;/b&gt; Relationships to one another. This will ensure the availability of required information when needed from related tables for Reports.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above lines were only a reminder to your future projects. You can see an example image of a bad Table design below. The &lt;b&gt;Location&lt;/b&gt; names and &lt;b&gt;Description&lt;/b&gt; values should have been in Tables of their own with appropriate Codes. Two &lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;Combo Boxes&lt;/a&gt; can be created in the &lt;b&gt;Transactions&lt;/b&gt; Table Structure to insert those Codes into the fields to avoid duplication of information as shown below. &lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable1-735668.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 300px; height: 320px;" src="http://www.msaccesstips.com/uploaded_images/DPTable1-735650.jpg" border="0" alt="Source Data Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;But here, we are going to concentrate on learning the data processing steps using the above Table. &lt;br /&gt; &lt;br /&gt;The second data field &lt;b&gt;Type&lt;/b&gt; contains transaction type Codes. &lt;b&gt;R&lt;/b&gt; stands for &lt;b&gt;Revenue&lt;/b&gt; and &lt;b&gt;E&lt;/b&gt; for &lt;b&gt;Expenses&lt;/b&gt;.  These category Codes are introduced in the Table keeping in mind that we must be able to Group the transactions on Category and Tabulate the &lt;b&gt;Revenue&lt;/b&gt; and &lt;b&gt;Expenses&lt;/b&gt; Values separately. The Description field shows the actual Account Heads under which each transaction is recorded.&lt;br /&gt;&lt;br /&gt;We have been asked to prepare a Location-wise &lt;b&gt;Profit/Loss&lt;/b&gt; Statement. Subtracting the Total of all Expenses from the Total of all Revenue figures will give us the required result.  How many Queries or steps you require to solve this problem, any idea? We require only the final &lt;b&gt;Profit/Loss&lt;/b&gt; value with the &lt;b&gt;Location Name&lt;/b&gt; on the Report, like the image below:&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable2-732001.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 155px; height: 68px;" src="http://www.msaccesstips.com/uploaded_images/DPTable2-731996.jpg" border="0" alt="Quick Report Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The first thought in your mind, I presume may be, how you can subtract the value of one Row from the other. Then you are thinking on the right direction.&lt;br /&gt;&lt;br /&gt;If you say &lt;b&gt;in four steps&lt;/b&gt; I will not accept that as a good approach but if you can solve the problem and come out with the result then that is OK with me.  After all, the correct end-result is all that matters as far as the User is concerned.&lt;br /&gt;&lt;br /&gt;If you say &lt;b&gt;in three steps&lt;/b&gt; I will be happy to see you how you do it.  If you say &lt;b&gt;in two steps&lt;/b&gt; then I know you have some grip on things around here. If you say &lt;b&gt;in one step&lt;/b&gt; then I know you are somebody with MS-Access.&lt;br /&gt;&lt;br /&gt;If you are really interested in taking up this simple challenge then stop reading further down from here and start trying out this in a database of your own.  Come back with your own solution and compare it on the examples given here. If you do it differently, but arrived at the same result then share that idea with me too.&lt;br /&gt;&lt;br /&gt;Create the &lt;b&gt;Transactions&lt;/b&gt; Table with the Structure and sample data given above. &lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;b&gt;One Step solution&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy the following SQL String into the SQL Editing Window of a new Query and save it with a name you prefer.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;SELECT Transactions.Location, Sum(IIf([type]=&amp;quot;E&amp;quot;,-[Amount],[Amount])) AS Profit&lt;br /&gt;FROM Transactions&lt;br /&gt;GROUP BY Transactions.Location;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;a href="http://www.msaccesstips.com/2008/04/finding-consecutive-workdays-with-query.shtml"&gt;Query&lt;/a&gt; in Normal View and you will see the result of the Query as shown in the second Image given above.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;b&gt;Two Step solution&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create a Query with the following SQL String and name the Query as &lt;b&gt;Query_Step1&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="Alt1"&gt;&lt;br /&gt;SELECT Transactions.*, IIf([Type]=&amp;quot;E&amp;quot;,-[Amount],[Amount]) AS Amt&lt;br /&gt;FROM Transactions;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The Query output will look like the image given below:&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable3-779371.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 264px;" src="http://www.msaccesstips.com/uploaded_images/DPTable3-779351.jpg" border="0" alt="Query Result with formatted Column" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;b&gt;Tip:&lt;/b&gt;&lt;i&gt; The Query &lt;b&gt;Amt&lt;/b&gt; Column is formatted to display Negative Values in Color and in brackets. Open the Query in Design View. Highlight the Column and click on the &lt;b&gt;Properties&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars.shtml"&gt;Toolbar&lt;/a&gt; Button or select &lt;b&gt;Properties&lt;/b&gt; from &lt;b&gt;View&lt;/b&gt; Menu to display the &lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Property&lt;/a&gt; Sheet of the Column. Type &lt;font class=”colrgreen”&gt;0.00;[Red](0.00);0.00;0.00&lt;/font&gt; into the &lt;b&gt;Format&lt;/b&gt; Property and save the Query. If you open the Query now the output will appear in color.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Format Property Values are expressed in four segments separated with semi-colons.  First segment dictates how to display positive values, second segment stands for Negative values, third segment says what to display when the field value is &lt;b&gt;Zero&lt;/b&gt; and fourth segment displays zero when the Field/Column contain &lt;b&gt;Null&lt;/b&gt;.  Third and fourth segments can be set with a literal string like &lt;font class="colrgreen"&gt; 0.00;[Red](0.00);"Zero";"Null"&lt;/font&gt; to display these values rather than &lt;b&gt;0.00&lt;/b&gt;. You can set the Field &lt;b&gt;Format&lt;/b&gt; Property values on the Table Structure, on &lt;a href="http://www.msaccesstips.com/2008/10/wave-shaped-reminder-ticker.shtml"&gt;Forms&lt;/a&gt; or on &lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Reports&lt;/a&gt;. It is not necessary that you should use all the four segments of the Format Property Values all the time.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Create another Query, with the following SQL String, using &lt;b&gt;Query_Step1&lt;/b&gt; as Source Data and save the Query with the name &lt;b&gt;PL_Report&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre class="Alt1"&gt;&lt;br /&gt;SELECT Query_Step1.Location, Sum(Query_Step1.Amt) AS Amount&lt;br /&gt;FROM Query_Step1&lt;br /&gt;GROUP BY Query_Step1.Location;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;PL_Report&lt;/b&gt; Query in normal view and the result will be same as the second image given above.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;b&gt;Three Step Solution&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;If you need more clarity in how the results are being formed for the final report then try this method.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;You can use the first Query under the two steps solution as the first step here.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Use the following SQL String, that uses the first step Query&amp;#39;s output as source data, and create the second step Query with the name &lt;b&gt;Query_Step2&lt;/b&gt;:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT Query_Step1.Location, Query_Step1.Type, Sum(Query_Step1.Amt) AS Amt&lt;br /&gt;FROM Query_Step1&lt;br /&gt;GROUP BY Query_Step1.Location, Query_Step1.Type&lt;br /&gt;ORDER BY Query_Step1.Location, Sum(Query_Step1.Amt) DESC;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output of the second Query is given below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable4-776635.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 229px; height: 127px;" src="http://www.msaccesstips.com/uploaded_images/DPTable4-776627.jpg" border="0" alt="Query Result Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;li&gt;Create a third Query for the final result, with the SQL String given below, using the second step Query (&lt;b&gt;Query_Step2&lt;/b&gt;) as Input:&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT Query_Step2.Location, "Profit/Loss" AS Description, Sum(Query_Step2.Amt) AS Amt&lt;br /&gt;FROM Query_Step2&lt;br /&gt;GROUP BY Query_Step2.Location;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output of the above Query is given below with a three Column result replacing &lt;b&gt;Type&lt;/b&gt; Column with &lt;b&gt;Description&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable5-796592.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 275px; height: 87px;" src="http://www.msaccesstips.com/uploaded_images/DPTable5-796586.jpg" border="0" alt="Report Image with Profit/Loss Description and Value" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;How about doing it differently and arrive at the following Result with Queries in two Steps?&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable6-703122.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 86px;" src="http://www.msaccesstips.com/uploaded_images/DPTable6-703115.jpg" border="0" alt="Report image with Revenue, Expenses and Profit Columns" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create the first Query &lt;b&gt;Method2_1&lt;/b&gt; with the following SQL String:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;TRANSFORM Sum(Transactions.Amount) AS SumOfAmount&lt;br /&gt;SELECT Transactions.Location&lt;br /&gt;FROM Transactions&lt;br /&gt;GROUP BY Transactions.Location&lt;br /&gt;PIVOT IIf([Type]="R","Revenue","Expenses");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Create the Report Query &lt;b&gt;Method2_2&lt;/b&gt; with the following SQL String that uses &lt;b&gt;Method2_1&lt;/b&gt; as Source:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;SELECT Method2_1.Location, Method2_1.Revenue, Method2_1.Expenses, [Revenue]-[Expenses] AS [Profit/Loss]&lt;br /&gt;FROM Method2_1;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Method2_2&lt;/b&gt; Query in Normal View and check the output.&lt;br /&gt;As you have seen in the above examples you can approach a problem in MS-Access differently and arrive at the same result. If you have to create several steps to get the final Report output, then it is a good idea to create a Flow Chart of the Process Steps.  Later on if you find something is not right with the Report you can always follow this path and back-track to find the Error.&lt;/li&gt;  &lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;A sample Flow Chart of the &lt;b&gt;Three Step Solution&lt;/b&gt; is given below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPFlow-751493.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 227px;" src="http://www.msaccesstips.com/uploaded_images/DPFlow-751490.jpg" border="0" alt="Data Process Flow Chart" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;If the &lt;b&gt;Transactions&lt;/b&gt; Table has &lt;b&gt;Year&lt;/b&gt; and &lt;b&gt;Month&lt;/b&gt; Fields too and both locations have &lt;b&gt;January&lt;/b&gt; and &lt;b&gt;February 2009&lt;/b&gt; data in them then how you will create the Report Month-wise?&lt;br /&gt;&lt;br /&gt;Try it out on your own and check it out with my examples next week. Sample image of the output is given below for reference.&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/DPTable7-787934.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 51px;" src="http://www.msaccesstips.com/uploaded_images/DPTable7-787926.jpg" border="0" alt="Transaction with Year and Month" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/11/ms-access-and-data-processing.shtml&amp;amp;title=MS-Access+and+Data+Processing"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/08/microsoft-excel-power-in-ms-access.shtml"&gt;Microsoft Excel Power in Access&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log.shtml"&gt;Un-secured Database and Users-Log&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals.shtml"&gt;MS-Access Report and Page Total&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Detail and Summary from Same Report&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3.shtml"&gt;Hiding Report Lines Conditionally-3&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-9219891714526163685?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/11/ms-access-and-data-processing.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>7</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-8572726140401850192</guid><pubDate>Sun, 08 Nov 2009 16:24:00 +0000</pubDate><atom:updated>2009-11-08T21:21:11.329+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Form Bookmarks And Data Editing-3</title><description>&lt;br /&gt;&lt;br /&gt;This is the continuation of our discussion on the usage of &lt;a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars.shtml"&gt;Form&lt;/a&gt; Bookmarks to revisit the records which we have already visited earlier. The links to the earlier Articles are given below:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml"&gt;Form Bookmarks And Data Editing&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml"&gt;Form Bookmarks And Data Editing-2&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;The discussion on Bookmarks is not complete without touching the subject of Searching and Finding records and showing it as Current Record on Form using &lt;b&gt;RecordsetClone&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In our earlier examples we have used the &lt;b&gt;Find&lt;/b&gt; Control (&lt;b&gt;Ctrl+F&lt;/b&gt; or &lt;b&gt;Edit - -&gt;Find…&lt;/b&gt;) to search for a record and when found save its Bookmark in an Array Variable in Memory for later use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This time we will use a different method to find the record and bring it on the Form with the use of Bookmark of the &lt;b&gt;RecordsetClone&lt;/b&gt; of the Form. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For this method we will use an Unbound Text Box to enter the search key value and a &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; to click and find the record.  To keep the VBA Code simple this time we will use the &lt;b&gt;Customers&lt;/b&gt; Table rather than &lt;b&gt;Order Details&lt;/b&gt; table, because &lt;b&gt;Order Details&lt;/b&gt; Table have several records with the same OrderIDs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we use &lt;b&gt;Order Details&lt;/b&gt; table then we have to combine the &lt;b&gt;ProductID&lt;/b&gt; with &lt;b&gt;OrderID&lt;/b&gt; to form a unique value to retrieve a specific record among several records with the same OrderIDs.  This method we have already used in the &lt;a href="http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml"&gt;earlier example&lt;/a&gt; to select and display all the records we have retrieved and edited.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As I have pointed out in the earlier Articles, when we open a Form with a &lt;b&gt;Table, Query or SQL Statement&lt;/b&gt; each record on the Form is marked by MS-Access with a unique identification tag known as Bookmark.  We can create a copy of this &lt;b&gt;Recordset&lt;/b&gt; into memory (&lt;b&gt;RecordsetClone&lt;/b&gt;) and work with it independently. Using the RecordsetClone, with the Form Bookmark attached to each record, we can find the required record with VBA Code using the search Key Value.  Once we find the target record in memory we can read that record&amp;#39;s Bookmark and insert it into the Form&amp;#39;s Bookmark &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Property&lt;/a&gt; to make that record current on the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But remember, you cannot read the Form&amp;#39;s Bookmark Property Value and insert it into the &lt;b&gt;RecordsetClone&lt;/b&gt; to find the same record in memory.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;On the User&amp;#39;s point of View all she has to do is to enter the Search Key Value (CustomerID) into the Unbound &lt;a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins.shtml"&gt;Text Box&lt;/a&gt; and click the &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; next to it to find that record and bring it up on the &lt;a href="http://www.msaccesstips.com/2008/11/event-trapping-summary-on-datasheet.shtml"&gt;Form&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Look at the sample VBA Code given below that runs on the &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; Click (with the Name &lt;b&gt;cmdFind&lt;/b&gt;) after setting the &lt;b&gt;Search Key&lt;/b&gt; Value (&lt;b&gt;CustomerID&lt;/b&gt;) in an Unbound Text Box with the name &lt;b&gt;xFind&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Private Sub cmdFind_Click()&lt;br /&gt;Dim m_Find, rst As Recordset&lt;br /&gt;&lt;br /&gt;m_Find = Me![xFind]&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Set rst = Me.RecordsetClone&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;rst.FindFirst &amp;quot;CustomerID = '&amp;quot; &amp;amp; [m_Find] &amp;amp; &amp;quot;'&amp;quot;&lt;br /&gt;&lt;br /&gt;If Not rst.NoMatch Then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Me.Bookmark = rst.Bookmark&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The line that reads &lt;font class="colrgreen"&gt;Set rst = Me.RecordsetClone&lt;/font&gt; copies the Form&amp;#39;s Recordset into the Recordset Object Variable &lt;b&gt;rst&lt;/b&gt; in Memory and the next line runs the &lt;b&gt;FindFirst&lt;/b&gt; method of the Recordset Object to search and find the record with the given &lt;b&gt;CustomerID&lt;/b&gt; Value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the next three lines we are testing whether the &lt;b&gt;rst.FindFirst&lt;/b&gt; method was successful in finding the record or not.  If found then the &lt;b&gt;Bookmark&lt;/b&gt; of the current record in the Recordset is transferred to the &lt;b&gt;Bookmark Property&lt;/b&gt; of the &lt;a href="http://www.msaccesstips.com/2009/01/drill-down-inquiry-screen.shtml"&gt;Form&lt;/a&gt; to make that record Current on the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have already published an Article on this method few months back with the Title: &lt;a href="http://www.msaccesstips.com/2009/04/animating-label-on-search-success.shtml"&gt;Animating Label on Search Success&lt;/a&gt;. You may visit that Page to copy the complete VBA Code of the Sub-Routine given above and try them out.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You must import the &lt;b&gt;Customers Table&lt;/b&gt; and &lt;b&gt;Customers Form&lt;/b&gt; from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office\Office11\Northwind.mdb&lt;/font&gt; sample Database and modify the Form to add a &lt;b&gt;Text Box&lt;/b&gt; and a &lt;b&gt;Command Button&lt;/b&gt; at the Footer of the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When the &lt;b&gt;rst.FindFirst&lt;/b&gt; method finds the record and makes it current; a Label at the bottom of the Unbound Text Box will flash few times with a message indicating that the search operation was &lt;b&gt;successful&lt;/b&gt; and that record is made &lt;b&gt;Current&lt;/b&gt; on the Form.  If the search operation failed then the Label will flash few times with the message: &lt;b&gt;Sorry, not found. &lt;/b&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This method added to the above program gives the User a quick indication whether the search was successful or not.  To go to the Page to try out the Program Click &lt;a href="http://www.msaccesstips.com/2009/04/animating-label-on-search-success.shtml"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-3.shtml&amp;amp;title=Form+Bookmarks+and+Data+Editing-3"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/unsecured-database-and-users-log.shtml"&gt;Un-secured Database and Users-Log&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals.shtml"&gt;MS-Access Report and Page Total&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Detail and Summary from Same Report&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3.shtml"&gt;Hiding Report Lines Conditionally-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-2.shtml"&gt;Hiding Report Lines Conditionally-2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-8572726140401850192?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-3.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-5812263276504255742</guid><pubDate>Sun, 01 Nov 2009 17:23:00 +0000</pubDate><atom:updated>2009-11-03T21:53:08.054+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Form Bookmarks And Data Editing-2</title><description>&lt;br /&gt;&lt;br /&gt;In the &lt;a href="http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml"&gt;first part of this Article&lt;/a&gt;, we were using the saved Bookmarks to revisit the earlier visited records one by one to take a second look, if it became necessary, to ascertain the accuracy of edited information. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Function &lt;b&gt;myBookMarks()&lt;/b&gt; that we have created for this purpose can be added with one more Option, (along with &lt;b&gt;1=Save Bookmark, 2=retrieve Bookmarks, 3=initialize Bookmark List&lt;/b&gt;) to display all the edited records together in &lt;a href="http://www.msaccesstips.com/2008/11/event-trapping-summary-on-datasheet.shtml"&gt;Datasheet View&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, this method has some side effects and must be aware of it to implement some work around methods in such situations. Here, we will try that with the &lt;b&gt;Order Details&lt;/b&gt; Table. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the last example we were using the Bookmark Index Number and OrderID number values as a guide to cross check with the retrieved record. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Several Products can be ordered under the same &lt;b&gt;Purchase Order&lt;/b&gt; and all Products under the same Order will bear the same OrderIDs too.  If OrderIDs are alone used in a Query Criteria to retrieve the records then all records with the same Order IDs will be displayed, irrespective of which record among them we have visited earlier. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There were no such issues when we were using &lt;b&gt;Bookmarks&lt;/b&gt; of each record to find them again and OrderIDs were used only as a guide to cross check the retrieved record’s identity. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; But here, we are trying to use the OrderId Values saved in the Combo Box List as Criteria in a Query to retrieve all the &lt;b&gt;edited records&lt;/b&gt; at one go. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This problem we can overcome if some other unique value, if available, is used in the &lt;a href="http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml"&gt;Combo Box&lt;/a&gt; list.  Or use one or more field values combined to form a unique value for each record and save it in the Combo Box List along with the Bookmark Index Number.  This is what we are going to do now with the &lt;b&gt;4th Option&lt;/b&gt; of &lt;b&gt;myBookMarks()&lt;/b&gt; Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will use &lt;b&gt;OrderID&lt;/b&gt; with &lt;b&gt;ProductID&lt;/b&gt; combined Values and save them in the Combo Box List. The same Product Code will not appear twice under the same Purchase Order. This will ensure that the values saved in the Combo Box are unique. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The idea behind this new method is to create a Dynamic Query using the Values saved in the &lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;Combo Box&lt;/a&gt; list and open the Query with all the edited records from the &lt;b&gt;Order Detail&lt;/b&gt; Table with one click. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the fourth Option of the Function &lt;b&gt;myBookMarks()&lt;/b&gt; we will build an SQL String using the Values saved in the Combo box as Criteria and modify the SQL string of a &lt;b&gt;SELECT&lt;/b&gt; Query to retrieve the records.  We have to create another &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; near the &lt;b&gt;&amp;lt;&amp;lt; Reset&lt;/b&gt; Button to run this Option, so that the User can click on it to retrieve all the edited records and display them in Datasheet View at his will. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, first let us write the Code Segment that implements this particular Option.  We need few Objects and Variable declarations at the declaration section of the Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Dim db as Database, QryDef as Querydef&lt;br /&gt;Dim strSql as String, strSqltmp as String, strCriteria as String&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;Select Case ActionCode&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt; Case 1&lt;br /&gt; .&lt;br /&gt; Case 2&lt;br /&gt; .&lt;br /&gt; Case 3&lt;br /&gt; .&lt;br /&gt;     Case 4&lt;br /&gt;        strSqltmp = &amp;quot;SELECT [Order Details].* &amp;quot;&lt;br /&gt;        strSqltmp = strSqltmp &amp;amp; &amp;quot;FROM [Order Details] &amp;quot;&lt;br /&gt;        strSqltmp = strSqltmp &amp;amp; &amp;quot;WHERE ((([OrderID]&amp;quot; &amp;amp; &amp;quot;&amp;amp;&amp;quot; &amp;amp; Chr$(34)&lt;br /&gt;        strSqltmp = strSqltmp &amp;amp; &amp;quot;-&amp;quot; &amp;amp; Chr$(34) &amp;amp; &amp;quot;&amp;amp;&amp;quot; &amp;amp; &amp;quot;[ProductID]) In ('&amp;quot;&lt;br /&gt;        &lt;br /&gt;        strCriteria = &amp;quot;&amp;quot;&lt;br /&gt;        For j = 0 To ArrayIndex - 1&lt;br /&gt;            If Len(strCriteria) = 0 Then&lt;br /&gt;                strCriteria = ctrlCombo.Column(1, j)&lt;br /&gt;            Else&lt;br /&gt;                strCriteria = strCriteria &amp;amp; &amp;quot;','&amp;quot; &amp;amp; ctrlCombo.Column(1, j)&lt;br /&gt;            End If&lt;br /&gt;        Next&lt;br /&gt;        strCriteria = strCriteria &amp;amp; &amp;quot;')));&amp;quot;&lt;br /&gt;        &lt;br /&gt;        Set db = CurrentDb&lt;br /&gt;        Set Qrydef = db.QueryDefs(&amp;quot;OrderDetails_Bookmarks&amp;quot;)&lt;br /&gt;        strSql = strSqltmp &amp;amp; strCriteria&lt;br /&gt;        Qrydef.SQL = strSql&lt;br /&gt;        db.QueryDefs.Refresh&lt;br /&gt;        DoCmd.OpenQuery &amp;quot;OrderDetails_Bookmarks&amp;quot;, acViewNormal&lt;br /&gt;End Select  &lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;We are creating part of the SQL string that remains constant in the &lt;b&gt;strSqltmp&lt;/b&gt;.  Extracting the Combo Box &lt;b&gt;2nd Column&lt;/b&gt; Values (combined values of OrderID and ProductID separated with a hyphen character) and building the Criteria part of the Query in the String Variable &lt;b&gt;strCriteria&lt;/b&gt; within the &lt;b&gt;For…Next&lt;/b&gt; Loop. Finally we are redefining the SQL of the &lt;b&gt;OrderDetails_BookMarks&lt;/b&gt; Query before opening it with the extracted Records. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Combo Box Columns have Zero based Index Numbers and the second Column Index number is &lt;b&gt;1&lt;/b&gt;. So the statement &lt;font class="colrgreen"&gt;strCriteria = strCriteria &amp; "','" &amp; ctrlCombo.Column(1, j)&lt;/font&gt; takes the second column value OrderID and PrductID combined String value for criteria. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The modified Code of the &lt;b&gt;myBookMarks()&lt;/b&gt; Function with the above Option is given below. &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt; You may Copy the Code and Paste it in the Standard Module replacing the earlier Code or rename the earlier Function and save this Code separately.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Const ArrayRange As Integer = 25&lt;br /&gt;Dim bookmarklist(1 To ArrayRange) As String, ArrayIndex As Integer&lt;br /&gt;&lt;br /&gt;Public Function myBookMarks(ByVal ActionCode As Integer, ByVal cboBoxName As String, Optional ByVal RecordKeyValue) As String&lt;br /&gt;'-----------------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : October-2009&lt;br /&gt;'URL    : www.msaccesstips.com&lt;br /&gt;'Remarks: All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'-----------------------------------------------------------------&lt;br /&gt;'Action Code : 1 - Save Bookmark in Memory&lt;br /&gt;'            : 2 - Retrieve Bookmark and make the record current&lt;br /&gt;'            : 3 - Initialize Bookmark List and ComboBox contents&lt;br /&gt;‘            : 4 – Filter Records and display in Datasheet View&lt;br /&gt;'-----------------------------------------------------------------&lt;br /&gt;Dim ctrlCombo As ComboBox, actvForm As Form, bkmk As String&lt;br /&gt;Dim j As Integer, msg As String, bkmkchk As Variant&lt;br /&gt;Dim strRowSource As String, strRStmp As String, matchflag As Integer&lt;br /&gt;Dim msgButton As Integer&lt;br /&gt;&lt;br /&gt;Dim db As Database, Qrydef As QueryDef&lt;br /&gt;Dim strSql As String, strSqltmp As String, strCriteria As String&lt;br /&gt;&lt;br /&gt;'On Error GoTo myBookMarks_Err&lt;br /&gt;&lt;br /&gt;If ActionCode &amp;lt; 1 Or ActionCode &amp;gt; 4 Then&lt;br /&gt;   msg = &amp;quot;Invalid Action Code : &amp;quot; &amp;amp; ActionCode &amp;amp; vbCr &amp;amp; vbCr&lt;br /&gt;   msg = msg &amp;amp; &amp;quot;Valid Values : 1 to 4&amp;quot;&lt;br /&gt;   MsgBox msg, , &amp;quot;myBookMarks&amp;quot;&lt;br /&gt;   Exit Function&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Set actvForm = Screen.ActiveForm&lt;br /&gt;Set ctrlCombo = actvForm.Controls(cboBoxName)&lt;br /&gt;Select Case ActionCode&lt;br /&gt;    Case 1&lt;br /&gt;        bkmk = actvForm.Bookmark&lt;br /&gt;        'check for existence of same bookmark in Array&lt;br /&gt;        matchflag = -1&lt;br /&gt;        For j = 1 To ArrayIndex&lt;br /&gt;           matchflag = StrComp(bkmk, bookmarklist(j), vbBinaryCompare)&lt;br /&gt;           If matchflag = 0 Then&lt;br /&gt;               Exit For&lt;br /&gt;           End If&lt;br /&gt;        Next&lt;br /&gt;        If matchflag = 0 Then&lt;br /&gt;           msg = &amp;quot;Bookmark of &amp;quot; &amp;amp; RecordKeyValue &amp;amp; vbCr &amp;amp; vbCr&lt;br /&gt;           msg = msg &amp;amp; &amp;quot;Already Exists.&amp;quot;&lt;br /&gt;           MsgBox msg, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;           Exit Function&lt;br /&gt;        End If&lt;br /&gt;        'Save Bookmark in Array&lt;br /&gt;        ArrayIndex = ArrayIndex + 1&lt;br /&gt;        If ArrayIndex &amp;gt; ArrayRange Then&lt;br /&gt;          ArrayIndex = ArrayRange&lt;br /&gt;          MsgBox &amp;quot;Boookmark List Full.&amp;quot;, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;          Exit Function&lt;br /&gt;        End If&lt;br /&gt;        bookmarklist(ArrayIndex) = bkmk&lt;br /&gt;        &lt;br /&gt;        GoSub FormatCombo&lt;br /&gt;        &lt;br /&gt;        ctrlCombo.RowSource = strRowSource&lt;br /&gt;        ctrlCombo.Requery&lt;br /&gt;    Case 2&lt;br /&gt;        'Retrieve saved Bookmark and make the record current&lt;br /&gt;        j = ctrlCombo.Value&lt;br /&gt;        actvForm.Bookmark = bookmarklist(j)&lt;br /&gt;    Case 3&lt;br /&gt;        'Erase all Bookmarks from Array and&lt;br /&gt;        'Delete the Combobox contents&lt;br /&gt;        msg = &amp;quot;Erase Current Bookmark List...?&amp;quot;&lt;br /&gt;        msgButton = vbYesNo + vbDefaultButton2 + vbQuestion&lt;br /&gt;        If MsgBox(msg, msgButton, &amp;quot;myBookMarks()&amp;quot;) = vbNo Then&lt;br /&gt;            Exit Function&lt;br /&gt;        End If&lt;br /&gt;        For j = 1 To ArrayRange&lt;br /&gt;           bookmarklist(j) = &amp;quot;&amp;quot;&lt;br /&gt;        Next&lt;br /&gt;        ctrlCombo.Value = Null&lt;br /&gt;        ctrlCombo.RowSource = &amp;quot;&amp;quot;&lt;br /&gt;        ArrayIndex = 0&lt;br /&gt;    Case 4&lt;br /&gt;        strSqltmp = &amp;quot;SELECT [Order Details].* &amp;quot;&lt;br /&gt;        strSqltmp = strSqltmp &amp;amp; &amp;quot;FROM [Order Details] &amp;quot;&lt;br /&gt;        strSqltmp = strSqltmp &amp;amp; &amp;quot;WHERE ((([OrderID]&amp;quot; &amp;amp; &amp;quot;&amp;amp;&amp;quot; &amp;amp; Chr$(34)&lt;br /&gt;        strSqltmp = strSqltmp &amp;amp; &amp;quot;-&amp;quot; &amp;amp; Chr$(34) &amp;amp; &amp;quot;&amp;amp;&amp;quot; &amp;amp; &amp;quot;[ProductID]) In ('&amp;quot;&lt;br /&gt;        &lt;br /&gt;        strCriteria = &amp;quot;&amp;quot;&lt;br /&gt;        For j = 0 To ArrayIndex - 1&lt;br /&gt;            If Len(strCriteria) = 0 Then&lt;br /&gt;                strCriteria = ctrlCombo.Column(1, j)&lt;br /&gt;            Else&lt;br /&gt;                strCriteria = strCriteria &amp;amp; &amp;quot;','&amp;quot; &amp;amp; ctrlCombo.Column(1, j)&lt;br /&gt;            End If&lt;br /&gt;        Next&lt;br /&gt;        strCriteria = strCriteria &amp;amp; &amp;quot;')));&amp;quot;&lt;br /&gt;        &lt;br /&gt;        Set db = CurrentDb&lt;br /&gt;        Set Qrydef = db.QueryDefs(&amp;quot;OrderDetails_Bookmarks&amp;quot;)&lt;br /&gt;        strSql = strSqltmp &amp; strCriteria&lt;br /&gt;        Qrydef.SQL = strSql&lt;br /&gt;        db.QueryDefs.Refresh&lt;br /&gt;        DoCmd.OpenQuery &amp;quot;OrderDetails_Bookmarks&amp;quot;, acViewNormal&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;myBookMarks_Exit:&lt;br /&gt;Exit Function&lt;br /&gt;&lt;br /&gt;FormatCombo:&lt;br /&gt;'format current Bookmark serial number&lt;br /&gt;'and OrderID to display in Combo Box&lt;br /&gt;strRStmp = Chr$(34) &amp;amp; Format(ArrayIndex, &amp;quot;00&amp;quot;) &amp;amp; Chr$(34) &amp;amp; &amp;quot;;&amp;quot;&lt;br /&gt;strRStmp = strRStmp &amp;amp; Chr$(34) &amp;amp; RecordKeyValue &amp;amp; Chr$(34)&lt;br /&gt;&lt;br /&gt;'get current combobox contents&lt;br /&gt;strRowSource = ctrlCombo.RowSource&lt;br /&gt;&lt;br /&gt;'Add the current Bookmark serial number&lt;br /&gt;'and OrderID to the List in Combo Box&lt;br /&gt;If Len(strRowSource) = 0 Then&lt;br /&gt;     strRowSource = strRStmp&lt;br /&gt;Else&lt;br /&gt;     strRowSource = strRowSource &amp;amp; &amp;quot;;&amp;quot; &amp;amp; strRStmp&lt;br /&gt;End If&lt;br /&gt;Return&lt;br /&gt;&lt;br /&gt;myBookMarks_Err:&lt;br /&gt;MsgBox Err.Description, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;Resume myBookMarks_Exit&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can try out this Option with few changes to the Form that we have created earlier (the &lt;a href="http://www.msaccesstips.com/2008/01/progress-counter.shtml"&gt;Form&lt;/a&gt; in design view is given below) by creating another &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; and with a simple SELECT Query. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;First, Create a SELECT Query with the following SQL String and save it with the name &lt;b&gt;OrderDetails_Bookmarks&lt;/b&gt;:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;SELECT [Order Details].* FROM [Order Details];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the Form Order Details and create a &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; next to the &lt;b&gt;&amp;lt;&amp;lt;Reset&lt;/b&gt; Command Button as shown on the &lt;a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form.shtml"&gt;Form&lt;/a&gt; Design image given below:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/bookmarkQ00-724165.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 157px;" src="http://www.msaccesstips.com/uploaded_images/bookmarkQ00-724162.jpg" border="0" alt="Form in Design View with new Command Button" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;li&gt;Click on the Command Button to select it and display the Property Sheet (&lt;b&gt;View- - &gt; Properties&lt;/b&gt;)&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Name&lt;/b&gt; Property Value to &lt;b&gt;cmdShow&lt;/b&gt; and the &lt;b&gt;Caption&lt;/b&gt; Property Value to &lt;b&gt;View Records&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the &lt;b&gt;On Click&lt;/b&gt; Property, select &lt;b&gt;EventProcedure&lt;/b&gt; from the drop down list and click on the Build (&lt;b&gt;…&lt;/b&gt;) Button to open the Form&amp;#39;s Code Module with the following empty skeleton of Sub-Routine:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Private Sub cmdShow_Click()&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt; &lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Write the following line in the middle of the Sub-Routine as shown below:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;Private Sub cmdShow_Click()&lt;br /&gt;    myBookMarks 4, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save and Close the &lt;b&gt;Order Details&lt;/b&gt; Form and open it in Normal View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Double-Click on the Record Selector of few records on the Form to add the Bookmark List in the Combo Box.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the drop down control of the Combo Box to ensure that the selected Item Codes are added into the Combo Box List.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the &lt;b&gt;View Records&lt;/b&gt; Command Button to open the Query &lt;b&gt;OrderDetails_Bookmarks&lt;/b&gt; in Datasheet View with the records that matches with the Combo Box Values.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/bookmarkQ01-756971.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 247px;" src="http://www.msaccesstips.com/uploaded_images/bookmarkQ01-756924.jpg" border="0" alt="Query Result in Datasheet View" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;Check the sample image of Query result overlapping the Form, displaying all the records that belong to the Combo Box List Values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Product Field displays Product Description rather than the Product Code that is appearing in the Bookmark Combo Box on the Main Form. The &lt;b&gt;Display Width&lt;/b&gt; of the Combo Box in the Product Field is set to &lt;b&gt;0” &lt;/b&gt; to hide the Product Code in the Data View. But when you select an item from this Combo Box the Product Code is stored in the &lt;b&gt;Order Details&lt;/b&gt; Table, because that is the Bound Column to the Table.  When you double-click on the Record Selector the stored value of ProductID is taken rather than the Product Description, to combine with OrderID Value and updates the Combo Box List. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Want to find out how to open a Form with the last record that you were working on in the earlier session?, &lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Click here&lt;/a&gt;?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Want to find out how to use Combo Boxes and List Boxes in different ways? Visit the following Links: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/05/selected-list-box-items-and-dynamic.shtml"&gt;Selected ListBox Items and Dynamic Query&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/05/create-list-from-another-listbox.shtml"&gt;Create List from another ListBox&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/05/list-box-and-date-part-one.shtml"&gt;ListBox and Date : Part-1&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/05/list-box-and-date-part-two.shtml"&gt;ListBox and Date : Part-2&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;ComboBox Column Values&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/02/external-files-list-in-hyperlinks.shtml"&gt;External Files List in Hyperlinks&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml"&gt;Refresh Dependant ComboBox Contents&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml&amp;amp;title=Form+Bookmarks+and+Data+Editing-2"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/msaccess-report-and-page-totals.shtml"&gt;MS-Access Report and Page Total&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Detail and Summary from Same Report&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3.shtml"&gt;Hiding Report Lines Conditionally-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-2.shtml"&gt;Hiding Report Lines Conditionally-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Hiding Report Lines Conditionally&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-5812263276504255742?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/11/form-bookmarks-and-data-editing-2.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-2589006932856349121</guid><pubDate>Sun, 25 Oct 2009 17:31:00 +0000</pubDate><atom:updated>2009-10-25T22:14:52.298+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Form Bookmarks and Data Editing</title><description>You want to edit information on 25 records on the &lt;a href="http://www.msaccesstips.com/2008/11/custom-calculator-and-eval-function.shtml"&gt;Form&lt;/a&gt; randomly.  You will open the main data editing Form.  Search for the record by entering the Key Value to find (say Employee Code or OrderID Value) in the &lt;b&gt;Find (Ctrl+F) &lt;/b&gt; control and edit the record when found on the Form.  This procedure is repeated for all 25 records for the first time because you don&amp;#39;t have any other choice to find and edit the information.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, the information you have changed is very critical and any mistakes in them may lead to serious issues.  Mistakes can easily creep-in when you go through the finding and editing procedure in a hurry. It is important that you should have a second look at each record to verify and ensure the accuracy of changes. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Going through the same procedure to find all those 25 records again by displaying the &lt;b&gt;Find&lt;/b&gt; control, keying in the Key Values and clicking on the Find button to reach the required record is not as enjoyable as it did for the first time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, if you can reach all those distant records one by one, in the same order of editing, without going through the above cumbersome procedure then it will be a great relief and can finish the work fast. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Why I said in the same order during editing because you are holding the source document of changes in the same order of your first visit to the records. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will develop a trick with the Form&amp;#39;s &lt;b&gt;Bookmarks&lt;/b&gt; to make this kind of work easier for our Application Users. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;b&gt;&lt;u&gt;FORM BOOKMARKS&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;When you open a &lt;a href="http://www.msaccesstips.com/2008/11/event-trapping-summary-on-datasheet.shtml"&gt;Form&lt;/a&gt; attached to a &lt;b&gt;Table&lt;/b&gt;, &lt;b&gt;Query&lt;/b&gt; or &lt;b&gt;SQL Statement&lt;/b&gt; each record on the Form is marked by MS-Access with a unique identifying tag known as &lt;b&gt;Bookmark&lt;/b&gt; (a two Byte string Value).  This is happening every time you open the Form with the above record sources.  The Bookmarks are valid only on the current session of the Form and not stored in Tables. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can read the Bookmark of any record from the Form&amp;#39;s &lt;b&gt;Bookmark Property&lt;/b&gt;, when the &lt;b&gt;Record is Current&lt;/b&gt; on the Form, and store it in Variables in memory. Bookmarks saved this way can be used again to go back quickly to the same record we have visited earlier. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have created a Function with the name &lt;b&gt;myBookMarks()&lt;/b&gt; for this purpose and you can implement this method on any Form that has a &lt;b&gt;Recordset&lt;/b&gt; attached to it by creating a &lt;a href="http://www.msaccesstips.com/2009/01/combo-box-column-values.shtml"&gt;Combo Box&lt;/a&gt; and a &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; and four lines of Code in the VBA Code Module of the &lt;a href="http://www.msaccesstips.com/2008/01/progress-bar-on-form.shtml"&gt;Form&lt;/a&gt; to run the Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You will definitely get a pat on your back from the User of your MS-Access Application for implementing this simple feature. So, let us start with our sample Project. &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;b&gt;&lt;u&gt;SAMPLE PROJECT&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Open your VBA Editing Window (&lt;b&gt;Alt+F11&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a new &lt;b&gt;Standard&lt;/b&gt; Module (&lt;b&gt;Insert - -&gt; Module&lt;/b&gt;), Copy and Paste the following Code of &lt;b&gt;myBookMarks()&lt;/b&gt; Function into the Module and Save it: &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;Option Compare Database&lt;br /&gt;Option Explicit&lt;br /&gt;&lt;br /&gt;Public Const ArrayRange As Integer = 25&lt;br /&gt;Dim bookmarklist(1 To ArrayRange) As String, ArrayIndex As Integer&lt;br /&gt;&lt;br /&gt;Public Function myBookMarks(ByVal ActionCode As Integer, ByVal cboBoxName As String, Optional ByVal RecordKeyValue) As String&lt;br /&gt;'-----------------------------------------------------------------&lt;br /&gt;'Author : a.p.r. pillai&lt;br /&gt;'Date   : October-2009&lt;br /&gt;'URL    : www.msaccesstips.com&lt;br /&gt;'Remarks: All Rights Reserved by www.msaccesstips.com&lt;br /&gt;'-----------------------------------------------------------------&lt;br /&gt;'Action Code : 1 - Save Bookmark in Memory&lt;br /&gt;'            : 2 - Retrieve Bookmark and make the record current&lt;br /&gt;'            : 3 - Initialize Bookmark List and ComboBox contents&lt;br /&gt;'-----------------------------------------------------------------&lt;br /&gt;Dim ctrlCombo As ComboBox, actvForm As Form, bkmk As String&lt;br /&gt;Dim j As Integer, msg As String, bkmkchk As Variant&lt;br /&gt;Dim strRowSource As String, strRStmp As String, matchflag As Integer&lt;br /&gt;Dim msgButton As Integer&lt;br /&gt;&lt;br /&gt;On Error GoTo myBookMarks_Err&lt;br /&gt;&lt;br /&gt;If ActionCode &amp;lt; 1 Or ActionCode &amp;gt; 3 Then&lt;br /&gt;   msg = &amp;quot;Invalid Action Code : &amp;quot; &amp;amp; ActionCode &amp;amp; vbCr &amp;amp; vbCr&lt;br /&gt;   msg = msg &amp;amp; &amp;quot;Valid Values : 1,2 or 3&amp;quot;&lt;br /&gt;   MsgBox msg, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;   Exit Function&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;Set actvForm = Screen.ActiveForm&lt;br /&gt;Set ctrlCombo = actvForm.Controls(cboBoxName)&lt;br /&gt;Select Case ActionCode&lt;br /&gt;    Case 1&lt;br /&gt;        bkmk = actvForm.Bookmark&lt;br /&gt;        'check for existence of same bookmark in Array&lt;br /&gt;        matchflag = -1&lt;br /&gt;        For j = 1 To ArrayIndex&lt;br /&gt;           matchflag = StrComp(bkmk, bookmarklist(j), vbBinaryCompare)&lt;br /&gt;           If matchflag = 0 Then&lt;br /&gt;               Exit For&lt;br /&gt;           End If&lt;br /&gt;        Next&lt;br /&gt;        If matchflag = 0 Then&lt;br /&gt;           msg = &amp;quot;Bookmark of &amp;quot; &amp;amp; RecordKeyValue &amp;amp; vbCr &amp;amp; vbCr&lt;br /&gt;           msg = msg &amp;amp; &amp;quot;Already Exists. &amp;quot;&lt;br /&gt;           MsgBox msg, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;           Exit Function&lt;br /&gt;        End If&lt;br /&gt;        'Save Bookmark in Array&lt;br /&gt;        ArrayIndex = ArrayIndex + 1&lt;br /&gt;        If ArrayIndex &amp;gt; ArrayRange Then&lt;br /&gt;          ArrayIndex = ArrayRange&lt;br /&gt;          MsgBox &amp;quot;Boookmark List Full. &amp;quot;, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;          Exit Function&lt;br /&gt;        End If&lt;br /&gt;        bookmarklist(ArrayIndex) = bkmk&lt;br /&gt;        &lt;br /&gt;        GoSub FormatCombo&lt;br /&gt;        &lt;br /&gt;        ctrlCombo.RowSource = strRowSource&lt;br /&gt;        ctrlCombo.Requery&lt;br /&gt;    Case 2&lt;br /&gt;        'Retrieve saved Bookmark and make the record current&lt;br /&gt;        j = ctrlCombo.Value&lt;br /&gt;        actvForm.Bookmark = bookmarklist(j)&lt;br /&gt;    Case 3&lt;br /&gt;        'Erase all Bookmarks from Array and&lt;br /&gt;        'Delete the Combobox contents&lt;br /&gt;        msg = &amp;quot;Erase Current Bookmark List...? &amp;quot;&lt;br /&gt;        msgButton = vbYesNo + vbDefaultButton2 + vbQuestion&lt;br /&gt;        If MsgBox(msg, msgButton, &amp;quot;myBookMarks()&amp;quot;) = vbNo Then&lt;br /&gt;            Exit Function&lt;br /&gt;        End If&lt;br /&gt;        For j = 1 To ArrayRange&lt;br /&gt;           bookmarklist(j) = &amp;quot;&amp;quot;&lt;br /&gt;        Next&lt;br /&gt;        ctrlCombo.Value = Null&lt;br /&gt;        ctrlCombo.RowSource = &amp;quot;&amp;quot;&lt;br /&gt;        ArrayIndex = 0&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;myBookMarks_Exit:&lt;br /&gt;Exit Function&lt;br /&gt;&lt;br /&gt;FormatCombo:&lt;br /&gt;'format current Bookmark serial number&lt;br /&gt;'and OrderID to display in Combo Box&lt;br /&gt;strRStmp = Chr$(34) &amp;amp; Format(ArrayIndex, &amp;quot;00&amp;quot;) &amp;amp; Chr$(34) &amp;amp; &amp;quot;;&amp;quot;&lt;br /&gt;strRStmp = strRStmp &amp;amp; Chr$(34) &amp;amp; RecordKeyValue &amp;amp; Chr$(34)&lt;br /&gt;&lt;br /&gt;'get current combobox contents&lt;br /&gt;strRowSource = ctrlCombo.RowSource&lt;br /&gt;&lt;br /&gt;'Add the current Bookmark serial number&lt;br /&gt;'and OrderID to the List in Combo Box&lt;br /&gt;If Len(strRowSource) = 0 Then&lt;br /&gt;     strRowSource = strRStmp&lt;br /&gt;Else&lt;br /&gt;     strRowSource = strRowSource &amp;amp; &amp;quot;;&amp;quot; &amp;amp; strRStmp&lt;br /&gt;End If&lt;br /&gt;Return&lt;br /&gt;&lt;br /&gt;myBookMarks_Err:&lt;br /&gt;MsgBox Err.Description, , &amp;quot;myBookMarks()&amp;quot;&lt;br /&gt;Resume myBookMarks_Exit&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Import the following Tables from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; sample Database: &lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Order Details&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Products&lt;/li&gt;&lt;br /&gt;   &lt;/ul&gt;&lt;br /&gt;&lt;b&gt;NB: &lt;/b&gt; We are not using the second table directly, but the &lt;b&gt;Order Details&lt;/b&gt; table references the Products Table for Product Description.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click on the &lt;b&gt;Order Details&lt;/b&gt; Table to select it. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Form&lt;/b&gt; from &lt;b&gt;Insert&lt;/b&gt; Menu and select &lt;b&gt;AutoForm : Tabular&lt;/b&gt; from the displayed list. &lt;/li&gt; &lt;br /&gt;&lt;br /&gt;&lt;li&gt;MS-Access creates a Tabular Form quickly.  Save the Form with the name &lt;b&gt;Order Details&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;A sample image of a Tabular Form in Design View is given below. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/bookmark0-757437.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 103px;" src="http://www.msaccesstips.com/uploaded_images/bookmark0-757435.jpg" border="0" alt="Sample Tabular Form in Design View" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open &lt;b&gt;Order Details&lt;/b&gt; Form in Design View. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Expand the &lt;b&gt;Form Header&lt;/b&gt; area and move the Field Headings down for enough space to create a Combo Box and a &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; as shown on the sample design above. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the &lt;b&gt;ToolBox (View - -&gt;ToolBox)&lt;/b&gt;, if it is not already visible. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;If the &lt;b&gt;Control &lt;a href="http://www.msaccesstips.com/2008/12/custom-made-form-wizard.shtml"&gt;Wizards&lt;/a&gt;&lt;/b&gt; Tool Button is already in selected state then click on it to de-select it. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the &lt;b&gt;Combo Box&lt;/b&gt; Tool from the &lt;b&gt;ToolBox&lt;/b&gt; and draw a Combo Box in the &lt;b&gt;Header Section&lt;/b&gt; of the &lt;a href="http://www.msaccesstips.com/2008/10/wave-shaped-reminder-ticker.shtml"&gt;Form&lt;/a&gt; as shown on the design above. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;While the Combo Box is still in selected state; select &lt;b&gt;Properties&lt;/b&gt; from &lt;b&gt;View&lt;/b&gt; menu to display the Property Sheet of the &lt;b&gt;Combo Box&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the following Property Values as shown below: &lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Name = cboBMList&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Row Source Type  =  Value List&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Column Count  = 2&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Column Widths = .5&amp;quot;;1&amp;quot; &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Bound Column = 1&lt;/li&gt;&lt;br /&gt;&lt;li&gt;List Rows  =  8&lt;/li&gt;&lt;br /&gt;&lt;li&gt;List Width = 1.5&amp;quot; &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Caption&lt;/b&gt; of the Child Label, attached to the Combo Box, to &lt;b&gt;Bookmark List: &lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a &lt;b&gt;Command Button&lt;/b&gt; to the right side of the Combo Box. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the &lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Property&lt;/a&gt; Sheet of the Command Button. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the following Property Values as shown Below: &lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Name  =  cmdReset&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Caption = &amp;lt;&amp;lt; Reset&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;li&gt;Display the Code Module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following VBA Code into the Module; &lt;b&gt;Save&lt;/b&gt; and &lt;b&gt;Close&lt;/b&gt; the Form: &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;Option Compare Database&lt;br /&gt;&lt;br /&gt;Private Sub Form_DblClick(Cancel As Integer)&lt;br /&gt;    'Save Current Record's Bookmark in memory&lt;br /&gt;    myBookMarks 1, &amp;quot;cboBMList&amp;quot;, Me![OrderID]&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub cboBMList_Click()&lt;br /&gt;    'Retrieve the bookmark using the&lt;br /&gt;    'index number from the Combobox List&lt;br /&gt;    'and make the respective record current&lt;br /&gt;    myBookMarks 2, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub cmdReset_Click()&lt;br /&gt;    'Initialize Bookmarks and Combobox contents&lt;br /&gt;    myBookMarks 3, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Form_Unload(Cancel As Integer)&lt;br /&gt;    'Remove all Bookmarks from Memory&lt;br /&gt;    myBookMarks 3, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;Order Details&lt;/b&gt; Form in Normal View. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Double-Click on one of the record-selectors at the left side of the Form. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the &lt;a href="http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml"&gt;Combo Box&lt;/a&gt; Drop-down control to check whether the &lt;b&gt;OrderID&lt;/b&gt; value of the Record that you have double-clicked is added into the Combo Box List with a sequence number in the first Column or not. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Make few more double-click on different Record selectors up or down on the form as you like. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Check the Combo Box contents again to ensure that all these record references are added into the Combo Box with running serial numbers. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Now, let us check whether we can jump quickly to one of these records we have visited earlier by using the saved Bookmarks List appearing in the Combo Box. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click on the drop-down control of the Combo Box to display the list of Bookmarks and click on one of the item from the list. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/bookmark1-751479.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 167px;" src="http://www.msaccesstips.com/uploaded_images/bookmark1-751477.jpg" border="0" alt="Bookmark List in Combo Box Image" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The selected &lt;b&gt;OrderId&lt;/b&gt; record will become the Current Record on the Form.  Even if there are several records with the same OrderID it will correctly pick the record that you have visited earlier because we are using Bookmark and not the &lt;b&gt;Find&lt;/b&gt; method with the &lt;b&gt;OrderID&lt;/b&gt; Value to find the record.  If OrderID was used then it will stop at the first record with the same &lt;b&gt;OrderID&lt;/b&gt; numbers, not on the same record you have visited earlier.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You may try out other items appearing in the list for now. You may implement this method on Forms with Column Format too. &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/bookmark2-749630.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 171px;" src="http://www.msaccesstips.com/uploaded_images/bookmark2-749628.jpg" border="0" alt="Bookmark List in Column Format Form" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;Here, I would like to remind you that we are saving the List of Bookmarks in the &lt;b&gt;BookMarkList&lt;/b&gt; Array in &lt;b&gt;myBookMarks()&lt;/b&gt; Function in the Standard Module.  The Combo Box is only added with the Index Number of the Array elements already filled with Bookmarks out of a Total of 25 elements dimensioned for use. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Check the following declarations of the Function in the Global area of the Module: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Public Const ArrayRange As Integer = 25&lt;br /&gt;Dim bookmarklist(1 To ArrayRange) As String, ArrayIndex As Integer&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;You can change the Value 25 to a higher or lower desired value according to your specific needs. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us continue by adding few more distant record bookmarks into the existing list. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Scroll down the vertical scrollbar of the Form and double-click on the Record-Selectors of few more records from distant area of the Recordset. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Now, try to reach any of these Bookmarks we have added into the list by selecting them one by one from the Combo Box List. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Isn&amp;#39;t it very easy to revisit all those records a second time?&lt;br /&gt;&lt;br /&gt;&lt;li&gt;If you want to erase all those Bookmarks from the &lt;b&gt;BookmarkList&lt;/b&gt; Array in memory click on the &lt;b&gt;&amp;lt;&amp;lt; Reset&lt;/b&gt; Command Button. After this, you can create a fresh list of Bookmarks. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;The &lt;b&gt;OrderID&lt;/b&gt; Field Value added to the Combo Box along with the &lt;b&gt;Index Number&lt;/b&gt; of the Bookmark Array can be used to cross check with the retrieved record value to ensure correctness. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us look the Sub-Routines we have copied into the Form Module and check what they are doing. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Private Sub Form_DblClick(Cancel As Integer)&lt;br /&gt;    myBookMarks 1, &amp;quot;cboBMList&amp;quot;, Me![OrderID]&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;When you double-click on the Record Selector of a record the above Sub-Routine calls the main Function &lt;b&gt;myBookmarks()&lt;/b&gt; with the following parameters: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Action Code&lt;/b&gt; : 1   -  indicates to fetch the Current Bookmark (a two byte string value consists of displayable/non-displayable characters) from the Active Form and save it in Memory in BookMarkList Array after incrementing the Array index number in Variable &lt;b&gt;ArrayIndex&lt;/b&gt;.  The Action Code is tested in the &lt;b&gt;Select Case….End Select&lt;/b&gt; segment in the &lt;b&gt;myBookMarks()&lt;/b&gt; Function. The Bookmark value itself is not displayed anywhere. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Combo Box Name&lt;/b&gt; : &amp;quot;cboBMList&amp;quot; – to display the Index Number of the BookmarkList Array in the Combo Box. The Name of the Control is enough to reference it on the Active Form. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Record Field Value&lt;/b&gt; : OrderID – to display the Record Field Value in the Combo Box along with the BookMarkList Array Index number. You can use any Field Value of your Table so far as it serves the purpose of checking the correctness of the record retrieved using the Bookmark. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;The third parameter of &lt;b&gt;myBookMarks()&lt;/b&gt; Function is defined as &lt;b&gt;Optional&lt;/b&gt; and is omitted while calling the Functions to retrieve the Bookmark or to erase the Bookmarks List in the following three Sub-Routines respectively: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;Private Sub cboBMList_Click()&lt;br /&gt;    myBookMarks 2, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub cmdReset_Click()&lt;br /&gt;    myBookMarks 3, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;‘Erases the Bookmarks when the Form is closed&lt;br /&gt;Private Sub Form_Unload(Cancel As Integer)&lt;br /&gt;    'Remove all Bookmarks from Memory&lt;br /&gt;    myBookMarks 3, &amp;quot;cboBMList&amp;quot;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;Since, the main Function &lt;b&gt;myBookMarks()&lt;/b&gt; references the &lt;b&gt;Active Form&lt;/b&gt; you can implement this method on any Form without directly passing any Form Name to the Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt;&lt;ol&gt; &lt;li&gt;Saving, retrieving and using Bookmarks for finding records is valid only for the current session of the Form. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Re-querying the Form&amp;#39;s contents (not Refreshing) re-creates the Bookmarks for the Recordset on the form and earlier saved Bookmarks may not be valid after that. You must create fresh Bookmark List to use correctly. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;This method will not work on Forms attached to external Data Sources, linked to Microsoft Access, that doesn&amp;#39;t support bookmarks. &lt;/li&gt; &lt;br /&gt;&lt;/ol&gt; &lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml&lt;br /&gt;&amp;amp;title=Form+BookMarks+and+Data+Editing"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/detail-and-summary-from-same-report.shtml"&gt;Detail and Summary from Same Report&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3.shtml"&gt;Hiding Report Lines Conditionally-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-2.shtml"&gt;Hiding Report Lines Conditionally-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Hiding Report Lines Conditionally&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3.shtml"&gt;Network and Report Page Setup-3&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-2589006932856349121?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/10/form-bookmarks-and-data-editing.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-5927704929147255934</guid><pubDate>Fri, 16 Oct 2009 06:34:00 +0000</pubDate><atom:updated>2009-10-18T21:23:18.489+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess animation</category><title>Run Slide Show when Form is Idle</title><description>&lt;i&gt;Dear Readers,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I am very sorry about last two weeks unexpected events and could not come out with the weekly Articles. I had to go to India on an emergency on 27th September 2009 and the Website also failed on the same day itself due to some errors in the Web Server Configuration changes made by Administrators. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have noticed this serious state of the Website on 8th of October and could bring up the Site only on 9th of October 2009.  I deeply regret the inconvenience caused to you.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This week, we will create a Slide Show of images on a &lt;a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars.shtml"&gt;Form&lt;/a&gt; that runs when the Form remains idle for a certain period of time.  It works something like the following: &lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;When the &lt;a href="http://www.msaccesstips.com/2007/06/control-screen-design.shtml"&gt;Main Switchboard Form&lt;/a&gt; remains idle for about one minute the Slide Show runs and each image will change on a fixed interval of about 6 Seconds. The Idle Time and Interval Time can be changed according to your specific needs.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;The idle time of the Form is calculated based on the inactivity (i.e. no interaction with the User) of the Main Switchboard Form and the active control on the Form remains active for more than one minute.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If you click on a &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; or &lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;List box&lt;/a&gt; or any other control other than the active control on the Main Switchboard Form then the Form comes out of idle state and the Slide Show stops. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Checking for the idle state of the &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Form&lt;/a&gt; starts again from that point onwards with the new active control. If the same control remains active for more than one minute then the slide show starts again.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;If you open another Form over the Main Switchboard Form then the slide show sleeps until the Main Switchboard From becomes active again.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;You need few Bitmap Images of Landscapes or Photos and you can use as many images as you like for the Slide Show. All the images should have the same name with a Sequence Number at the end like &lt;b&gt;Image1.bmp, Image2.bmp, Image3.bmp&lt;/b&gt; and so on. You can use &lt;b&gt;.jpg&lt;/b&gt; or &lt;b&gt;.GIF&lt;/b&gt; and other images but this will display a progress bar for a brief moment while loading the image into the Image Control. All images must be of the same type.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;A sample Main Switchboard Form with the active Slide Show is given below: &lt;br /&gt;&lt;br /&gt;&lt;Center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/slideshow-707452.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 251px;" src="http://www.msaccesstips.com/uploaded_images/slideshow-707448.jpg" border="0" alt="Sample Slide Show Screen" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt; &lt;ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;To try out this interesting trick; first organize few Bitmap Images into a folder as explained above.&lt;/li&gt; &lt;br /&gt;&lt;li&gt;Make a copy of your existing Main Switchboard Form (&lt;a href="http://www.msaccesstips.com/2007/06/control-screen-menu-design.shtml"&gt;Control Screen&lt;/a&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the Form in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Make enough room on the Form to create an Image Control on the Form. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Toolbox (&lt;b&gt;View - -&gt;Toolbox&lt;/b&gt;), if it is not visible. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Control Wizards&lt;/b&gt; button on the Toolbox to make it active. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;Image&lt;/b&gt; control Tool from the &lt;b&gt;Toolbox&lt;/b&gt; and draw an Image Control on the Form where you want the Slide Show to appear. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;The &lt;b&gt;Common Dialog Control&lt;/b&gt; will display. Browse to the Images location and select the image with Serial Number 1 (Image1.bmp).&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;The selected image will appear in the Image Control.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;While the Image control is still in selected state; display the Property Sheet (&lt;b&gt;View - -&gt; Properties&lt;/b&gt;) and change the following Property Values as indicated below:&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Name  =  ImageFrame&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Size Mode  =  Zoom&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt; We need part of the &lt;b&gt;Picture&lt;/b&gt; Property Value (the location address of the Images) to make changes in the Program that we are going to introduce into the Code Module of the Form. So, note down the image location address on paper from the &lt;b&gt;Picture&lt;/b&gt; Property or copy and paste it into a Notepad Document for later use.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Display the Code Module of the Form (&lt;b&gt;View - -&gt; Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Press &lt;b&gt;Ctrl+A&lt;/b&gt; to highlight the existing VBA Code in the Module, if present, and press &lt;b&gt;Delete&lt;/b&gt; to remove them.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following Code into the Form Module.&lt;/li&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Option Compare Database&lt;br /&gt;Option Explicit&lt;br /&gt;&lt;br /&gt;Dim actForm As String, actControl As String, idletime As Integer&lt;br /&gt;Dim oldForm As String, oldControl As String, imageNo As Integer&lt;br /&gt;&lt;br /&gt;Private Sub Form_Activate()&lt;br /&gt;    Me.TimerInterval = 1000&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Form_Deactivate()&lt;br /&gt;    Me.TimerInterval = 0&lt;br /&gt;    Me.ImageFrame.Visible = False&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;DoCmd.Restore&lt;br /&gt;&lt;br /&gt;idletime = 0&lt;br /&gt;Me.ImageFrame.Visible = False&lt;br /&gt;Me.TimerInterval = 1000&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Form_Timer()&lt;br /&gt;&lt;br /&gt;actForm = Screen.activeForm.Name&lt;br /&gt;actControl = Screen.activeForm.activeControl.Name&lt;br /&gt;&lt;br /&gt;&lt;b&gt;If actForm = oldForm And actControl = oldControl And actForm = &amp;quot;Control&amp;quot; Then&lt;/b&gt;&lt;br /&gt;    idletime = idletime + 1&lt;br /&gt;Else&lt;br /&gt;    oldForm = actForm&lt;br /&gt;    oldControl = actControl&lt;br /&gt;    idletime = 0&lt;br /&gt;    Me.ImageFrame.Visible = False&lt;br /&gt;    DoEvents&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;If idletime &amp;gt; 60 Then&lt;br /&gt;   If idletime Mod 6 = 0 Then&lt;br /&gt;        Me.ImageFrame.Visible = True&lt;br /&gt;        imageNo = imageNo + 1&lt;br /&gt;        &lt;b&gt;imageNo = IIf(imageNo &amp;lt; 1 Or imageNo &amp;gt; 9, 1, imageNo)&lt;/b&gt;&lt;br /&gt;        &lt;b&gt;Me.ImageFrame.Picture = &amp;quot;E:\D\Movie\Britanica_Scenes\scene&amp;quot; &amp;amp; imageNo &amp;amp; &amp;quot;.bmp&amp;quot;&lt;/b&gt;&lt;br /&gt;        DoEvents&lt;br /&gt;   End If&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You have to make changes on few lines in the program that appears in bold letters.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Change the word &amp;quot;Control&amp;quot; in the first line (with bold letters) with your own Main Switchboard Form Name. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change Number &lt;b&gt;9&lt;/b&gt;, in the second line with bold letters, to match with the number of Images you have saved for the Slide Show as explained above.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy the Image Location Address and Image Name except Serial Number from the image location address we have saved in Notepad Document and Paste over the text &lt;b&gt;&lt;font class="colrgreen"&gt; E:\D\Movie\Britanica_Scenes\scene&lt;/font&gt;&lt;/b&gt; in the Program.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If your pictures are not Bitmap Images then change the file extension &lt;b&gt;&amp;quot;.bmp&amp;quot;&lt;/b&gt; to indicate your image type.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Save and Close the Form.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the Main Switchboard Form in Normal View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Wait for one minute to begin the Slide Show.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;When the Slide Show is running, if you click on a Control other than the active control on the Form the Slide Show will stop and the image will disappear.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you don&amp;#39;t click on any other control on the Form and the time elapsed is more than one minute, since your last click on a Control, the Slide Show will run again.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you want to increase or decrease the idle time of the Form then change the value in the VBA line &lt;b&gt;&lt;font class="colrgreen"&gt; If idletime &amp;gt; 60 Then&lt;/font&gt;&lt;/b&gt; to an appropriate value you prefer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Each Image stays displayed for about 6 seconds.  If you want to increase or decrease the display time then change the Value in the VBA line &lt;b&gt;&lt;font class="colrgreen"&gt; If idletime Mod 6 = 0 Then&lt;/font&gt;&lt;/b&gt; to the required value you prefer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2008/05/selected-list-box-items-and-dynamic.shtml&amp;amp;title=Selected+List-Box+Items+and+Dynamic+Query"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-5927704929147255934?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/10/run-slide-show-when-form-is-idle.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-4230870708062790891</guid><pubDate>Fri, 25 Sep 2009 12:01:00 +0000</pubDate><atom:updated>2009-09-25T16:39:17.541+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Filter Function Output In Listbox-2</title><description>Last week we have seen the usage of &lt;a href="http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml"&gt;Filter() Function&lt;/a&gt; with a simple example and I hope you understood how it works. We have assigned constant values to the Source Array elements directly to keep the VBA Code as simple as possible. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can filter data on Forms by setting Criteria on the &lt;b&gt;Filter&lt;/b&gt; Property of Forms. Similarly, we can use conditions in Queries to filter information from Tables as well. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, the &lt;b&gt;Filter()&lt;/b&gt; Function gives a unique way of filtering data from an Array of information loaded from Tables or Queries and create output quickly based on &lt;b&gt;matching&lt;/b&gt; or &lt;b&gt;non-matching&lt;/b&gt; options. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us try out the &lt;b&gt;Filter()&lt;/b&gt; Function in an &lt;b&gt;Address Book&lt;/b&gt; Application to quickly find persons or places that matches with the specified search text and display them in a List Box.  We will use Names and Addresses from the Employees Table of &lt;b&gt;Northwind.mdb&lt;/b&gt; sample database for our experiment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Following is the User Interface design that we planned to create and explains how the User will interact with it to display information quickly on the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will design a Form with a List Box, a Text Box Control, a Check-Box Control and a Command Button for our experiment. An image of such a Form in Design View is given below: &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/filteroutput1-703188.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 220px;" src="http://www.msaccesstips.com/uploaded_images/filteroutput1-703186.jpg" border="0" alt="User Interface in Design View" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;When the Form is open in normal view the &lt;a href="http://www.msaccesstips.com/2008/05/selected-list-box-items-and-dynamic.shtml"&gt;List Box&lt;/a&gt; and Text Box Controls will be empty.  The User can enter the word &lt;b&gt;ALL&lt;/b&gt; in the Text Box Control and click the &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; to display the Name and Addresses of all Employees in the List Box. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Or&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The User can enter a word or phrase, like part of a Name or Address, that can match anywhere within the Name and Address text, and click on the &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; to filter out the matching items and to display them in the List Box. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the &lt;b&gt;Matching Cases&lt;/b&gt; Check-Box is in selected state then the Filter action will select records that matches with the search text given in the &lt;a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins.shtml"&gt;Text Box&lt;/a&gt; Control otherwise it will select all records that &lt;b&gt;do not match&lt;/b&gt; with the search text. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To provide the User with the above facility we need two Subroutines on the Form&amp;#39;s Code Module and a &lt;a href="http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml"&gt;User Defined Function&lt;/a&gt; in Standard Module of the Database to use the Filter() Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When the User opens the above Form the first Sub-Routine is run from the &lt;b&gt;Form_Load()&lt;/b&gt; &lt;i&gt;EventProcedure&lt;/i&gt; to read the data (First Name, Last Name &amp;amp; Address) from Employees Table, join all the three field values into a single row of text and load them into a &lt;b&gt;Singly Dimensioned Array&lt;/b&gt; Variable in Memory. This data will remain in memory till the User closes the Form.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The second Sub-Routine is run when the User clicks on the &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Button&lt;/a&gt; to extract information from the Source Array with the help of &lt;b&gt;Filter()&lt;/b&gt; function, based on the search text entered into the Text Box Control. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Filter()&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/11/sum-min-max-avg-paramarray.shtml"&gt;Function&lt;/a&gt; will extract the entries that matches with the search Text in the Text Box Control, from the Source Array Variable, and save the output into the target variable  xTarget.  All we have to do is to take these values, format and insert as &lt;b&gt;Row Source&lt;/b&gt; Property Value to display them in the &lt;a href="http://www.msaccesstips.com/2008/05/create-list-from-another-listbox.shtml"&gt;List Box&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/filteroutput2-733414.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 224px;" src="http://www.msaccesstips.com/uploaded_images/filteroutput2-733409.jpg" border="0" alt="Filtered Records Output View" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;Let us prepare for the &lt;b&gt;Address Book&lt;/b&gt;&amp;#39;s Quick Find Project. &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Import &lt;b&gt;Employees&lt;/b&gt; Table from &lt;font class=”colrgreen”&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt; sample database.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open a new Form in Design View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select the List Box Control from the Tool Box and draw a &lt;b&gt;List Box&lt;/b&gt; as shown on the design above.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;While the List Box is in selected state display the Property Sheet (&lt;b&gt;View - - &gt; Properties&lt;/b&gt;) and change the following Property Values as given below:&lt;/li&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Name            =  AddBook&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Row Source Type = Value List&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Width           = 4.5&amp;quot;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Height          = 1.75&amp;quot;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Font Name       = Courier New&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Font Size       =  10&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Position the Child Label attached to the List Box above and change the &lt;b&gt;Caption&lt;/b&gt; value to &lt;b&gt;Address Book&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Draw a &lt;b&gt;Text Box&lt;/b&gt; below the List Box.  Change the &lt;b&gt;Name&lt;/b&gt; Property of the Text Box to &lt;b&gt;xFind&lt;/b&gt;. Position the Child Label above the Text Box and change the &lt;b&gt;Caption&lt;/b&gt; value to &lt;b&gt;Search Text/ALL&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a &lt;b&gt;Check-Box&lt;/b&gt; Control to the right of the Text Box.  Change the &lt;b&gt;Name&lt;/b&gt; Property of the Check-Box to &lt;b&gt;MatchFlag&lt;/b&gt;. Change the &lt;b&gt;Default Value&lt;/b&gt; Property to &lt;b&gt;True&lt;/b&gt;.  Change the &lt;b&gt;Caption&lt;/b&gt; value of the child label to &lt;b&gt;Matching Cases&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create a &lt;b&gt;Command Button&lt;/b&gt; to the right of the Check-Box control.  Change the &lt;b&gt;Name&lt;/b&gt; Property Value of the Command Button to &lt;b&gt;cmdFilter&lt;/b&gt; and the &lt;b&gt;Caption&lt;/b&gt; Property Value to &lt;b&gt;Filter&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB&lt;/b&gt;: Ensure that the &lt;b&gt;Name&lt;/b&gt; Property Values of the above controls are given exactly as I have mentioned above.  This is important because we are referencing these names in Programs. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Display the Code Module of the Form (&lt;b&gt;View- - &gt;Code&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the following Code into the Form Module:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Option Compare Database&lt;br /&gt;Option Explicit&lt;br /&gt;Dim xSource() As Variant&lt;br /&gt;&lt;br /&gt;Private Sub Form_Load()&lt;br /&gt;Dim db As Database, rst As Recordset, J As Integer&lt;br /&gt;Dim FName As String * 12, LName As String * 12, Add As String * 20&lt;br /&gt;&lt;br /&gt;'Take the count of records&lt;br /&gt;J = DCount(&amp;quot;*&amp;quot;, &amp;quot;Employees&amp;quot;)&lt;br /&gt;&lt;br /&gt;'redimension the array for number of records&lt;br /&gt;ReDim xSource(J) As Variant&lt;br /&gt;&lt;br /&gt;Set db = CurrentDb&lt;br /&gt;Set rst = db.OpenRecordset(&amp;quot;Employees&amp;quot;, dbOpenDynaset)&lt;br /&gt;'load the name and addresses into the array&lt;br /&gt;J = 0&lt;br /&gt;Do Until rst.EOF&lt;br /&gt;   FName = rst![FirstName]&lt;br /&gt;   LName = rst![LastName]&lt;br /&gt;   Add = rst![Address]&lt;br /&gt;  xSource(J) = FName &amp; LName &amp; Add&lt;br /&gt;rst.MoveNext&lt;br /&gt;J = J + 1&lt;br /&gt;Loop&lt;br /&gt;rst.Close&lt;br /&gt;Set rst = Nothing&lt;br /&gt;Set db = Nothing&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Private Sub cmdFilter_Click()&lt;br /&gt;Dim x_Find As String, xlist As String, xTarget As Variant&lt;br /&gt;Dim x_MatchFlag As Boolean, J As Integer&lt;br /&gt;&lt;br /&gt;Me.Refresh&lt;br /&gt;x_Find = Nz(Me![xFind], &amp;quot;&amp;quot;)&lt;br /&gt;x_MatchFlag = Nz(Me![MatchFlag], 0)&lt;br /&gt;&lt;br /&gt;'if no search criteria then exit&lt;br /&gt;If Len(x_Find) = 0 Then&lt;br /&gt;  Exit Sub&lt;br /&gt;End If&lt;br /&gt;    'initialize list box&lt;br /&gt;    xlist = &amp;quot;&amp;quot;&lt;br /&gt;    Me.AddBook.RowSource = xlist&lt;br /&gt;    Me.AddBook.Requery&lt;br /&gt;&lt;br /&gt;If UCase(x_Find) = &amp;quot;ALL&amp;quot; Then&lt;br /&gt;    'Take all values from the Source Array&lt;br /&gt;    'Format it as listbox items&lt;br /&gt;    For J = 0 To UBound(xSource())&lt;br /&gt;      xlist = xlist &amp;amp; xSource(J) &amp;amp; &amp;quot;;&amp;quot;&lt;br /&gt;    Next&lt;br /&gt;Else&lt;br /&gt;    'Call the Filter Function&lt;br /&gt;    xTarget = GetFiltered(xSource(), x_Find, x_MatchFlag)&lt;br /&gt;    'format the returned values as list box items&lt;br /&gt;    If Len(xTarget(0)) &gt; 0 Then&lt;br /&gt;        For J = 0 To UBound(xTarget)&lt;br /&gt;            xlist = xlist &amp;amp; xTarget(J) &amp;amp; &amp;quot;;&amp;quot;&lt;br /&gt;        Next&lt;br /&gt;    End If&lt;br /&gt;End If&lt;br /&gt;    'remove the semicolon from&lt;br /&gt;    'the end of the list box Value List&lt;br /&gt;    If Len(xlist) &gt; 0 Then&lt;br /&gt;        xlist = Left(xlist, Len(xlist) - 1)&lt;br /&gt;    End If&lt;br /&gt;    'insert the list item string&lt;br /&gt;    'and refresh the list box&lt;br /&gt;    Me.AddBook.RowSource = xlist&lt;br /&gt;    Me.AddBook.Requery&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save the Form with the name &lt;b&gt;Filter Form&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy and paste the following Function in a Standard Module and save the Module:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt2"&gt;&lt;br /&gt;Public Function GetFiltered(ByRef SourceArray() As Variant, ByVal xFilterText As Variant, ByVal FilterType As Boolean) As Variant&lt;br /&gt;&lt;br /&gt;GetFiltered = Filter(SourceArray, xFilterText, FilterType)&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We cannot use the &lt;b&gt;Filter()&lt;/b&gt; Function in the Form Module because the function name clashes with the Form Property &lt;b&gt;Filter&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have inserted the &lt;b&gt;Filter()&lt;/b&gt; Function in the Standard Module enveloped in a User Defined Function &lt;b&gt;GetFiltered()&lt;/b&gt; with necessary Parameters so that we can call it from Form Module. The first parameter to the Function is passed &lt;b&gt;By Reference&lt;/b&gt; so that it can use the Source Array values directly. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the &lt;b&gt;Filter Form&lt;/b&gt; in normal View.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Enter the word &lt;b&gt;ALL&lt;/b&gt; (in this case the &lt;b&gt;Matching Cases&lt;/b&gt; flag has no effect) in the Text Box control and Click on the &lt;b&gt;Filter&lt;/b&gt; Command Button.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;This action will display the Name and Addresses of all Employees from the &lt;b&gt;xSource()&lt;/b&gt; Array loaded from the Employees Table. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Enter the text &lt;b&gt;Ave&lt;/b&gt; in the Text Box and see that the &lt;b&gt;Matching Cases&lt;/b&gt; check box is in selected state.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the Command Button.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;This time you will find that only two Employee (Nancy &amp;amp; Laura) names and addresses are filtered and the word &lt;b&gt;Ave&lt;/b&gt; is appearing in their Address Lines. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Remove the check-mark from the &lt;b&gt;Matching Cases&lt;/b&gt; check box and click on the &lt;b&gt;Filter&lt;/b&gt; Command Button again.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;Now, all items except the lines with the word &lt;b&gt;Ave&lt;/b&gt; are listed in the List Box. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you go through the Programs that we have copied into the Form Module you can see that we have declared the &lt;b&gt;xSource() Array&lt;/b&gt; Variable in the Global area of the Module so that we can use the data in both Sub-Routines in the Form Module. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In the &lt;b&gt;Form_Load()&lt;/b&gt; &lt;i&gt;Event Procedure&lt;/i&gt; we have declared three Variables as fixed length String Type (see the declaration line given below). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class=”colrgreen”&gt; Dim FName As String * 12, LName As String * 12, Add As String * 20&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;When we read employee Name and Address into these Variables the values will be left justified inside the Variable and balance area of the declared size will be space filled to the right.  This method will space out items in fixed distance from each other and properly aligned when displayed. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It is important that we use a Fixed Width Font, like &lt;b&gt;Courier New&lt;/b&gt;, for the List Box display and we set this in &lt;b&gt;Step-4&lt;/b&gt; above. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you click the &lt;b&gt;Filter&lt;/b&gt; Command Button when the Text Box is empty then the program terminates, otherwise it calls the &lt;b&gt;GetFiltered()&lt;/b&gt; Function by passing the parameter values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The output Values are returned in the &lt;b&gt;xTarget Array&lt;/b&gt; and the next steps formats the Value List and displays them in the List Box.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml&amp;amp;title=Filter+Function+Output+in+ListBox-2 "&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-3.shtml"&gt;Hiding Report Lines Conditionally-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-2.shtml"&gt;Hiding Report Lines Conditionally-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Hiding Report Lines Conditionally&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3.shtml"&gt;Network and Report Page Setup-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Network and Report Page Setup-2&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-4230870708062790891?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox-2.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-36408464989205079</guid><pubDate>Fri, 18 Sep 2009 13:45:00 +0000</pubDate><atom:updated>2009-09-18T18:22:44.242+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Filter Function output in ListBox</title><description>This FILTER is not related to a Query or WHERE clause in SQL or Filter settings on a Form. It is a built-in &lt;a href="http://www.msaccesstips.com/2007/09/useful-report-functions.shtml"&gt;Function&lt;/a&gt;.  Its usage is very interesting and it is useful to quickly filter out data from an Array of information through text matching.  We will use this Function to search for values across more than one field of data from a Table, extract matched items or mismatch items, as the case may be, and display them in a &lt;a href="http://www.msaccesstips.com/2008/05/create-list-from-another-listbox.shtml"&gt;List Box&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But first, let us look into a simple example to understand its usage.  Copy and Paste the sample VBA code given below into a Standard Module in your database: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function myFilter()&lt;br /&gt;Dim X(7) As Variant, Y As Variant&lt;br /&gt;Dim J as Integer, msg as String&lt;br /&gt;&lt;br /&gt;X(0) = &amp;quot;Strawberry Milk&amp;quot;&lt;br /&gt;X(1) = &amp;quot;Chocolates&amp;quot;&lt;br /&gt;X(2) = &amp;quot;Milkshake&amp;quot;&lt;br /&gt;X(3) = &amp;quot;Mango Juice&amp;quot;&lt;br /&gt;X(4) = &amp;quot;Icecold Milk&amp;quot;&lt;br /&gt;X(5) = &amp;quot;Apple Juice&amp;quot;&lt;br /&gt;X(6) = &amp;quot;Buttermilk&amp;quot;&lt;br /&gt;X(7) = &amp;quot;Vanilla Icecream&amp;quot;&lt;br /&gt;&lt;br /&gt;'Extract all items containing the text &amp;quot;milk&amp;quot; from Array X()&lt;br /&gt;'and save the output in Array Y()&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Y = FILTER(x, &amp;quot;milk&amp;quot;, True, vbTextCompare)&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;msg = &amp;quot;&amp;quot;&lt;br /&gt;For J = 0 To UBound(Y)&lt;br /&gt;   msg = msg &amp;amp; J + 1 &amp;amp; &amp;quot;. &amp;quot; &amp;amp; Y(J) &amp;amp; vbCr&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;MsgBox msg&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Click anywhere within the Code and press &lt;b&gt;F5&lt;/b&gt; to Run the Code.  The output of the function will be displayed in an &lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;MsgBox&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/filteroutput-763467.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 145px; height: 149px;" src="http://www.msaccesstips.com/uploaded_images/filteroutput-763461.jpg" border="0" alt="Filter Function Output Display" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;Let us examine the above code closely.  The Variable &lt;b&gt;X&lt;/b&gt; is dimensioned for eight  elements and loaded the Array with text values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The FILTER() Function in the statement &lt;font class="colrgreen"&gt; Y = FILTER(X,&amp;quot;milk&amp;quot;,True,vbTextCompare)&lt;/font&gt; extracts the items that matches with the search text &lt;b&gt;milk&lt;/b&gt; from the Source Array of values from Variable &lt;b&gt;X&lt;/b&gt; and saves the output as an array of Values into Variable &lt;b&gt;Y&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The FILTER() Function accepts four parameters. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first parameter &lt;b&gt;X&lt;/b&gt; is the Array containing the Text Values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The second parameter value &lt;b&gt;milk&lt;/b&gt; is the search text that is compared with each item of the Array of values in variable X and if a match found anywhere within the Array Item then extracts that item as output and adds it into an element of the target Array Variable &lt;b&gt;Y&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The third parameter value &lt;b&gt;True&lt;/b&gt; asks the Filter Function to extract the &lt;b&gt;matched items&lt;/b&gt; as output and save them in Variable &lt;b&gt;Y&lt;/b&gt;. When this value is set as &lt;b&gt;False&lt;/b&gt; then the output will be &lt;b&gt;items that do not contain&lt;/b&gt; the search text &lt;b&gt;milk&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The fourth Parameter asks the Filter Function to apply a specific comparison method like Binary Comparison, Database Comparison or Text Comparison method.  Here, we have used Text Comparison method. Third and fourth parameters are Optional.&lt;br /&gt;&lt;br /&gt;You may try the above Code with different piece of search text, like &lt;b&gt;juice&lt;/b&gt; or &lt;b&gt;Ice&lt;/b&gt; etc. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you look at the Variable declarations of the Code you can see that we have declared the Variable &lt;b&gt;Y&lt;/b&gt; as a simple Variant Type and not as an Array Variable. &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;But, this declaration is changed by the FILTER() Function and re-dimensions it as an Array automatically, depending on the output of the filter action.  Every time when we run the code with different search text parameter this can be different and unpredictable too. So, we have used the &lt;b&gt;UBound()&lt;/b&gt; Function to find the number of elements in the output Array for the &lt;b&gt;For…Next&lt;/b&gt; loop to take all the items and format a string to display the output items in the &lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;MsgBox&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Source Variable must be a singly dimensioned &lt;a href="http://www.msaccesstips.com/2008/11/sum-min-max-avg-paramarray.shtml"&gt;Array&lt;/a&gt;.  If your search text needs to be compared with several piece of information then join all of them together as a single string and load into the singly dimensioned array. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Filter() Function will not work in Code Modules of &lt;a href="http://www.msaccesstips.com/2009/03/change-form-modes-on-user-profile.shtml"&gt;Form&lt;/a&gt; or &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Report&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have developed an Application around this Function for our Secretary to find all the Office Files with their location addresses (we have hundreds of them) that matches a specific word or phrase in their Subject or Description Fields and display them in a &lt;a href="http://www.msaccesstips.com/2008/05/list-box-and-date-part-one.shtml"&gt;List Box&lt;/a&gt; on a Form. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;We will try a similar and simple example with data taken from more than one field of the Employees Table, joined together as source Array contents and display the Filter result in a List Box.  I will give details of this example in the next Article. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Till that time if you find you can use this function for some of your own tasks, you may do that.  When I come out with my example you can compare yours with that and find the difference. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you did it differently share your ideas with me, so that I can learn something from you too.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml&amp;amp;title=Filter+Function+Output+in+ListBox"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/07/hiding-report-lines-conditionally-2.shtml"&gt;Hiding Report Lines Conditionally-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Hiding Report Lines Conditionally&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3.shtml"&gt;Network and Report Page Setup-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Network and Report Page Setup-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Network and Report Page Setup&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-36408464989205079?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/09/filter-function-output-in-listbox.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-1919068303481318436</guid><pubDate>Fri, 11 Sep 2009 16:10:00 +0000</pubDate><atom:updated>2009-09-11T23:03:55.965+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess controls</category><title>Dynamic ListBox ComboBox Contents</title><description>&lt;br /&gt;&lt;br /&gt;How about displaying different Set of un-related Values in a List Box; Values in different column layouts interchangeably? Perhaps, the change over can be with the click of a Button or based on some other action from the User.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When we create a &lt;a href="http://www.msaccesstips.com/2008/05/create-list-from-another-listbox.shtml"&gt;List Box&lt;/a&gt; or &lt;a href="http://www.msaccesstips.com/2008/03/refresh-dependant-combo-box-contents.shtml"&gt;Combo Box&lt;/a&gt; we are provided with three different options in MS-Access:&lt;b&gt;Table/Query, Value List&lt;/b&gt; or &lt;b&gt;Field List&lt;/b&gt; to choose from in the &lt;b&gt;Row Source Type&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2007/08/saving-data-on-forms-not-in-table.shtml"&gt;Property&lt;/a&gt; to fill with values in them.  We normally use one of these Options to create a Combo Box or List Box and insert other Property Values, like &lt;b&gt;Column Count, Column Widths, Bound Column etc.&lt;/b&gt; manually. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, we can use a &lt;b&gt;User Defined Function&lt;/b&gt; in the &lt;b&gt;Row Source Type&lt;/b&gt; Property besides the values mentioned above to fill with Values in a List Box or Combo Box. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Even though this Function is known as a &lt;b&gt;User Defined Function&lt;/b&gt; it is actually defined by Microsoft Access and given in the &lt;b&gt;Help&lt;/b&gt; Documents with specific rules as how to use it with various parameter Values and VBA Code structure.  All we have to do is to Copy this Code and Customize to our specific needs. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can get the details of this Function, by placing the insertion point in the &lt;b&gt;Row Source Type&lt;/b&gt; Property of a List Box or Combo Box Control and by pressing &lt;b&gt;F1&lt;/b&gt; Key to display the Help Document.  When the Help Document is open look for the Hyperlink with the description &lt;b&gt;User-define Function&lt;/b&gt; and click on it to display the details of various parameters and what they do in the Function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will look closely at the second example Code given in the Help Document. The VBA Code is given below and we will use it in a List Box to get a general idea of its usage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Function ListMDBs(fld As Control, ID As Variant,  row As Variant, col As Variant,  code As Variant) As Variant&lt;br /&gt;    Static dbs(127) As String, Entries As Integer&lt;br /&gt;    Dim ReturnVal As Variant&lt;br /&gt;    ReturnVal = Null&lt;br /&gt;    Select Case code&lt;br /&gt;        Case acLBInitialize                ' Initialize.&lt;br /&gt;            Entries = 0&lt;br /&gt;            dbs(Entries) = Dir(&amp;quot;*.MDB&amp;quot;)&lt;br /&gt;            Do Until dbs(Entries) = &amp;quot;&amp;quot; Or Entries &amp;gt;= 127&lt;br /&gt;                Entries = Entries + 1&lt;br /&gt;                dbs(Entries) = Dir&lt;br /&gt;            Loop&lt;br /&gt;            ReturnVal = Entries&lt;br /&gt;        Case acLBOpen                        ' Open.&lt;br /&gt;            ' Generate unique ID for control.&lt;br /&gt;            ReturnVal = Timer&lt;br /&gt;        Case acLBGetRowCount            ' Get number of rows.&lt;br /&gt;            ReturnVal = Entries&lt;br /&gt;        Case acLBGetColumnCount    ' Get number of columns.&lt;br /&gt;            ReturnVal = 1&lt;br /&gt;        Case acLBGetColumnWidth    ' Column width.&lt;br /&gt;            ' -1 forces use of default width.&lt;br /&gt;            ReturnVal = -1&lt;br /&gt;        Case acLBGetValue                    ' Get data.&lt;br /&gt;            ReturnVal = dbs(row)&lt;br /&gt;        Case acLBEnd                        ' End.&lt;br /&gt;            Erase dbs&lt;br /&gt;    End Select&lt;br /&gt;    ListMDBs = ReturnVal&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Copy the above Code into a new Standard Module in your Database and save it. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open a new Form in Design View and create a List Box on it. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the List Box to select it, if it is not already in selected state. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Property Sheet (&lt;b&gt;View - -&gt; Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Insert the Function name &lt;b&gt;ListMDBs&lt;/b&gt; in the &lt;b&gt;Row Source Type&lt;/b&gt; Property overwriting the value &lt;b&gt;Table/Query&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Save the Form. &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Open the Form in normal view. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;A list of databases from your default directory (check &lt;b&gt;Tools - -&gt; Options - -&gt; General&lt;/b&gt; Tab for your default directory location) will appear in the List Box.  A sample image of a ListBox is given below: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/dynamiclist1-712039.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 222px; height: 175px;" src="http://www.msaccesstips.com/uploaded_images/dynamiclist1-712032.jpg" border="0" alt="List of Databases in List Box" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;You may modify the following entry in the Program to take listing of Word or Excel files in the List Box from different Folder like: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;dbs(Entries) = Dir(&amp;quot;*.xls&amp;quot;)&lt;br /&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;dbs(Entries) = Dir(&amp;quot;C:\My Documents\*.xls&amp;quot;)&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The  &lt;b&gt;dbs(Entries) = Dir&lt;/b&gt; in the subsequent calls uses the first call parameter value &lt;b&gt;&amp;quot;C:\My Documents\*.xls&amp;quot;&lt;/b&gt; by default and populates the String Array &lt;b&gt;dbs()&lt;/b&gt; in the &lt;b&gt;Initialize&lt;/b&gt; step of the Program. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is one of the segments of the Code we can customize and use it for different requirements.  After the initializing phase the Function is called repeatedly to obtain other values likes &lt;b&gt;Rows Count, Column Count&lt;/b&gt; and others to define the Property Values of the List Box, which we normally set manually on the List Box in design time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;ColumnWidths&lt;/b&gt;, when set with the &lt;b&gt;Value -1&lt;/b&gt; in the Program gives the signal to use the Default Values set manually on the Property Sheet without change.  This is useful when we need a mixed format of different column sizes when more than one column of information is displayed. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Finally, the following statements pass the List Box Source Values &lt;b&gt;dbs(row)&lt;/b&gt; that we have created under the &lt;b&gt;Initialize&lt;/b&gt; stage for displaying in the List Box: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;        Case acLBGetValue        ' Get data.&lt;br /&gt;            ReturnVal = dbs(row)&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;row&lt;/b&gt; holds the value for the actual number of items we have loaded into the &lt;b&gt;dbs()&lt;/b&gt; Array of &lt;b&gt;127&lt;/b&gt; elements declared initially.  This value is passed to the Function through the &lt;b&gt;Entries&lt;/b&gt; Variable in the following segment of the Code: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;        Case acLBGetRowCount  ' Get number of rows.&lt;br /&gt;            ReturnVal = Entries&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;dbs&lt;/b&gt; Variable is declared as a &lt;b&gt;Static Singly Dimensioned Array&lt;/b&gt; with &lt;b&gt;128&lt;/b&gt; elements (0 to 127) to retain the value loaded into it in the &lt;b&gt;Initialize&lt;/b&gt; stage when the User Defined Function &lt;b&gt;ListMDBs&lt;/b&gt; is called repeatedly by MS-Access. The Parameter Values are automatically passed by MS-Access and we don’t need to provide them explicitly. The first Parameter is the name of the List Box Control.  The second Parameter ID is essential and this is set with the System Timer under the following statements: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;        Case acLBOpen     ' Open.&lt;br /&gt;            ' Generate unique ID for control.&lt;br /&gt;            ReturnVal = Timer&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;The System &lt;b&gt;Timer&lt;/b&gt; generates new values at every millisecond interval and this ensures that a unique number will always assign to this parameter as a unique &lt;b&gt;Identification&lt;/b&gt; Value if more than one User Defined Function is active at the same time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Code&lt;/b&gt; parameter passes appropriate values used in the &lt;b&gt;Select Case&lt;/b&gt; statements and uses the &lt;b&gt;Returned Values&lt;/b&gt; to define the List Box Property Values. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; If you understood or have a general idea as how this function works to define the contents of a List Box or Combo Box then we can go forward with the trick that I have mentioned at the beginning of this Article. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will create a Copy of the above Code and modify to create a List Box with Employees Code and First Name Values (two Columns of Values) from the Employees Table of Northwind.mdb database. &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Import the Employees Table from &lt;font class="colrgreen"&gt;C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb&lt;/font&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Copy the following VBA Code into the Standard Module of your database and save the Module:&lt;/li&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Function ListBoxValues(fld As Control, ID As Variant, row As Variant, col As Variant,&lt;br /&gt;     code As Variant) As Variant&lt;br /&gt;    Static xList(127, 0 To 1) As String, Entries As Integer&lt;br /&gt;    Dim ReturnVal As Variant, k As Integer&lt;br /&gt;    Dim db As Database, rst As Recordset, recCount As Integer&lt;br /&gt;    &lt;br /&gt;    ReturnVal = Null&lt;br /&gt;    Select Case code&lt;br /&gt;        Case acLBInitialize  ' Initialize.&lt;br /&gt;            Set db = CurrentDb&lt;br /&gt;            Set rst = db.OpenRecordset(&amp;quot;Employees&amp;quot, dbOpenDynaset)&lt;br /&gt;            Entries = 0&lt;br /&gt;            Do Until rst.EOF&lt;br /&gt;               For k = 0 To 1&lt;br /&gt;                    xList(Entries, k) = rst.Fields(k).Value&lt;br /&gt;               Next&lt;br /&gt;               rst.MoveNext&lt;br /&gt;               Entries = Entries + 1&lt;br /&gt;            Loop&lt;br /&gt;            rst.Close&lt;br /&gt;            ReturnVal = Entries&lt;br /&gt;        Case acLBOpen                    ' Open.&lt;br /&gt;            ' Generate unique ID for control.&lt;br /&gt;            ReturnVal = Timer&lt;br /&gt;        Case acLBGetRowCount         ' Get number of rows.&lt;br /&gt;            ReturnVal = Entries&lt;br /&gt;        Case acLBGetColumnCount    ' Get number of columns.&lt;br /&gt;            ReturnVal = 2&lt;br /&gt;        Case acLBGetColumnWidth    ' Column width.&lt;br /&gt;            ' -1 forces use of default width.&lt;br /&gt;            ReturnVal = -1&lt;br /&gt;        Case acLBGetValue                ' Get data.&lt;br /&gt;            ReturnVal = xList(row, col)&lt;br /&gt;        Case acLBEnd                        ' End.&lt;br /&gt;            Erase xList&lt;br /&gt;    End Select&lt;br /&gt;    ListBoxValues = ReturnVal&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the Form in Design View with the List Box that we have created earlier.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the List Box to select it.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Display the Property Sheet (&lt;b&gt;View- -&gt;Properties&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Change the &lt;b&gt;Column Widths&lt;/b&gt; Property Value to &lt;b&gt;0.5&amp;quot;;1.5&amp;quot;&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;The following lines of Code say that use the values set in the &lt;b&gt;Column Widths&lt;/b&gt; Property without change: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="colrgreen"&gt;&lt;br /&gt;        Case acLBGetColumnWidth    ' Column width.&lt;br /&gt;            ' -1 forces use of default width.&lt;br /&gt;            ReturnVal = -1&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;If the value in the &lt;b&gt;Column Widths&lt;/b&gt; Property is a single value (say 1&amp;quot;) then a multi-column List will use 1 Inch for all Columns.  This may not give a nice look for values with different length.  You may try this with different values to understand them better. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Create a &lt;b&gt;Command Button&lt;/b&gt; on the Form.&lt;br /&gt;&lt;li&gt;Ensure that the &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Command Button&lt;/a&gt; is in selected state and display the Property Sheet.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click on the &lt;b&gt;On Click&lt;/b&gt; Property and select &lt;b&gt;[EventProcedure]&lt;/b&gt; from the Drop Down control and Click on the Build (&lt;b&gt;…&lt;/b&gt;) Button to open the VBA Module with the skeleton of the &lt;b&gt;On Click&lt;/b&gt; Event Procedure.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following lines of Code in the middle of the &lt;b&gt;Event Procedure&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;Me.&lt;b&gt;List40&lt;/b&gt;.RowSourceType = &amp;quot;ListMDBs&amp;quot;&lt;br /&gt;Me.&lt;b&gt;List40&lt;/b&gt;.Requery&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;li&gt;Change the name of the List Box (the name in Bold Letters) to match with the name of your own List Box.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Create another &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Command Button&lt;/a&gt; below the first one.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Repeat the Procedure in &lt;b&gt;Step-10&lt;/b&gt; and &lt;b&gt;11&lt;/b&gt; for the &lt;b&gt;On Click&lt;/b&gt; Property of the second &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Command Button&lt;/a&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Copy and Paste the following Code in the middle of the &lt;b&gt;On Click&lt;/b&gt; Event Procedure:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="alt1"&gt;&lt;br /&gt;Me.&lt;b&gt;List40&lt;/b&gt;.RowSourceType = &amp;quot;ListBoxValues&amp;quot;&lt;br /&gt;Me.&lt;b&gt;List40&lt;/b&gt;.Requery&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Change the name of the List Box (the name in Bold Letters) in the Code to match with the name of your own List Box.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Save and Close the Form.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Open the Form in Normal View.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Since, you have already inserted the &lt;b&gt;ListMDBs&lt;/b&gt; User Defined Function in &lt;b&gt;Row Source Type&lt;/b&gt; Property earlier the list of databases will appear in the List Box first. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click on the second &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Command Button&lt;/a&gt; to change the List Box contents to the Employees List.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Sample image of the List Box with Employee List is given below: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;CENTER&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/dynamiclist2-754585.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 224px; height: 262px;" src="http://www.msaccesstips.com/uploaded_images/dynamiclist2-754573.jpg" border="0" alt="List Box with Employee List in two Columns" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/CENTER&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;Click on the first Command Button to change the &lt;a href="http://www.msaccesstips.com/2008/05/list-box-and-date-part-one.shtml"&gt;List Box&lt;/a&gt; Contents back to the Database List again.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;It works for Combo Boxes in the same way. You may create a Combo Box control and try in the same value. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Don&amp;#39;t forget to set the &lt;b&gt;Default Value&lt;/b&gt; Property with the value &lt;b&gt;1&lt;/b&gt;, otherwise the Combo Box may not show anything in its Text Box area before you select an item from the List.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml&amp;amp;title=Dynamic+ListBox+ComboBox+Contents"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/hiding-report-lines-conditionally.shtml"&gt;Hiding Report Lines Conditionally&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3.shtml"&gt;Network and Report Page Setup-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Network and Report Page Setup-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Network and Report Page Setup&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/filter-by-character-and-sort.shtml"&gt;Filter by Character and Sort&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-1919068303481318436?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/09/dynamic-listbox-combobox-contents.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-4974856693421386781</guid><pubDate>Fri, 04 Sep 2009 13:55:00 +0000</pubDate><atom:updated>2009-09-04T21:08:36.643+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess animation</category><title>Office Assistant And Msgbox Menus-3</title><description>&lt;br /&gt;&lt;br /&gt;After going through the earlier Articles on this subject I hope that the Readers are now familiar with programming the Balloon Object of Microsoft &lt;a href="http://www.msaccesstips.com/2008/02/selection-of-office-assistant.shtml"&gt;Office Assistant&lt;/a&gt;.  You have seen that you can use this feature with few lines of customizable VBA Code to display MsgBox text formatted with Color, underline and with your favorite Images on them.  We can display Menus on them to obtain responses from Users, besides the buttons that we normally use like &lt;b&gt;OK, Cancel, Yes, No&lt;/b&gt; etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Since, this Article is the third part of this series I suggest that new Readers may go through the earlier Documents on this subject to learn interesting and simple ways to use this feature in MS-Access before continuing with this Article.  Links to those Articles are given below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in MsgBox&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml"&gt;Office Assistant and MsgBox Menus-2&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Last week we have learned how to display Clickable Menu Options in Message Box with the use of Office Assistant.  The Image of that example is given below. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant03-726163.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 124px; height: 280px;" src="http://www.msaccesstips.com/uploaded_images/assistant03-726155.jpg" border="0" alt="MsgBox Image with Options" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;We have displayed the Menu Options on Message Box with the &lt;b&gt;Labels&lt;/b&gt; Property of the &lt;b&gt;Balloon&lt;/b&gt; Object of &lt;b&gt;Office Assistant&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here, we will learn how to display Menu Options with &lt;b&gt;Checkboxes&lt;/b&gt; and how responses from the User can be obtained, examined and execute actions that is programmed for each choice made? The example Code and the sample image of MsgBox that displays the Check-Box Menu are given below:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Function ChoicesCheckBox()&lt;br /&gt;Dim i As Long, msg As String&lt;br /&gt;Dim bln As Balloon, j As Integer&lt;br /&gt;Dim selected As Integer, checked As Integer&lt;br /&gt;&lt;br /&gt;Set bln = Assistant.NewBalloon&lt;br /&gt;With bln&lt;br /&gt;    .Heading = &amp;quot;Select Data Output Option&amp;quot;&lt;br /&gt;    .Checkboxes(1).text = &amp;quot;Print Preview.&amp;quot;&lt;br /&gt;    .Checkboxes(2).text = &amp;quot;Export to Excel.&amp;quot;&lt;br /&gt;    .Checkboxes(3).text = &amp;quot;Datasheet View.&amp;quot;&lt;br /&gt;    .Button = msoButtonSetOkCancel&lt;br /&gt;    .text = &amp;quot;Select one of &amp;quot; _&lt;br /&gt;       &amp;amp; .Checkboxes.Count &amp;amp; &amp;quot; Choices?&amp;quot;&lt;br /&gt;    i = .Show&lt;br /&gt;    &lt;br /&gt;    selected = 0&lt;br /&gt;    If i = msoBalloonButtonOK Then&lt;br /&gt;        'Validate Selection&lt;br /&gt;        For j = 1 To 3&lt;br /&gt;            If .Checkboxes(j).checked = True Then&lt;br /&gt;                selected = selected + 1&lt;br /&gt;                checked = j&lt;br /&gt;            End If&lt;br /&gt;        Next&lt;br /&gt;&lt;br /&gt;        'If User selected more than one item&lt;br /&gt;        'then re-run this program and force the&lt;br /&gt;        'User to select only one item as suggested&lt;br /&gt;        ‘in the message text.&lt;br /&gt;        If selected = 0 or selected &gt; 1 Then&lt;br /&gt;           Call ChoicesCheckBox&lt;br /&gt;        Else&lt;br /&gt;            Select Case checked&lt;br /&gt;                Case 1&lt;br /&gt;                    Debug.Print .Checkboxes(checked).text&lt;br /&gt;                Case 2&lt;br /&gt;                    Debug.Print .Checkboxes(checked).text&lt;br /&gt;                Case 3&lt;br /&gt;                   Debug.Print .Checkboxes(checked).text&lt;br /&gt;            End Select&lt;br /&gt;        End If&lt;br /&gt;    End If&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;End Function&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant05-720857.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 150px; height: 320px;" src="http://www.msaccesstips.com/uploaded_images/assistant05-720849.jpg" border="0" alt="Image of MsgBox with Labels Property" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Like the &lt;b&gt;Labels&lt;/b&gt; Property Array the dimension of &lt;b&gt;CheckBoxes&lt;/b&gt; also can be up to a maximum of five elements only.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In our earlier example we have not used the &lt;b&gt;OK&lt;/b&gt; or &lt;b&gt;Cancel&lt;/b&gt; buttons along with the Labels based Menu because the Balloon Button (&lt;b&gt;msoBalloonTypeButtons&lt;/b&gt;) based options were clickable and accepts the clicked item as a valid response and dismisses the Office Assistant on this action. The clicked item&amp;#39;s index number is returned as the response value and it was easy to check this value and execute the action accordingly.&lt;br /&gt;&lt;br /&gt;But in the case of Check-Boxes this is little more complex because of the following reasons&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;The Check Boxes can be either in &lt;b&gt;checked&lt;/b&gt; or in &lt;b&gt;unchecked&lt;/b&gt; state, which needs to be  validated.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The User may put check-marks on one or more Options at the same time.  If this cannot be allowed then there must be a validation check and force the User to make selection of one item only.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;If the User has the option of selecting more than one item then program must be written to execute more than one action based on the combination of selections made.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;In either case we have to inspect the &lt;b&gt;checked&lt;/b&gt; or &lt;b&gt;un-checked&lt;/b&gt; state of each element of the &lt;b&gt;CheckBoxes&lt;/b&gt; Array to determine the validity of Menu selection.&lt;/li&gt;  &lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;In the example code given above the User can select only one item at a time.&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;In the validation check stage of the code, first we are checking whether the User has clicked the &lt;b&gt;OK&lt;/b&gt; Button or not.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;If she did then in the next step we take a count of all check-marked items, in the Variable &lt;b&gt;selected&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;If the value in Variable &lt;b&gt;selected&lt;/b&gt; is &lt;b&gt;zero&lt;/b&gt; (User clicked &lt;b&gt;OK&lt;/b&gt; Button without selecting any option from the list) or selected more than one item then the Program is called again from within the &lt;b&gt;ChoicesCheckBox()&lt;/b&gt; Function itself. This will refresh the Menu, removes the check marks and display it again.  This will force the User to make only one selection as suggested in the message or she can click &lt;b&gt;Cancel&lt;/b&gt; Button.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;In the next step the action is programmed based on the selection made by the User.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;li&gt;If the User is allowed to put check-marks on more than one item (depending on the purpose of the Message Box based Menu) then the validation check and the execution of actions can be different and the code must be written accordingly.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;The methods which I have introduced to you and explained in these three Articles are good to learn the basics of this feature and easy to understand the usage of different Properties of &lt;b&gt;Balloon&lt;/b&gt; Object of &lt;b&gt;Office Assistant&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, you will appreciate the fact that duplicating and customizing these Codes everywhere in your Programs for different needs is not advisable.  This will increase the size of your database, no flexibility in usage of Code and it is not good programming practice either.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You may go through the Articles (links given below) published earlier on this Subject that shows how to define Public Functions like &lt;b&gt;MsgOK(), MsgYN(), MsgOKCL()&lt;/b&gt; and others with the use of Office Assistant. It simplifies the usage of this feature, without duplicating the Code, and can use them freely anywhere in your Programs like MS-Access &lt;b&gt;MsgBox()&lt;/b&gt; Function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The above Function Names themselves suggests what kind of Buttons will appear in the Message Box when they are called with the minimum Parameter Value of &lt;b&gt;Message Text&lt;/b&gt; alone or &lt;b&gt;Message Text&lt;/b&gt; and &lt;b&gt;Title&lt;/b&gt; Values.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2006/09/msgbox-with-office-assistant.shtml"&gt;Message Box with Office Assistant&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/01/msgbox-with-options-menu.shtml"&gt;Message Box with Options Menu&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/02/office-assistant-with-check-box-menu.shtml"&gt;Office Assistant with CheckBox Menu&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;A comparison of the above User Defined Function usage with the MsgBox is given below for references.  The underscore character in the text indicates the continuation of lines and should not be used when all values are placed on the same line.&lt;br /&gt;&lt;br /&gt;&lt;Table Border="1" width="550" cellpadding="5" cellspacing="0"&gt;&lt;tr&gt;&lt;td width="50%" align="center"&gt;&lt;b&gt;&lt;br /&gt;MS-Access MsgBox() usage&lt;/b&gt;&lt;/td&gt;&lt;td width="50%" align="center"&gt;&lt;b&gt;Office Assistant based User Defined Function usage&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width="50%" align="left"&gt;MsgBox &amp;quot;Welcome to Tips and Tricks&amp;quot;&lt;/td&gt;&lt;td width="50%" align="left"&gt;MsgOK &amp;quot;Welcome to Tips and Tricks&amp;quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width="50%" align="left"&gt;X = MsgBox(&amp;quot;Shut Down Application&amp;quot;, _ vbQuestion+vbDefaultButton2+vbYesNo, _  &amp;quot;cmdClose_Click()&amp;quot;)&lt;/td&gt;&lt;td width="50%" align="left"&gt;X = MsgYN(&amp;quot;Shut Down Application&amp;quot;, _ &amp;quot;cmdClose_Click()&amp;quot;)&lt;/td&gt;&lt;/tr&gt;&lt;td width="50%" align="left"&gt;X = MsgBox( &amp;quot;Click OK to Proceed or Cancel?&amp;quot;, _ vbOKCancel+vbDefaultButton2+vbQuestion, _ &amp;quot;MonthEndProcess()&amp;quot;)&lt;/td&gt;&lt;td width="50%" align="left"&gt;X = MsgOKCL(&amp;quot;Click OK to Proceed or Cancel?&amp;quot;, _ &lt;br /&gt;&amp;quot;MonthEndProcess()&amp;quot;)&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml&amp;amp;title=Office+Assistant+and+MsgBox+Menu-3"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-3.shtml"&gt;Network and Report Page Setup-3&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Network and Report Page Setup-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Network and Report Page Setup&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/filter-by-character-and-sort.shtml"&gt;Filter by Character and Sort&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/animating-label-on-search-success.shtml"&gt;Animating Label on Search Success&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-4974856693421386781?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/09/office-assistant-and-msgbox-menus-3.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-4889092950552440221</guid><pubDate>Fri, 28 Aug 2009 07:32:00 +0000</pubDate><atom:updated>2009-08-28T12:24:26.335+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess animation</category><title>Office Assistant And Msgbox Menus-2</title><description>This is the continuation of last Week&amp;#39;s Article: &lt;a href="http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml"&gt;Office Assistant and MsgBox Menus&lt;/a&gt;.  Readers may go through that Page first, if you have not already done so, before continuing. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Last week we have learned how to use Office Assistant for &lt;a href="http://www.msaccesstips.com/2006/09/msgbox-with-office-assistant.shtml"&gt;MsgBox&lt;/a&gt; in a simple way and seen how to create a &lt;a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars.shtml"&gt;Menu&lt;/a&gt; and present it to the User, with the &lt;b&gt;Labels&lt;/b&gt; Property of the &lt;b&gt;Balloon&lt;/b&gt; Object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant03-726163.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 124px; height: 280px;" src="http://www.msaccesstips.com/uploaded_images/assistant03-726155.jpg" border="0" alt="MsgBox Image with Options" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;We have seen that we can display the Menu from &lt;b&gt;Labels().Text&lt;/b&gt; Property in three different ways by setting the Values of &lt;b&gt;BalloonType&lt;/b&gt; Property: &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;BalloonType = &lt;b&gt;msoBalloonTypeButtons&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;The User can click on any of these &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Buttons&lt;/a&gt; to select one of the Options presented.&lt;br /&gt;&lt;br /&gt;&lt;li&gt;BalloonType = &lt;b&gt;msoBalloonTypeBullets&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BalloonType = &lt;b&gt;msoBalloonTypeNumbers&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;The second and third &lt;b&gt;BalloonType&lt;/b&gt; Values displays the &lt;b&gt;Labels().Text&lt;/b&gt; in different styles but they cannot be selected by the User. So, we can use these options for different situations in Programs. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us look little closer to the overall behavior of the &lt;b&gt;Balloon Object&lt;/b&gt; when you display MsgBox with Office Assistant, to understand it better. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;If you go back and try those earlier examples, you can see that while a &lt;b&gt;MsgBox&lt;/b&gt; with the Office Assistant&amp;#39;s &lt;b&gt;Balloon Object&lt;/b&gt; is displayed you cannot click or work with any other object in the database unless you dismiss the &lt;b&gt;Balloon&lt;/b&gt; by responding to the actions you are suggested to do, like clicking on the &lt;b&gt;OK&lt;/b&gt; or &lt;b&gt;Cancel&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Button&lt;/a&gt; and so on. This is true in the case of the normal MsgBox() &lt;a href="http://www.msaccesstips.com/2008/04/days-in-month-function.shtml"&gt;Function&lt;/a&gt; of MS-Access too. But, Office Assistant has some solution to this rigid behavior of Message Boxes. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;When the &lt;b&gt;Balloon&lt;/b&gt; is displayed, you cannot open a &lt;a href="http://www.msaccesstips.com/2008/10/form-menu-bars-and-toolbars.shtml"&gt;Form&lt;/a&gt; or &lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Report&lt;/a&gt; to check something on it, before clicking the &lt;b&gt;Yes&lt;/b&gt; or &lt;b&gt;No&lt;/b&gt; Button on the MsgBox because the &lt;font class=”colrgreen”&gt;&lt;b&gt;Mode&lt;/b&gt;&lt;/font&gt; Property of the &lt;b&gt;Balloon&lt;/b&gt; Object is set with default value &lt;font class=”colrgreen”&gt;&lt;b&gt;msoModeModal&lt;/b&gt;&lt;/font&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have not introduced the &lt;b&gt;Mode&lt;/b&gt; Property to you in the earlier examples to avoid overcrowding of usage rules.  Once you are through with the basics it will be easier to understand other things associated with it better.  You have already seen that you can create Message Boxes using Balloon Object of Office Assistant with few lines of Code and display them in style without using these properties. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Mode&lt;/b&gt; Property can be set with three different values to control the behavior of the &lt;b&gt;Balloon&lt;/b&gt; Object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; Mode  = &lt;b&gt;msoModeModal&lt;/b&gt; (default) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This value setting forces the User to dismiss the Balloon by responding to the suggested action before doing anything else, like normal MS-Access MsgBox. You have to click on one of the &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Buttons&lt;/a&gt; (if more than one is showing like &lt;b&gt;OK&lt;/b&gt; and &lt;b&gt;Cancel&lt;/b&gt;) on the MsgBox to dismiss the &lt;b&gt;Balloon&lt;/b&gt; before you are allowed to do anything else. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; Mode  =  &lt;b&gt;msoModeModeless&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This value setting allows the User to access other database objects, while the &lt;b&gt;Balloon&lt;/b&gt; is active. But, this forces the use of another Property &lt;b&gt;CallBack&lt;/b&gt;, to run separate &lt;b&gt;Sub-Routine&lt;/b&gt; to do the testing of selection of choices or do different things based on the choice and finally to &lt;b&gt;Close&lt;/b&gt; the &lt;b&gt;Balloon&lt;/b&gt; Object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; Mode  =  &lt;b&gt;msoModeAutoDown&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;This value setting dismisses the &lt;b&gt;Balloon&lt;/b&gt; (MsgBox) automatically if you click somewhere else ignoring the Balloon. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first and last &lt;b&gt;Mode&lt;/b&gt; Property value setting and their usages are very clear. But, the second one (&lt;b&gt;msoModeModeless&lt;/b&gt;) needs the &lt;b&gt;CallBack&lt;/b&gt; Property Value set with the name of a valid Sub-Routine otherwise the &lt;b&gt;Balloon&lt;/b&gt; will not work.  You cannot load the &lt;b&gt;CallBack&lt;/b&gt; Property with an empty string either because that will trigger an Error. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So let us see how we can re-write the earlier Program to understand the usage of &lt;b&gt;Mode Property&lt;/b&gt; set with the value &lt;b&gt;msoModeModeless&lt;/b&gt; and &lt;b&gt;Callback&lt;/b&gt; Property with the name of a Sub-Routine to handle the selection of option displayed in the Menu. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Modified Code with &lt;b&gt;Mode&lt;/b&gt; and &lt;b&gt;CallBack&lt;/b&gt; Property Settings and the sample Code for the required Sub-Routine &lt;b&gt;MyProcess()&lt;/b&gt; is given below: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Sub Choices()&lt;br /&gt;Dim bln As Balloon&lt;br /&gt;&lt;br /&gt;Set bln = Assistant.NewBalloon&lt;br /&gt;With bln&lt;br /&gt;    .Heading = &amp;quot;Report Options&amp;quot;&lt;br /&gt;    .Icon = msoIconAlertQuery&lt;br /&gt;    .Button = msoButtonSetNone&lt;br /&gt;    .labels(1).text = &amp;quot;Print Preview.&amp;quot;&lt;br /&gt;    .labels(2).text = &amp;quot;Print. &amp;quot;&lt;br /&gt;    .labels(3).text = &amp;quot;Pivot Chart. &amp;quot;&lt;br /&gt;    .BalloonType = msoBalloonTypeButtons&lt;br /&gt;    .text = &amp;quot;Select one of  &amp;quot; &amp;amp; .labels.Count &amp;amp; &amp;quot; Choices? &amp;quot;&lt;br /&gt;   &lt;b&gt; .mode = msoModeModeless&lt;br /&gt;    .Callback = &amp;quot;myProcess&amp;quot;&lt;/b&gt;&lt;br /&gt;    .Show&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sub MyProcess(&lt;b&gt;bln&lt;/b&gt; As Balloon, &lt;b&gt;lbtn&lt;/b&gt; As Long, &lt;b&gt;lPriv&lt;/b&gt; As Long)&lt;br /&gt;&lt;b&gt;Assistant.Animation = msoAnimationPrinting&lt;/b&gt;&lt;br /&gt;Select Case lbtn&lt;br /&gt;    Case 1&lt;br /&gt;        DoCmd.OpenReport &amp;quot;MyReport&amp;quot;, acViewPreview&lt;br /&gt;    Case 2&lt;br /&gt;        DoCmd.OpenReport &amp;quot;MyReport&amp;quot;, acViewNormal&lt;br /&gt;    Case 3&lt;br /&gt;        DoCmd.OpenReport &amp;quot;MyReport&amp;quot;, acViewPivotChart&lt;br /&gt;End Select&lt;br /&gt;    &lt;b&gt;bln.Close&lt;/b&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;CallBack&lt;/b&gt; Property is set with the Sub-Routine name &lt;b&gt;myProcess&lt;/b&gt;. When the User clicks on one of the Options from the displayed &lt;b&gt;MsgBox&lt;/b&gt; the &lt;b&gt;MyProcess()&lt;/b&gt; Sub-Routine is called by the &lt;b&gt;Balloon&lt;/b&gt; and passes the required &lt;b&gt;Parameter Values&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There are three parameters passed to the Sub-Routine when called: &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;The Balloon Object &lt;b&gt;bln&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;A &lt;b&gt;Long Integer&lt;/b&gt; type value &lt;b&gt;lbtn&lt;/b&gt; (BalloonTypeButton) identifying the Option clicked.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;A &lt;b&gt;Long Integer&lt;/b&gt; type value &lt;b&gt;lPriv&lt;/b&gt; (Private) uniquely identifying the &lt;b&gt;Balloon&lt;/b&gt; that called the Sub-Routine, if there are more than one &lt;b&gt;Balloon&lt;/b&gt; active in memory at the same time.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt; &lt;i&gt;There is no such thing as collection of Balloon Objects. But, you can create an Array of Variables with &lt;b&gt;Balloon&lt;/b&gt; Object, define different Property Settings for each of them and &lt;b&gt;.Show&lt;/b&gt; them with their respective index numbers in Programs when you need them to appear. &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;lbtn&lt;/b&gt; Variable will have the value of User&amp;#39;s choice. This is tested in the Sub-Routine and runs the &lt;b&gt;Docmd.OpenReport&lt;/b&gt; action within the &lt;b&gt;Select Case …End Select&lt;/b&gt; Statements.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;font class=”colrgreen”&gt; Assistant.Animation = msoAnimationPrinting&lt;/font&gt; line is placed in the Sub-Routine, rather than in the main Program as part of the &lt;b&gt;Balloon&lt;/b&gt; Object Property setting, to animate the printing action only after the User makes a selection from the displayed Menu otherwise the printing animation will run before the selection of choices. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;font class=”colrgreen”&gt;bln.close&lt;/font&gt; statement dismisses the MsgBox. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next week we will learn how to use the &lt;b&gt;CheckBoxes().Text&lt;/b&gt; Property Values of the &lt;b&gt;Balloon&lt;/b&gt; Object to display a Menu with &lt;b&gt;Check-Boxes&lt;/b&gt; in MsgBox.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml&amp;amp;title=Office+Assistant+and+MsgBox+Menus-2"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-print-page-setup-2.shtml"&gt;Network and Report Page Setup-2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Network and Report Page Setup&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/filter-by-character-and-sort.shtml"&gt;Filter by Character and Sort&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/animating-label-on-search-success.shtml"&gt;Animating Label on Search Success&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/form-background-with-gradient-color.shtml"&gt;Form Background with Gradient Color&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-4889092950552440221?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus-2.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-34083602.post-8091813746059922363</guid><pubDate>Wed, 19 Aug 2009 14:55:00 +0000</pubDate><atom:updated>2009-12-26T22:55:35.813+04:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>msaccess animation</category><title>Office Assistant and MsgBox Menus</title><description>&lt;br /&gt;&lt;br /&gt;In last Week&amp;#39;s Article: &lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in Message Box&lt;/a&gt; we have seen a method to use Office Assistant quickly to display a Message Box with formatted text. We are not going to discuss further on the formatting part but I have a general feeling that Readers would like to know how this simple method can be used to obtain responses from Users, out of several options presented to them, and do different things based on their selection of choices. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have already covered this topic by creating Functions like &lt;b&gt;MsgOK(), MsgYN(), MsgOKCL()&lt;/b&gt; etc.,  with the use of Office Assistant. These can be called with only the &lt;b&gt;Message Text&lt;/b&gt; Value alone or &lt;b&gt;Message Text&lt;/b&gt; and  &lt;b&gt;Title&lt;/b&gt; Values as Parameters, from anywhere within the Application like the built-in Function &lt;b&gt;MsgBox()&lt;/b&gt;.  I made an attempt to simplify the usage of Office Assistant through the above mentioned &lt;a href="http://www.msaccesstips.com/2008/11/custom-calculator-and-eval-function.shtml"&gt;Functions&lt;/a&gt; and others, which otherwise needs several property values to be passed to the Office Assistant’s &lt;b&gt;Balloon&lt;/b&gt; Object for displaying. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But, in the simplification process the method used in those Functions is not fully understood by several readers. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Links to those earlier posts are given below for reference: &lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2006/09/msgbox-with-office-assistant.shtml"&gt;Message Box with Office Assistant&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/01/msgbox-with-options-menu.shtml"&gt;Message Box with Options Menu&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.msaccesstips.com/2008/02/office-assistant-with-check-box-menu.shtml"&gt;Office Assistant with CheckBox Menu&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;In the example Code presented in last week’s Post: &lt;a href="http://www.msaccesstips.com/2009/08/color-and-picture-in-message-box.shtml"&gt;Color and Picture in Message Box&lt;/a&gt; we came across several Properties of the &lt;b&gt;Balloon&lt;/b&gt; Object of &lt;b&gt;Office Assistant&lt;/b&gt; that can be set with values before the Message Box is displayed. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We are going to work with these properties directly, so that it is easy to understand their usage, rather than passing values for them through the &lt;b&gt;Parameter List&lt;/b&gt; in the function definition. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Following are some of these properties: &lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Animation &lt;/li&gt;&lt;br /&gt;&lt;li&gt;Icon&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Heading&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Text&lt;/li&gt;&lt;br /&gt;&lt;li&gt;BalloonType&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Button&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB:&lt;/b&gt; If you have not already attached the &lt;b&gt;Microsoft Office Object Library&lt;/b&gt; to your Database, to try out the examples given here, then do that by following the procedure given below. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;i&gt;&lt;br /&gt;&lt;li&gt;Press &lt;b&gt;Alt+F11&lt;/b&gt; to display the VBA Code Window (or &lt;b&gt;Tools - -&gt;Macro- -&gt;Visual Basic Editor&lt;/b&gt;).&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Select &lt;b&gt;References&lt;/b&gt; from &lt;b&gt;Tools&lt;/b&gt; Menu.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Find &lt;b&gt;Microsoft Office Object Library&lt;/b&gt; in the &lt;b&gt;Available List&lt;/b&gt; and put a check mark to select it.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Click &lt;b&gt;OK&lt;/b&gt; to close the Dialog Box. &lt;/li&gt; &lt;br /&gt;&lt;/i&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;The value for &lt;b&gt;Animation&lt;/b&gt; alone has about thirty five different choices which are defined as Constants in the &lt;b&gt;Microsoft Office Object Library&lt;/b&gt;.  The constant values for &lt;b&gt;Balloon&lt;/b&gt; Properties &lt;b&gt;Animation, Button, Icon&lt;/b&gt; and &lt;b&gt;BalloonType&lt;/b&gt; are given below for reference: &lt;br /&gt;&lt;br /&gt;&lt;table width="400" border="1" cellpadding="5" cellspacing="0"&gt;&lt;tr&gt;&lt;td width="50%" align="center"&gt;&lt;b&gt;Animation&lt;/b&gt;&lt;/td&gt;&lt;td width="50%" align="center"&gt;&lt;b&gt;Icon&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width="50%" align="left" valign="top"&gt;&lt;br /&gt;msoAnimationAppear &lt;br /&gt;msoAnimationBeginSpeaking &lt;br /&gt;msoAnimationCharacterSuccessMajor &lt;br /&gt;msoAnimationCheckingSomething &lt;br /&gt;msoAnimationDisappear &lt;br /&gt;msoAnimationEmptyTrash &lt;br /&gt;msoAnimationGestureDown &lt;br /&gt;msoAnimationGestureLeft &lt;br /&gt;msoAnimationGestureRight &lt;br /&gt;msoAnimationGestureUp &lt;br /&gt;msoAnimationGetArtsy &lt;br /&gt;msoAnimationGetAttentionMajor &lt;br /&gt;msoAnimationGetAttentionMinor &lt;br /&gt;msoAnimationGetTechy &lt;br /&gt;msoAnimationGetWizardy &lt;br /&gt;msoAnimationGoodbye &lt;br /&gt;msoAnimationGreeting &lt;br /&gt;msoAnimationIdle &lt;br /&gt;msoAnimationListensToComputer &lt;br /&gt;msoAnimationLookDown &lt;br /&gt;msoAnimationLookDownLeft &lt;br /&gt;msoAnimationLookDownRight &lt;br /&gt;msoAnimationLookLeft &lt;br /&gt;msoAnimationLookRight &lt;br /&gt;msoAnimationLookUp &lt;br /&gt;msoAnimationLookUpLeft &lt;br /&gt;msoAnimationLookUpRight &lt;br /&gt;msoAnimationPrinting &lt;br /&gt;msoAnimationRestPose &lt;br /&gt;msoAnimationSaving &lt;br /&gt;msoAnimationSearching &lt;br /&gt;msoAnimationSendingMail &lt;br /&gt;msoAnimationThinking &lt;br /&gt;msoAnimationWorkingAtSomething &lt;br /&gt;msoAnimationWritingNotingSomething&lt;br /&gt;&lt;/td&gt;&lt;td width="50%" align="left" valign="top"&gt;&lt;br /&gt;msoIconAlert &lt;br /&gt;msoIconAlertCritical &lt;br /&gt;msoIconAlertInfo &lt;br /&gt;msoIconAlertQuery &lt;br /&gt;msoIconAlertWarning &lt;br /&gt;msoIconNone &lt;br /&gt;msoIconTip&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width="50%" align="left" valign="top"&gt;&lt;br /&gt;&lt;b&gt;Button&lt;/b&gt;&lt;/td&gt;&lt;td width="50%" align="left" valign="top"&gt;&lt;b&gt;BalloonType&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width="50%" align="left" valign="top"&gt;&lt;br /&gt;msoButtonSetAbortRetryIgnore &lt;br /&gt;msoButtonSetBackClose &lt;br /&gt;msoButtonSetBackNextClose &lt;br /&gt;msoButtonSetBackNextSnooze &lt;br /&gt;msoButtonSetCancel &lt;br /&gt;msoButtonSetNextClose &lt;br /&gt;msoButtonSetNone &lt;br /&gt;msoButtonSetOK &lt;br /&gt;msoButtonSetOkCancel &lt;br /&gt;msoButtonSetRetryCancel &lt;br /&gt;msoButtonSetSearchClose &lt;br /&gt;msoButtonSetTipsOptionsClose &lt;br /&gt;msoButtonSetYesAllNoCancel &lt;br /&gt;msoButtonSetYesNo &lt;br /&gt;msoButtonSetYesNoCancel&lt;br /&gt;&lt;/td&gt;&lt;td width="50%" align="left" valign="top"&gt;&lt;br /&gt;msoBalloonTypeButtons&lt;br /&gt;msoBalloonTypeBullets&lt;br /&gt;msoBalloonTypeNumbers&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;b&gt;Animation&lt;/b&gt; and &lt;b&gt;Icon&lt;/b&gt; properties are always set with one of the above values based on what we are trying to convey to the User. By default the &lt;b&gt;OK&lt;/b&gt; button will appear. If any other Button or Buttons Group is required then the &lt;b&gt;Button&lt;/b&gt; Property must be set with one of the above values. The &lt;b&gt;BalloonType&lt;/b&gt; is used with &lt;b&gt;Labels&lt;/b&gt; Property only. We will look into the &lt;b&gt;Labels&lt;/b&gt; property at the later part of this Article. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I am sure when you go through these simple straightforward examples you will be better informed about the usage of &lt;b&gt;Office Assistant&lt;/b&gt;, its methods and will start using them in your Applications. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I will reproduce the Code here with simple changes, which we have seen in last week’s Article, and go through it before we make changes in them for our new examples. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Sub MyMsgBox()&lt;br /&gt;Dim strMsg As String&lt;br /&gt;Dim strTitle As String&lt;br /&gt;&lt;br /&gt;strTitle = "Assistant Test"&lt;br /&gt;strMsg = "Wecome to MS-Access Tips and Tricks"&lt;br /&gt;&lt;br /&gt;With Assistant.NewBalloon&lt;br /&gt;    .Icon = msoIconAlertInfo&lt;br /&gt;    .Animation = msoAnimationGetAttentionMajor&lt;br /&gt;    .Heading = strTitle&lt;br /&gt;    .text = strMsg&lt;br /&gt;    .Show&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Press &lt;b&gt;Alt+F11&lt;/b&gt; to display the VBA Editing Window. Select &lt;b&gt;Module&lt;/b&gt; from &lt;b&gt;Insert&lt;/b&gt; Menu to create a new Standard VBA Module. Copy and Paste the above Code into the Module. Click somewhere in the middle of the Code and Press &lt;b&gt;F5&lt;/b&gt; to Run it. &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant01-701256.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 202px; height: 227px;" src="http://www.msaccesstips.com/uploaded_images/assistant01-701248.jpg" border="0" alt="Simple Example Image of MsgBox" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;In the above example the &lt;b&gt;.Show()&lt;/b&gt; method displays the Message Box after setting the other &lt;a href="http://www.msaccesstips.com/2009/02/forms-and-custom-properties.shtml"&gt;Property&lt;/a&gt; Values. The Text property value shows the body text of the Message Box and &lt;b&gt;Heading&lt;/b&gt; is the &lt;b&gt;Title&lt;/b&gt; Text in Bold letters. The &lt;a href="http://www.msaccesstips.com/2009/01/command-button-animation-2.shtml"&gt;Animation&lt;/a&gt; property can be set with one of the 35 different options given above.  The &lt;b&gt;Icon&lt;/b&gt; Property value we have changed to &lt;b&gt;Information&lt;/b&gt; type here. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we want to obtain the responses of the User to do different things then we need to bring in the &lt;a href="http://www.msaccesstips.com/2008/04/transparent-command-button.shtml"&gt;Button&lt;/a&gt; Property into the Code.  Let us say if the User needs to proceed with the report preparation process then she must click the &lt;b&gt;OK&lt;/b&gt; Button otherwise &lt;b&gt;Cancel&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/03/double-action-command-button.shtml"&gt;Button&lt;/a&gt;. To evaluate the response received from the User and to take action accordingly we must write code for that further down in the Routine. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let us see how we can do this with changes to the above Code. The modified program is given below: &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Sub MyMsgBox ()&lt;br /&gt;Dim strMsg As String&lt;br /&gt;Dim strTitle As String&lt;br /&gt;Dim R As Long&lt;br /&gt;&lt;br /&gt;Title = "Assistant Test"&lt;br /&gt;msgTxt = "Proceess Weekly Reports...?"&lt;br /&gt;&lt;br /&gt;With Assistant.NewBalloon&lt;br /&gt;   &lt;b&gt; .Icon = msoIconAlertQuery&lt;/b&gt;&lt;br /&gt;    .Animation = msoAnimationGetAttentionMajor&lt;br /&gt;   &lt;b&gt; .Button = msoButtonSetOkCancel&lt;/b&gt;&lt;br /&gt;    .Heading = strTitle&lt;br /&gt;    .text = strMsg&lt;br /&gt;  &lt;b&gt; R = .Show&lt;/b&gt;&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;If R = -1 Then 'User Clicked OK Button&lt;br /&gt;    DoCmd.RunMacro "ReportProcess"&lt;br /&gt;End If&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant02-764445.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 180px; height: 211px;" src="http://www.msaccesstips.com/uploaded_images/assistant02-764437.jpg" border="0" alt="Example Image with OK and Cancel Buttons" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;Compare the changes made in the new Code with the earlier one to find the difference. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If the User clicked the &lt;b&gt;OK&lt;/b&gt; &lt;a href="http://www.msaccesstips.com/2008/04/colorfull-command-buttons.shtml"&gt;Button&lt;/a&gt; (&lt;b&gt;-1&lt;/b&gt; is returned in Variable &lt;b&gt;R&lt;/b&gt;, &lt;b&gt;Cancel=-2&lt;/b&gt;) then the &lt;b&gt;ReportProcess&lt;/b&gt; Macro is run otherwise the Program ends doing nothing. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We can give different choices to the &lt;a href="http://www.msaccesstips.com/2006/11/create-msaccess-user-account.shtml"&gt;User&lt;/a&gt; in the form of a &lt;a href="http://www.msaccesstips.com/2007/07/custom-menus-and-tool-bars.shtml"&gt;Menu&lt;/a&gt; with the use of &lt;a href="http://www.msaccesstips.com/2008/10/textbox-and-label-inner-margins.shtml"&gt;Labels&lt;/a&gt; Property and perform the actions based on User’s response. See the example code given below: &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Sub Choices()&lt;br /&gt;Dim R As Long&lt;br /&gt;Dim bln As Balloon&lt;br /&gt;&lt;br /&gt;Set bln = Assistant.NewBalloon&lt;br /&gt;With bln&lt;br /&gt;    .Heading = "Report Options"&lt;br /&gt;    .Icon = msoIconAlertQuery&lt;br /&gt;    .Button = msoButtonSetNone&lt;br /&gt;  &lt;b&gt;  .labels(1).text = "Print Preview."&lt;br /&gt;    .labels(2).text = "Print."&lt;br /&gt;    .labels(3).text = "Pivot Chart."&lt;br /&gt;    .BalloonType = msoBalloonTypeButtons&lt;/b&gt;&lt;br /&gt;    .text = "Select one of " _&lt;br /&gt;       &amp; .labels.Count &amp; " Choices?"&lt;br /&gt;    R = .Show&lt;br /&gt;End With&lt;br /&gt;&lt;br /&gt;Select Case R&lt;br /&gt;    Case 1&lt;br /&gt;        DoCmd.OpenReport "MyReport", acViewPreview&lt;br /&gt;    Case 2&lt;br /&gt;        DoCmd.OpenReport "MyReport", acViewNormal&lt;br /&gt;    Case 3&lt;br /&gt;        DoCmd.OpenReport "MyReport", acViewPivotChart&lt;br /&gt;End Select&lt;br /&gt;&lt;br /&gt;End Sub &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note: &lt;/b&gt; You may copy and paste the Code into the VBA Module and modify it with appropriate changes before attempting to Run it. &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant03-726163.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 124px; height: 280px;" src="http://www.msaccesstips.com/uploaded_images/assistant03-726155.jpg" border="0" alt="MsgBox Image with Options" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;The dimension of the &lt;b&gt;Labels()&lt;/b&gt; Property Value can be up to a maximum of 5 only. The &lt;b&gt;BalloonType&lt;/b&gt; Value &lt;b&gt;msoBalloonTypeButtons&lt;/b&gt; allows the User to click on one of the Options to select it and the Index value of the item clicked is returned in Variable &lt;b&gt;R&lt;/b&gt;.  We have set the Value &lt;b&gt;Button = msoButtonSetNone&lt;/b&gt; to remove the &lt;b&gt;OK&lt;/b&gt; Button from appearing so that the User will click only on one of the Options displayed. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There are two more &lt;b&gt;BalloonType&lt;/b&gt; Property values available: &lt;b&gt;msoBalloonTypeBullets&lt;/b&gt; and &lt;b&gt;msoBalloonTypeNumbers&lt;/b&gt;.  These are not selectable, like &lt;b&gt;msoBalloonTypeButtons&lt;/b&gt;, and used only for displaying information. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Compare the following Code with the earlier one to see the difference in changed Property Values. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Public Sub InfoDisplay()&lt;br /&gt;Dim bln As Balloon&lt;br /&gt;&lt;br /&gt;Set bln = Assistant.NewBalloon&lt;br /&gt;With bln&lt;br /&gt;    .Heading = "Reminder"&lt;br /&gt;    .Icon = msoIconAlertInfo&lt;br /&gt;    .labels(1).text = "MIS Reports."&lt;br /&gt;    .labels(2).text = "Trial Balance."&lt;br /&gt;    .labels(3).text = "Balance Sheet."&lt;br /&gt;    .BalloonType = msoBalloonTypeBullets&lt;br /&gt;    .text = "Monthly Reports for User Departments"&lt;br /&gt;    .Button = msoButtonSetOK&lt;br /&gt;    .Show&lt;br /&gt;End With&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Sample Images with &lt;b&gt;BalloonType&lt;/b&gt; Property Changes are given below: &lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.msaccesstips.com/uploaded_images/assistant04-720797.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 291px; height: 320px;" src="http://www.msaccesstips.com/uploaded_images/assistant04-720779.jpg" border="0" alt="MsgBox with Bullets and Numbers" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/center&gt;&lt;br /&gt;We will continue this discussion next week to see more ways to use the Office Assistant with &lt;b&gt;Labels&lt;/b&gt; and &lt;b&gt;CheckBoxes&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div align="right"&gt;&lt;br /&gt;&lt;a href="http://www.stumbleupon.com/submit?url=http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml&lt;br /&gt;&amp;amp;title=Office+Assistant+and+MsgBox+Menus"&gt;&lt;br /&gt;&lt;img border=0 src="http://www.msaccesstips.com/images/stumbleupon.gif" alt="StumbleUpon Toolbar"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;hr&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/06/network-and-report-page-setup.shtml"&gt;Network and Report Page Setup&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/filter-by-character-and-sort.shtml"&gt;Filter by Character and Sort&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/animating-label-on-search-success.shtml"&gt;Animating Label on Search Success&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/04/form-background-with-gradient-color.shtml"&gt;Form Background with Gradient Color&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.msaccesstips.com/2009/03/ms-access-and-reference-library.shtml"&gt;MS-Access and Reference Library&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-2376623373770548";
/* acc468x60footer, created 2/9/09 */
google_ad_slot = "4299616543";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/34083602-8091813746059922363?l=www.msaccesstips.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.msaccesstips.com/2009/08/office-assistant-and-msgbox-menus.shtml</link><author>noreply@blogger.com (a.p.r. pillai)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item></channel></rss>