Read List Box selection

I have an application I am converting from VisualBasic. In the visual basic progam, the user would view the clients in a window. He then could ciick on a ‘grid’ command button that opens a new form with a datagrid showing all the customers of the company. When the user clicks on a customer and closes the grid form it passes that record back to the form that shows only one customer for the user to edit.

I can display all the customers in the list box, but how do I capture the item selection (one of the columns is an account number), and pass it back to the first window?

Create a method in the grid window (e.g. “ShowGrid”) and set the return type to the datatype you want to capture. Also add a property to the window of the same type.

Function ShowGrid() As Integer Me.ShowModal ' show the window and wait Return Me.AccountNumber ' the value you want to capture End Function

Note that you need to save the value to the property before the window closes: you can’t read from the listbox/grid after ShowModal returns since the controls will already have been destroyed.

e.g. something like this in the CancelClose event:

Function CancelClose(appQuitting As Boolean) As Boolean Me.AccountNumber = Listbox1.Cell(Listbox1.ListIndex, 1) End Function

Thank you, Andrew, I am now able to get the data from the list box, saved to a variable.

Now, one more question. I want to pass that data back to the orginanal window and change its data controls sqlquery property, then refresh the windows.

I have tried the following code:

AccountNumber = Listbox1.Cell(Listbox1.ListIndex, 0)

but I receive a syntax error on the second line. I have searched the forums, but do not find an example that is applicable… any ideas?

Remove the comma after the end quote in your query string.

That removes the syntax error… now when I go back to the orginal window, it locks up if I click on any controls. How do I send an update to the data control on the orginal window?