This thread will be a multi-part thread showing some common database methods which are easy to implement into your design.
As, I go on in this thread, this database will become more and more diverse, all-the-while, I will be implementing simple methods to make the database easier to use, and giving it an asthetically pleasing appearance. In the beginning, I will be concentrating on function; I will also be cleaning up the appearance little by little with each post.
Part I - Your first VBA function (Requery)
I see requests for this all the time:etc. etc.When I choose a name in a combobox, I want the rest of the fields to update with it.
How do I pull up records with a combobox?
Well, if you're new to Access, this may seem like a danting task, but in reality, this is very, very simple.
In this segment, I will show you how to accomplish this. This procedure has only one line of vba code, and it will also show you how to run your query from a form control.
We're going to start with your basic demographic table:
You will notice a thumbnail below, it is the design view of the query and form with labels 1 - 4.Code:Table1 IDnumber - Text - Primary Key FirstName - Text LastName - Text Addr1 - Text Addr2 - Text City - Text State - Text Zip - Text
1. This is the form name (form1)
2. This is the combo box name (cboIDnum)
3. This is the builder for the after update of the combobox (cboIDnum)
3a. You will want to choose code builder when you click the 3 dots.
3b. A new window will open up. This is the VBA editor. Simply type ME.REQUERY then close this window, then save the form.
4. This is your query for the form, notice the criteria from the combobox from the form (forms!form1.cboIDnum)
The SQL view of the query would be this:In the VBA, I did a "me.requery". A simple definition is this..... the me part states that in this form (me), you want to requery (or reload - in this case with the criteria of the combobox)Code:SELECT Table1.IDnumber, Table1.FirstName, Table1.LastName, Table1.Addr1, Table1.Addr2, Table1.City, Table1.State, Table1.Zip FROM Table1 WHERE (((Table1.IDnumber)=[forms]![form1].[cboIDnum]));
That's all there is to it!
The sample database is below the thumbnail.



LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks