|
Form Bookmarks and Data Editing Posted: 25 Oct 2009 10:31 AM PDT You want to edit information on 25 records on the Form 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 Find (Ctrl+F) 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't have any other choice to find and edit the information. 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. Going through the same procedure to find all those 25 records again by displaying the Find 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. 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. 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. We will develop a trick with the Form's Bookmarks to make this kind of work easier for our Application Users. FORM BOOKMARKS When you open a Form attached to a Table, Query or SQL Statement each record on the Form is marked by MS-Access with a unique identifying tag known as Bookmark (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. We can read the Bookmark of any record from the Form's Bookmark Property, when the Record is Current 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. I have created a Function with the name myBookMarks() for this purpose and you can implement this method on any Form that has a Recordset attached to it by creating a Combo Box and a Command Button and four lines of Code in the VBA Code Module of the Form to run the Function. 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. SAMPLE PROJECT
NB: We are not using the second table directly, but the Order Details table references the Products Table for Product Description. A sample image of a Tabular Form in Design View is given below. ![]()
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. ![]() The selected OrderId 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 Find method with the OrderID Value to find the record. If OrderID was used then it will stop at the first record with the same OrderID numbers, not on the same record you have visited earlier. You may try out other items appearing in the list for now. You may implement this method on Forms with Column Format too. ![]() Here, I would like to remind you that we are saving the List of Bookmarks in the BookMarkList Array in myBookMarks() 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. Check the following declarations of the Function in the Global area of the Module: Public Const ArrayRange As Integer = 25 Dim bookmarklist(1 To ArrayRange) As String, ArrayIndex As Integer You can change the Value 25 to a higher or lower desired value according to your specific needs. Let us continue by adding few more distant record bookmarks into the existing list. Isn't it very easy to revisit all those records a second time? The OrderID Field Value added to the Combo Box along with the Index Number of the Bookmark Array can be used to cross check with the retrieved record value to ensure correctness. Let us look the Sub-Routines we have copied into the Form Module and check what they are doing. Private Sub Form_DblClick(Cancel As Integer) myBookMarks 1, "cboBMList", Me![OrderID] End Sub When you double-click on the Record Selector of a record the above Sub-Routine calls the main Function myBookmarks() with the following parameters: Action Code : 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 ArrayIndex. The Action Code is tested in the Select Case….End Select segment in the myBookMarks() Function. The Bookmark value itself is not displayed anywhere. Combo Box Name : "cboBMList" – 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. Record Field Value : 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. The third parameter of myBookMarks() Function is defined as Optional and is omitted while calling the Functions to retrieve the Bookmark or to erase the Bookmarks List in the following three Sub-Routines respectively: Private Sub cboBMList_Click() myBookMarks 2, "cboBMList" End Sub Private Sub cmdReset_Click() myBookMarks 3, "cboBMList" End Sub 'Erases the Bookmarks when the Form is closed Private Sub Form_Unload(Cancel As Integer) 'Remove all Bookmarks from Memory myBookMarks 3, "cboBMList" End Sub Since, the main Function myBookMarks() references the Active Form you can implement this method on any Form without directly passing any Form Name to the Function. NB:
Detail and Summary from Same Report Hiding Report Lines Conditionally-3 Hiding Report Lines Conditionally-2 Hiding Report Lines Conditionally Network and Report Page Setup-3 |
You are subscribed to email updates from LEARN MS-ACCESS TIPS AND TRICKS To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.