Solved

Show selected values in List box  VBA - ACCESS

Posted on 2012-04-02
5
463 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

730 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