473,503 Members | 1,656 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 2345
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
5385
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...
12
3349
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...
3
1509
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...
5
4672
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...
4
2847
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...
6
2450
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) ...
5
6328
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...
8
5161
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...
18
3531
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...
0
7202
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
7278
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,...
0
7328
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...
0
7458
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
5578
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,...
1
5013
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...
0
3167
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
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...

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.