Solved

Show selected values in List box  VBA - ACCESS

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

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Great ! Its working fine, Thank You so much  capricorn1,
George
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now