473,770 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Switch RowSource Query for Listbox Options

14 New Member
I have been fighting with this for a while, and I know someone on this board will be able to figure it out in a split second :)

I have a List Box and a Combo Box. Based on the selection the user makes in the Combo Box, I need for the Rowsource in the List Box to be changed to one of two queries, and requeried so the user can select an option from the List Box based on the newly selected criteria from the Combo Box.

I thought it would be fairly simple, but its not working, and im not exactly sure what I am doing wrong :(

Here is the code that I have messing aound with (AppPosition being the Combo Box and ClassSelectLIST being the List Box):

Expand|Select|Wrap|Line Numbers
  1. Private Sub AppPosition_Change()
  2.  
  3. 'CHANGE THE ROWSOURCE QUERY IN THE ClassSelectLIST LIST BOX
  4. 'THEN REQUERY
  5. If Me.Controls!AppPosition = "Trainer" Then
  6. Me!ClassSelectLIST.RowSource = (qry_FindAvailableSlotsTRA)
  7. Else
  8. Me!ClassSelectLIST.RowSource = (qry_FindAvailableSlotsINS)
  9. End If
  10. Me!ClassSelectLIST.Requery
  11. End Sub
Thanks guys, and if any details are unclear as to what I am trying to do please let me know!
Aug 10 '07 #1
7 15031
ADezii
8,834 Recognized Expert Expert
I have been fighting with this for a while, and I know someone on this board will be able to figure it out in a split second :)

I have a List Box and a Combo Box. Based on the selection the user makes in the Combo Box, I need for the Rowsource in the List Box to be changed to one of two queries, and requeried so the user can select an option from the List Box based on the newly selected criteria from the Combo Box.

