?
Solved

Show selected values in List box  VBA - ACCESS

Posted on 2012-04-02
5
Medium Priority
?
468 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

777 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