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 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.
-
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 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:
|
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....
|
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...
|
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
|
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()
| |
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,
|
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.
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |