473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

populate list box..

Hi,
I have 2 list boxes on my form...
I need to populate the second list box based on the value selected on the first one...
i have some sample code..

Expand|Select|Wrap|Line Numbers
  1. Private Sub List4_AfterUpdate()
  2. Dim strTable As String
  3.     strTable = Me.Ins
  4.     Me.List4.RowSourceType = "Table/Query"
  5.     Me.List4.RowSource = "SELECT DISTINCT [Portfolio Management].[Delivery Dept] FROM [Portfolio Management] _ 
  6. WHERE [Portfolio Management].[Delivery Institution])= '&strTable';"
  7.     Me.List4.Requery
  8. End Sub
..but i am not getting any data in my second list box...
I am new to access..please let me know where i m going wrong?or suggest some better ideas..??

Thanks
Vani
Feb 21 '11 #1
5 1753
Stewart Ross
2,545 Expert Mod 2GB
You need to split the WHERE part of the string in line 6 so that you are including the value of strTable in the where clause, which you are not doing at present:

Expand|Select|Wrap|Line Numbers
  1. "SELECT ... WHERE [Portfolio Management].[Delivery Institution] = '"& strTable & "';"
The three dots '...' just means include the other parts of your SELECT statement as before (the DISTINCT keyword followed by your field names).

-Stewart
Feb 21 '11 #2
Dear Stewart,

Thanks for the reply...but i tried using your syntax...
but i am still not getting my second list box populated when i select my first one..

I am writing this code in the after update event of the second list box..

Please let know where i am going wrong..
I tried the code in the after update event of first list box also..

nothing helped..

Thanks
Feb 22 '11 #3
Stewart Ross
2,545 Expert Mod 2GB
We have an Insights article on cascading combo/listboxes which explains in much more detail than I can do here how to set up the code concerned.

Please be clear that in my post above I simply corrected an obvious error in your original code; without further information on how what your SQL statement actually contains when your code is run, and the context in which you are running it, I can't comment on what might be wrong with your current interpretation of cascading listboxes.

-Stewart
Feb 22 '11 #4
I have done exactly what was described in the article u sent...infact i tried this concept seeing tht article only..

I am also able to print the recordsource with the value i passed..

SELECT DISTINCT [Portfolio Management].[Delivery Dept] FROM [Portfolio Management]WHERE [Portfolio Management].[Delivery Institution])='HSC';

but still i m not getting the list box populated..


my code:


Private Sub Ins_AfterUpdate()
Dim strTable As String
strTable = Me.Ins
Me.Dept.RowSourceType = "Table/Query"
Me.Dept.RowSource = "SELECT DISTINCT [Portfolio Management].[Delivery Dept] FROM [Portfolio Management]WHERE [Portfolio Management].[Delivery Institution])='" & strTable & "';"
Me.Dept.Requery
Debug.Print Me.Dept.RowSource

End Sub
Feb 22 '11 #5
Dear Stewart,

I got the issue resolved finally...I need to now see how to pass multiple values selected in list box to the query to get the results...Please let me know if u have idea on this..

Thanks
vani
Feb 22 '11 #6

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

Similar topics

1
by: Adrian | last post by:
Hi I kind of new here, but how do i get a value from a combo box and populate a list box base on the selected value from a combo box? If possible can i get a sample coding Thank you. regards...
3
by: MS | last post by:
I would like to be able to examine a folder, and populate a List Box or Combo Box with the files that are in it. How would you go about doing this? The reason is that I would like the user to...
2
by: James McGivney | last post by:
In a C# program I have an SQL database. A data adapter is connected to the database and a dataset has been generated. I would like to populate a listBox (or comboBox) from the dataset such that...
0
by: yousuf | last post by:
I have a dataList that pulls from a database table - Im trying to do the normal Edit, Update, Delete, Cancel - on it. when I put the following inside a user control - .ascx file it dosn't work,...
0
by: parag100 | last post by:
hello how to populist list item thriogh sql query in forms 6i. see there is a form .on that one list item,stud_list . i have sat it combo box. but how to populate it by query.
2
by: Jacko7289 | last post by:
Good Day, My form has two combo boxes where the list of second combo box is dependent on the data chosen from the first combo box. This is how the table (source of data) looks like... Table 1:...
1
by: DanWeaver | last post by:
I have several lists each of several hundred selectable items. I send all lists to the client along with the javascript. When the user types the first letter of the item in a text box, I know which...
2
balabaster
by: balabaster | last post by:
Am I going crazy? I'm sure I recall seeing a method of instantiating a list and populating it using some method akin to: Dim myList As List(Of Integer) {0, 4, 9, 10, 50} It appears not to be...
2
by: RhysPhelps | last post by:
hi guys and girls, What i have is a list of account codes, and a list of cost centres. Each combination of these (so for example "5030" and "Externals") will have it's own budget reference...
5
by: Kaosman | last post by:
I have been trying to figure out this problem for a while. All I want to do is have a combo box populate a list box and the list box change to the record based on the users choice. The combo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...

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.