473,480 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Populating a List Box

1 New Member
Hi all,

I am trying to populate a list box ona form with data in a table. I am new to Access VBA and am not able to do it. Following is the snapshot of my code. Could somebody please look into it tell me where am I going wrong and wht shld I change. Any help would be sincerely appreciated.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim strSQL As String
  3.     Dim strcustomername As String
  4.     Dim rstLoans As DAO.Recordset
  5.     Dim dbase As DAO.Database
  6.  
  7.  'strcustomername = txtorderno.Value
  8.     Set rstLoans = dbase.OpenRecordset("MASTERRECORD")
  9.      'Set rstLoans = dbase.OpenRecordset("MASTERRECORD", dbOpenCDO)
  10.     SecuritiesList.RowSource = ""
  11.  
  12. 'strSQL = "SELECTtblorder.orderno,tblorder.ProductID1,tblorde  r. [Clothingtype1]"
  13. 'strSQL = strSQL & "FROM tblorder;"
  14.  
  15. strSQL = "SELECT * FROM [MASTERRECORD]"
  16.  
  17.     Me.SecuritiesList.RowSource = strSQL
  18. End Sub
Thanks
RB
Aug 13 '08 #1
1 1394
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. There is no need at all to define recordsets if you want to set the recordsource of a listbox in code. The only statement that matters is the one setting your rowsource - none of the recordsource or database lines have any relevance to this at all and can be removed with no penalty. Doing so on the code you provided and removing the commented out lines leaves just:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim strSQL As String
  3.     strSQL = "SELECT * FROM [MASTERRECORD]"    
  4.     Me.SecuritiesList.RowSource = strSQL
  5. End Sub
As it is just one very simple select statement this should provide to the listbox all fields from your masterrecord table in the order they are defined for that table, if this is indeed what you want to show in your listbox. However, what your listbox shows to users depends on the number of columns you have defined for that listbox, and their widths. You will need to check what you have specified for that listbox to make sure you will actually see the list of fields concerned. You won't see much if you have defined just 1 column of width 0...

If you make further changes to the recordsource of a control you may need to include a requery call to effect those changes after setting the rowsource property.

Expand|Select|Wrap|Line Numbers
  1. Me.SecuritiesList.Requery
-Stewart
Aug 13 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2561
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is...
0
1436
by: gerry | last post by:
I want to populating an asp list box from a simple access lookup list (single column not a table.)I don't want to create tables just for lookups as the values will be descriptive only and will...
1
2455
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
6
1547
by: P K | last post by:
I have a listbox which I am populating on the client (it contains a list of dates selected from calender). The listbox is a server control. When I get to the server after postback by selecting an...
4
8052
by: Pete Lux | last post by:
I have a drop down that populates on page load. The drop down brings in customer numbers from my local MSDE database. It does this fine, but I click a button that finds quotes for those customers...
0
3658
by: Paul Hadfield | last post by:
I'm looking for thoughts on the "correct" design for this problem (DotNet 2.0 - in winforms, but that's not so important). I've got two combo boxes (combo1 and combo2), both are populating via...
0
1671
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
2
3936
by: Johnny BeGood | last post by:
Hi All, I need to populate a list box and/or a dropdown list on a form. I have all the bits and pieces together, all bar the code which takes the result of a query and creates a list box. Any...
2
3256
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
8
13328
by: Mantorok | last post by:
Hi all I'm populating a DataTable with around 1,500,000 rows, the table contains 4 columns, 3 string columns and a decimal column. However, I keep getting OutOfMemory exceptions when my app...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.