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?
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.
-
Private Sub region_Click()
-
Dim db As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim varItem As Variant
-
Dim strCriteria As String
-
Dim strSQL As String
-
-
Set db = CurrentDb()
-
Set qdf = db.QueryDefs("qryMultiSelect")
-
-
If Me!region.ItemsSelected.Count > 0 Then
-
For Each varItem In Me!region.ItemsSelected
-
strCriteria = strCriteria & "tbl_country.Region = " & Chr(34) _
-
& Me!region.ItemData(varItem) & Chr(34) & "OR "
-
Next varItem
-
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
-
Else
-
strCriteria = "tbl_country.Region Like '*'"
-
End If
-
-
strSQL = "SELECT Country FROM tbl_country " & _
-
"WHERE " & strCriteria & ";"
-
qdf.SQL = strSQL
-
-
'DoCmd.OpenQuery "qryMultiSelect"
-
-
Set db = Nothing
-
Set qdf = Nothing
-
-
' This line does nothing
-
Forms!Search!Country.Requery
-
End Sub
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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)
...
|
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...
|
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...
|
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...
|
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,...
|
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,...
| |
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...
|
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...
|
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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
| |