If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Got record using a value from a list box
I'm currently designing a contacts database. I want to be
able to select a contact from a list box and have the correct information appear. Each contact has a Contact ID (primary key), but the value in the list box is the contact name. How do I get the database to search for the value and retrieve the correct record? Code for this would be very helpful. |
#2
|
|||
|
|||
Got record using a value from a list box
Mr Paul, If you are using a bound form, which in your example would be bound
to a table/query based on your Contacts table, then all you have to do is add a combobox to your form and follow the wizard that launches when you place it on the form. The 3rd option on the initial window states "Find a record on my form based on the value I select in my combo box. Finish through the wizard and your set. If the wizard isn't launching when you place the combobox on your form make sure the little wand with the stars button located in the toolbox toolbar is selected before placing the control on your form. Hope this helps If you have a combo on your form basically what you need to do is double-click the combo while in design view to bring up the properties window. Click the All tab and set the following: Row Source Type: Table/Query Row Source: Name of the query that has your PrimaryKey and the Name field added to the control grid. Column Count: 2 Column Widths: 0";1" (this will hide the PK field so that only the name is displayed) Bound Column: 1 Limit to List: Yes (Probably) Now click the event tab of the properties window. Click the ellipsis next to the After Update event. This will open the code window. Type in something like this replacing the names here with the names of your controls/fields. Private Sub myCombo_AfterUpdate() ' Find the record that matches the control. Dim rs As Object Set rs = Me.Recordset.Clone rs.FindFirst "[ID] = " & str(Me![myCombo]) Me.Bookmark = rs.Bookmark End Sub Hope this helps! -- Reggie ---------- "MrPAUL" wrote in message ... I'm currently designing a contacts database. I want to be able to select a contact from a list box and have the correct information appear. Each contact has a Contact ID (primary key), but the value in the list box is the contact name. How do I get the database to search for the value and retrieve the correct record? Code for this would be very helpful. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
synchronizing form and list box | Deb Smith | Using Forms | 8 | June 21st, 2004 08:15 PM |
Select record from a list | Andrea | Using Forms | 2 | June 15th, 2004 11:25 PM |
Add/delete record from list box | will | New Users | 2 | May 19th, 2004 06:41 PM |
Form Does Not Go To New Record | Steve | New Users | 1 | May 12th, 2004 03:15 AM |
Use dropdown list to display more than one record from a table | Cheryl | Worksheet Functions | 6 | May 6th, 2004 02:08 PM |