Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List box

Status
Not open for further replies.

sarath77

Programmer
Apr 21, 2002
4
0
0
DE
Hello

I have a text box to enter some text and then by clicking a button, i'm saving my data into a table.Now, i want to display the text in a list box after clicking the button.How should i implement this?could somebody please give me the code.

Thank you
 
The easiest way to manipulate listbox content I have found is SQL statements.

Create a query from the table to collect the data you want in your list box. Once this is displaying what you want you can go to SQL view and copy the SQL. Close the query and save it if you want.

Open a new form in design view and select the listbox size it to what you want and open the properties window. to the Row Source property and click on the ... This will take you to a query design grid, go to the SQL view and paste your code in there. Go back to dataview and check your query is still selecting the records you want.

Close out and check your column count, and column width statements, you may need to modify these.

Open the form in form view and it should show your list box. (if a column is too narrow or wide or missing, refer above)

To open this from your save button, just go into code and type DoCmd.OpenForm MyForm, after the save event is complete.

 
I have a suggestion. You can put the listBox as dynamictiger described on the form that contains the button and not on the separate form. It'll save you from opening and closing this additional form each time. All you have to do is in the end of the code which inserts new data from the textBox add:
listBox_name.Requery
It'll refresh the list and show the new value that was just added.
 
Let's pretend that the name of your listbox is [CustomerName]. After placing your new text into your table, use the .setfocus along with the "On Focus" event to refresh the values in the listbox. the following code should work for you:

For the after update event of your textbox write the following VB code:
[CustomerName].setfocus
For the "On Got Focus" event place the following code:
Me![CustomerName].Requery

this sequence should refresh the information in your listbox after you have placed a new value into your table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top