473,651 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access: Update Listbox from query

2 New Member
Hi,

I'm trying to build a simple search in Access. I'll just give a simplified example, as I think I can solve the problem, if you can help me with this subproblem..

I have 2 listboxes - "Region" and "Country". "Region" supports extended multiple select.

I want the Country listbox to populate with all countries in all of the selected regions.

So far, I can do it without multiple select, using requery.

I've created a subroutine that extracts each selected value from the "Region" listbox and creates a new query.

The "Country" listbox is based on this query. But when I do requery, "Country" doesn't seem to load the altered query - it just refreshes the already selected query. This means that the box isn't updated with the new selection, but it is when I go to design view and back again.

How do I get the listbox to populate from the new version of the stored query?

--- Or is there a simpler way to do it?
Nov 30 '06 #1
2 2353
sashi
1,754 Recognized Expert Top Contributor
Hi,

I'm trying to build a simple search in Access. I'll just give a simplified example, as I think I can solve the problem, if you can help me with this subproblem..

I have 2 listboxes - "Region" and "Country". "Region" supports extended multiple select.

I want the Country listbox to populate with all countries in all of the selected regions.

So far, I can do it without multiple select, using requery.

I've created a subroutine that extracts each selected value from the "Region" listbox and creates a new query.

The "Country" listbox is based on this query. But when I do requery, "Country" doesn't seem to load the altered query - it just refreshes the already selected query. This means that the box isn't updated with the new selection, but it is when I go to design view and back again.

How do I get the listbox to populate from the new version of the stored query?

--- Or is there a simpler way to do it?
Hi there,

You seems to have a great theory here, have you started initial programming task regarding the above mentioned issue? Please post your code segment for further validation / debuging. Good luck & Take care.
Nov 30 '06 #2
Chucara
2 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub region_Click()
  2.    Dim db As DAO.Database
  3.    Dim qdf As DAO.QueryDef
  4.    Dim varItem As Variant
  5.    Dim strCriteria As String
  6.    Dim strSQL As String
  7.  
  8.    Set db = CurrentDb()
  9.    Set qdf = db.QueryDefs("qryMultiSelect")
  10.  
  11.    If Me!region.ItemsSelected.Count > 0 Then
  12.       For Each varItem In Me!region.ItemsSelected
  13.          strCriteria = strCriteria & "tbl_country.Region = " & Chr(34) _
  14.                        & Me!region.ItemData(varItem) & Chr(34) & "OR "
  15.       Next varItem
  16.       strCriteria = Left(strCriteria, Len(strCriteria) - 3)
  17.    Else
  18.       strCriteria = "tbl_country.Region Like '*'"
  19.    End If
  20.  
  21.    strSQL = "SELECT Country FROM tbl_country " & _
  22.             "WHERE " & strCriteria & ";"
  23.    qdf.SQL = strSQL
  24.  
  25.    'DoCmd.OpenQuery "qryMultiSelect"
  26.  
  27.    Set db = Nothing
  28.    Set qdf = Nothing
  29.  
  30. ' This line does nothing
  31.     Forms!Search!Country.Requery
  32. End Sub
  33.  
Above code is from the "region" listbox. This produces the correct query. The problem is that the final line does not update the "country" listbox with the next query..

Perhaps an example is in order:

There form has two listboxes. If I in the first listbox (region" select "Europe" and "North Africa"), the second listbox (country) should display "Algeria, Denmark, Germany, Libya etc" -- all countries in the selected regions.
Nov 30 '06 #3

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

Similar topics

14
5405
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB 7.2 environment, the choices the optimizer makes often seem flaky. But this last example really floored me. I was hoping someone could explain why I get worse response time when the optimizer uses two indexes, than when it uses one. Some context:
12
3375
by: Mike MacSween | last post by:
Sorry if this is a bit off topic, but I can't seem to find a 'remote control' newsgroup on my news server. And anyway I know Tony has some experience of this. The app is split FE/BE. I'd like remote access to at least the server, hopefully the whole network. And to be able to upload/download, to install new versions of the FE to the server (which then get sent up to the clients at runtime). What experience does anybody have of this....
3
1516
by: Magno101 | last post by:
Hi all, First let me start out with what I want to happen with this and then maybe y'all can give me some better insight. I have a database in Microsoft Access which we need to upsize to SQL. We currently have a problem with it now. On one of our forms (frmScan, which is an unbound form with two unbound controls) there is a txtBox contorl (txtScan) which gets a number from a barcode put into it (usually a 9 character varchar). I have...
5
4692
by: Andrew | last post by:
I've got a list box that selects a record on a subform, and in that subform are a few text fiels and a button that runs an update query. How do I have the update query button run and only update the record that is selected in the list box? The data updates right, but I can't get the update query to do anything but update all of the records. Thanks, Andrew
4
2854
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table query. I'm having trouble doing it. Help! Here is my code so far: Sub OldRegionQuery()
6
2457
by: AAJ | last post by:
Hi all I have a listbox on a form. If I set its rowsource directly, and the query in the rowsourse returns no data, then the displayed listbox is empty (exactly as you would expect) However.... If I programatically set the rowsource, and the query returns no records then access completely crashes and switches its self off,
5
6334
by: Lisa | last post by:
Hello, I am new to using recordsets, and i am completly stuck with this one. I am trying to use a multi select list box to write records to a table. Something in my code is causing the same record to be written over and over, for example if I have 4 items selected, it writes the same item 4 times in my table. Here is my code.
8
5167
by: NJonge01 | last post by:
Great thanks to all the helpful responses I've read! Recently using MS Access after a lengthy (7-10 years) away from the tool. I apologize for posting a question that for all intents & purposes appears to have been answered several times. Unfortunately, I've tried nearly a dozen approaches that seem to work for others on this board with similar (nearly identical in some cases) problems. I would like to navigate through records on a subform...
18
3546
by: Ljordan2k6 | last post by:
Hi. First post here, so I apologize ahead of time if it isn't the best-formatted post. I am working on a form that has a listbox (named LstCustID) that is bound to an access table (named CustomerInfo). I also have a datagrid (named DgvWOList) in which I want to display the results of my query into the table it is bound to (named WorkOrder). My problem is this: I want to be able to select a customer from the listbox and have a query run...
0
8695
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
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
8576
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
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...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
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.