Solved

Show selected values in List box  VBA - ACCESS

Posted on 2012-04-02
5
465 Views
Last Modified: 2012-06-22
I like to show some items (like For n = 0 to 10) as selected in a list box using vba code,
but below code working only for the final value of 'n' ,
Can you please help me? In my list box there is three columns in a row.

 Me.List_SLCInsert.Selected(n) = True

I can load the values in list box (its property is set as extended), but selection is not working..

Thanks in Advance

George
0
Comment
Question by:gtmathewDallas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37800552
try this

dim n
With Me.List_SLCInsert
      for n=0 to 10
              .selected(n)=true

      next

End with

Set the Multi Select property of the Listbox to Simple
0
 

Author Comment

by:gtmathewDallas
ID: 37801407
Its giving the same result as before,

The loop is working fine and the elements are adding to the list box properly, but canot show the values as selected there.

Here is the code,



slcnt = UBound(flds)
                           
                            With Me.List_SLCInsert

                            For n = 0 To slcnt - 1
                                    'To load the assigned values in list box
                                    '=======================================
                                     Dim rst As DAO.Recordset
                                     Set rst = CurrentDb.OpenRecordset("SELECT * FROM SUB_LEDGER where Sl_Id = CInt('" & (flds(n)) & "') ")
                                     Me.List_SLCInsert.AddItem "'" & rst!Sl_Id & "';'" & rst!Sl_Number & "';'" & rst!Account_Number & "';'" & rst!Title & "'"
                                     'Me.List_SLCInsert.Selected(l) = True
                                     .Selected(n) = True
                                    '===========
                              Next n
                              End With



Thanks,
George
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 37801598
gtmathewDallas,

add all the items to the listbox from your recordset, after that, use the codes

                                     Dim rst As DAO.Recordset
                                     Set rst = CurrentDb.OpenRecordset("SELECT * FROM SUB_LEDGER where Sl_Id = CInt('" & (flds(n)) & "') ")
                                     Me.List_SLCInsert.AddItem "'" & rst!Sl_Id & "';'" & rst!Sl_Number & "';'" & rst!Account_Number & "';'" & rst!Title & "'"


slcnt = UBound(flds)
                           
                            With Me.List_SLCInsert

                            For n = 0 To slcnt - 1

                                 .Selected(n) = True
                                    '===========
                              Next n
                              End With
0
 

Author Comment

by:gtmathewDallas
ID: 37801743
Great ! Its working fine, Thank You so much  capricorn1,
George
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question