I thought it would be fairly simple, but its not working, and im not exactly sure what I am doing wrong :(

Here is the code that I have messing aound with (AppPosition being the Combo Box and ClassSelectLIST being the List Box):

Expand|Select|Wrap|Line Numbers
  1. Private Sub AppPosition_Change()
  2.  
  3. 'CHANGE THE ROWSOURCE QUERY IN THE ClassSelectLIST LIST BOX
  4. 'THEN REQUERY
  5. If Me.Controls!AppPosition = "Trainer" Then
  6. Me!ClassSelectLIST.RowSource = (qry_FindAvailableSlotsTRA)
  7. Else
  8. Me!ClassSelectLIST.RowSource = (qry_FindAvailableSlotsINS)
  9. End If
  10. Me!ClassSelectLIST.Requery
  11. End Sub
Thanks guys, and if any details are unclear as to what I am trying to do please let me know!
Place the following code in the AfterUpdate() Event of AppPosition:
Expand|Select|Wrap|Line Numbers
  1. Private Sub AppPosition_AfterUpdate()
  2. If Me![AppPosition] = "Trainer" Then
  3.   Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsTRA"
  4. Else
  5.   Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsINS"
  6. End If
  7. End Sub
Aug 10 '07 #2
Scott Price
1,384 Recognized Expert Top Contributor
This is some copied code from M$ help file on RowSource. Looks like your syntax is the only thing holding you up:

Expand|Select|Wrap|Line Numbers
  1. Forms!Employees!cmboNames.RowSourceType = "Table/Query"
  2. Forms!Employees!cmboNames.RowSource = "EmployeeList"
Change the () to "" and if needed enclose the query name in [] (generally needed only when the query/table/form/control name referred to includes spaces.)

Regards,
Scott
Aug 10 '07 #3
Scott Price
1,384 Recognized Expert Top Contributor
Place the following code in the AfterUpdate() Event of AppPosition:
Expand|Select|Wrap|Line Numbers
  1. Private Sub AppPosition_AfterUpdate()
  2. If Me![AppPosition] = "Trainer" Then
  3.   Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsTRA"
  4. Else
  5.   Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsINS"
  6. End If
  7. End Sub

Sorry ADezii! Didn't realize you were on this one too! Must have posted at the same time.

Regards,
Scott
Aug 10 '07 #4
ADezii
8,834 Recognized Expert Expert
Sorry ADezii! Didn't realize you were on this one too! Must have posted at the same time.

Regards,
Scott
Never a problem, Scott. Two heads are better than one, especially when one of them is mine!
Aug 11 '07 #5
bluray
14 New Member
you guys are great! ill give it a try right now
Aug 13 '07 #6
bluray
14 New Member
ok guys, works perfectly. I actually had to use advice from both your posts and this is the result:

Expand|Select|Wrap|Line Numbers
  1. ' #############################################################
  2. 'CHANGE THE ROWSOURCE QUERY IN THE ClassSelectLIST LIST BOX 
  3. ' THEN REQUERY
  4. Private Sub AppPosition_AfterUpdate()
  5.  
  6. If Me![AppPosition] = "Installer" Then
  7.     Forms![frm_VEH4a]!ClassSelectLIST.RowSourceType = "Table/Query"
  8.     Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsINS"
  9.     Me!ClassSelectLIST.Requery
  10.   Else
  11.       Forms![frm_VEH4a]!ClassSelectLIST.RowSourceType = "Table/Query"
  12.       Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsTRA"
  13.       Me!ClassSelectLIST.Requery
  14. End If
  15. End Sub
this script effectively shifts between two queries depending on the users selection and requeries to ensure the most up to date information is selectable in the List Box.

again thanks guys!
Aug 13 '07 #7
ADezii
8,834 Recognized Expert Expert
ok guys, works perfectly. I actually had to use advice from both your posts and this is the result:

Expand|Select|Wrap|Line Numbers
  1. ' #############################################################
  2. 'CHANGE THE ROWSOURCE QUERY IN THE ClassSelectLIST LIST BOX 
  3. ' THEN REQUERY
  4. Private Sub AppPosition_AfterUpdate()
  5.  
  6. If Me![AppPosition] = "Installer" Then
  7.     Forms![frm_VEH4a]!ClassSelectLIST.RowSourceType = "Table/Query"
  8.     Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsINS"
  9.     Me!ClassSelectLIST.Requery
  10.   Else
  11.       Forms![frm_VEH4a]!ClassSelectLIST.RowSourceType = "Table/Query"
  12.       Me![ClassSelectLIST].RowSource = "qry_FindAvailableSlotsTRA"
  13.       Me!ClassSelectLIST.Requery
  14. End If
  15. End Sub
this script effectively shifts between two queries depending on the users selection and requeries to ensure the most up to date information is selectable in the List Box.

again thanks guys!
Anytime we can be of service!
Aug 13 '07 #8

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

Similar topics

2
4517
by: James A | last post by:
I have 3 problems which I'd like people to solve for me (I've run out of ideas) 1) I have a table called s7-300. If i simply run this line of code: lstResult.rowsource = "Select * FROM S7-300"
3
1977
by: R. de Vos | last post by:
Hi all you experts, I have a 'small' problem In a mdb I have a column called "PLACE" its value type = text rowsourcetype=list with values Rowsource = HOME;SCHOOL;STATION What I would like is, one way or the other, to use the items in Rowsource in
0
1183
by: James | last post by:
Hello, This is a bit complicated but the bottom line is this: I have a form, class, and 'wrapper' function in an MDE that I have listed in my References. (The 'wrapper' is to enable referring to the class from another database that References the MDE.) The form has a listbox object whose Rowsource I set to an SQL string that I pass as a parameter to the wrapper. Here is my problem: once displayed, the list box appears empty (as though...
3
5198
by: Scott | last post by:
I have a function named MyFunction in a standard module that creates a semi-colon delimited list. I want to use this list for the value list in a listbox. I have the row source type property set to Value List. Can I use the function, MyFunction, as the row source of the listbox? I have tried =MyFunction and just MyFunction and in each case the listbox shows =MyFunction or MyFunction like it is the first choice in the listbox rather than...
4
4678
by: Corey | last post by:
I am having some real trouble getting a listbox rowsource to load properly. The listbox is actually on a subform. My main form has several command buttons that change the MASTER_SUB_FORM object source to the specific sub form needed by the end user. When designing the sub form i used the querybuilder to create an SQL statment to define the listbox values. **** RowSource SQL Statement ****
1
3352
by: mlarson | last post by:
Hello, I'm working on a page that dynamically creates listboxes and the "options" that are added to the listbox. A user can then click on buttons to either add or delete the "options" from one listbox to the other. All of this works fine, but when the user changes from one page to the next, I'm trying to save all user input before it redirects to the next page. For some reason, I can't see what values have been selected in one of the...
5
3518
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator; Response.Form.GetEnumerator(), etc. while, identifying specific controls by programmatically assigned unique id (e.g. MyButton_AnswerID_123). However, I am not sure if that is the proper way. What is the common practice?
3
8107
by: Prochot | last post by:
I'm trying to design a database to track projects and the associates assigned to them. I have almost no experience with this. I have three tables: -Projects -Associates -Assignments where assignments contains projectID and associateID and is related to the projects.projectID primary key and the associates.associateID primary key. I have a form based on the projects table that contains a list box that I would like to use to...
6
4383
by: cwhitcomb2 | last post by:
I have created a form in my database that resembles a calendar. I have 42 textboxes that display the day of the week for whatever month and year is selected in the combo boxes at the top of the form. The text boxes are named Text1, Text2, etc. The combo boxes are named cboYear and cboMonth. Here is the problem: I put a listbox under each textbox that should show the project# for the projects that are active on that day. I'm using 3 fields...
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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 we have to send another system
3
2850
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.