User-Selected List of Fields to Display on a Form
In this class we're going to work with custom list box columns. We're going to build a form based on any table. We'll start with a customer table, but you can switch it to any table or query that you want. You'll be able to specify which fields you want to make available to the user in the table/query field properties. Then the user can select which fields they want to see on the form at runtime. We'll work more with recordsets, multi-select list boxes, and learn some new stuff including querydefs.
In Lesson 1, we're going to build a form with custom list box columns, in other words we'll have our customers in a list box on the left, and a list of fields on the right. Based on what the user selects in those check boxes, that will determine which fields are displayed in the list box.
In Lesson 2, we're continuing to work with the custom list box columns form. We're going to replace those check boxes with a multi-select list box. Now we've done multi-select list boxes before in Developer 15. We're going to review them a little bit here and we're going to see how this is much easier to maintain the long run, and it looks better. It's a more elegant solution than a whole bunch of check boxes.
In Lesson 3, we're going to start moving away from having all of the fields listed in our VB code. It's a lot harder to maintain and upgrade. Instead, I want to store that information in the table itself in the table properties. So we're going to learn how to use the tabledefs collection the, fields collection, the field properties collection. We're going to loop through all the fields in a table and then we're going to load the field list based on the properties we're going to set in the table, which will determine the fields that we want to have listed, their widths, whether they're selected when the form loads, and lots more.
In Lesson 4, we're going to replace our requery list with generic code. In other words, it's going to ignore the field list completely and as long as you've got that table property set up it will work with any field in the table. Then we'll see how to resize the form so that if you want to make it wider or taller it'll resize the list widths accordingly and it'll move our little field list over to the right as well.
In Lesson 5, we're going to make some custom labels to go across the top of each of the columns so we can see what the column has in it. We'll make a bunch of blank labels and then using our code we'll position them properly on the screen. We'll do some inches to twips conversion. We'll set the width of the label and its other properties based on the data in our list box already. We know how wide each column is so that can tell us where to place each label.
In Lesson 6, we're still working with the custom list box form. We're going to see how we can prevent those labels from going too far to the right and we'll deal with a quirk with the horizontal scroll bar that pops up. Then we're going to see how we can change the table that's in the form so we can pick the customer table or the order table and have the data in here change based on which table we pick.
In Lesson 7, we're going to wrap up by learning something new: querydefs. We haven't done querydefs yet in any of our Developer classes (I just checked). We're going to add queries to the form. Now querydefs are very similar to tabledefs which we've done but you got to handle them a little bit differently. Then we're going to deal with missing that ID field. If the user doesn't put an ID field in their table or query then we have to be able to process that differently and disable the doubleclick event.
Enroll now so that you watch these lessons, learn with us, post questions, and more!
Please feel free to post your questions or comments below. Thanks.
microsoft access, ms access, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #instruction, #learn, #lesson, #training, #database, user defined List Box Columns, Specify Columns, User Editable, Multiple Columns, Populating a MultiColumn ListBox, column widths, multi-select list box, read settings from table, Display only Selected Fields, tabledefs, querydefs, inches to twips
You may want to read these articles from the 599CD News: