vb123.com

Garry Robinson's Popular MS Access, Office and VB Resource Site

 

Home  Contact Us
Order our Software

RSS & Newsletter  
Join our XML/RSS Newsfeed or sign up for our informative newsletter on Office Automation, Access and VB topics
Read More

Get Good Help
If you need help with a database, our Professionals could be the answer
Read More

  Is Your Database Corrupt ?
If you have a corrupt database, Try our Access Recovery service

The Workbench  Find out who has your database open, start the correct version of Access, easy compacting and backups, change startup options, mde compile,  shutdown database Read and Download

The Toolshed 
Searchable help file comprising of all the information at vb123.com plus hidden downloads etc. Read More



The Toolbox

Libraries of software that we regularly import into our projects. Enhances the Toolshed More..


DryToast New
Backup and query your BaseCamp
® projects
Read More


Datamining/Graphs

Explore your data with this versatile graphing and data mining shareware tool. 
Read More

Garry's Blog
Find out a few other things that Garry has been writing about Microsoft Access. Read more

About The Editor Garry Robinson writes for a number of popular computer magazines, is now a book author and has worked on 100+ Access databases. He is based in Sydney, Australia
Contact Us ...

Search ...

or try our Aussie
 vb123.com.au
  mirror site

 

Next Tip    Using The Multi Selection Option In Access List Boxes

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_exit
Dim 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.gr-fx.com/graf-fx.htm

 

Links >>>  Home | Search | Workbench | Orders | Newsletter | Access Security | Access professionals