|
The List Boxes in Access 97 have property that allows you to select multiple items in the list box. You will find this property under the Others tag and it is called Multi Select. But if you want to use it, you will now have to write vb that loops through a collection rather than simple pointing to the list box itself. The Access 97 help examples are shown The following example prints the value of the bound column for each selected row in a Names list box on a Contacts form. To try this example, create the list box and set its BoundColumn property as desired and its MultiSelect property to Simple or Extended. Switch to Form view, select several rows in the listbox, and run the following code:Sub BoundData() Dim frm As Form, ctl As Control Dim varItm As Variant Set frm = Forms!Contacts Set ctl = frm!Names For Each varItm In ctl.ItemsSelected Debug.Print ctl.ItemData(varItm) Next varItm End Sub The next example uses the same list box control, but prints the values of each column for each selected row in the list box, instead of only the values in the bound column. Sub AllSelectedData() Dim frm As Form, ctl As Control Dim varItm As Variant, intI As Integer Set frm = Forms!Contacts Set ctl = frm!Names For Each varItm In ctl.ItemsSelected For intI = 0 To ctl.ColumnCount - 1 Debug.Print ctl.Column(intI, varItm) Next intI Debug.Print Next varItm End Sub The code that I wrote for a wizard that I am building in Graf-FX is as follows. This example uses information from 2 columns in a list box. On Error GoTo hide_unhide_exitDim frm As Form, ctl As Control Dim varItm As Variant DoCmd.SetWarnings False Set frm = Me Set ctl = frm!cboTables For Each varItm In ctl.ItemsSelected DoCmd.RunSQL "Delete from z_systables where tabname = '" & ctl.ItemData(varItm) & "'" DoCmd.RunSQL "insert into z_systables (tabName, tabType, tabIgnore ) SELECT '" & ctl.ItemData(varItm) & "','" & ctl.Column(1, varItm) & "' ," & hideFlag & ";" Next varItm hide_unhide_exit: DoCmd.SetWarnings True Try out our popular Access shareware Graf-FX @ http://www.vb123.com/graf/
|
|
Links >>> Home | Search | Workbench | Orders | Newsletter | Access Security | Access professionals |