Solved

Show selected values in List box  VBA - ACCESS

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

839 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