473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to populate a combo box with canned queries and display results

AccessIdiot
493 Contributor
I have one big fat table with goose nesting data. Things like nest location (name of island in a river), nest type (ground/platform), number of eggs, number of eggs hatched, type of predation, etc.

I have some canned queries that I need to report: total number of eggs, number of eggs by island, number of eggs by type, number of nests, number of nests by island, number of nests by type, etc. So there are a few basic questions (total # nests, total # eggs, total nest success, total nest failure) and then further filters (all of the above filtered by type, location, possibly date range).

I would LOVE to build a dynamic search form but I keep failing (combo box #1 = total # of . . .; combo box #2 = filter by type/location; 3rd filter of date range).

So now I'm trying to just build one combo box that contains all these canned queries and then have a subform or report (whatever is easiest) show the results. The queries are not simple select statements, they are sums and counts. Any ideas? All I've got right now is an unbound form with an unbound combo box that contains a value list of two columns: name of query, description of query. I'm clueless about what to put in the after update part of my combo box.

By the way this is Access 2007. Cheers!
Jul 8 '10 #1
21 2638
AccessIdiot
493 Contributor
Okay so now I have a select case running openquery in my after update statement of my combo box. I'd like to have the results displayed in a subform instead of popping open the actual query. How is this accomplished?
Jul 8 '10 #2
patjones
931 Recognized Expert Contributor
In the broadest terms possible, you'll want to use something like:

Expand|Select|Wrap|Line Numbers
  1. Select Case combovalue
  2.    Case value1
  3.       Forms![subform name].RecordSource = str_query1_SQL
  4.    Case value2
  5.       Forms![subform name].RecordSource = str_query2_SQL
  6.    . . .
  7. End Select
  8.  
  9. Forms![subform name].Requery

If there is a lot of similarity between the various SQL, something you can do is set the subform recordsource ahead of time in a very general way - say "SELECT * FROM tablename", then simply use the case structure to pick out the appropriate filter (call it "strFilter" ) and set the filter after coming out of the case structure: Forms![subform name].Filter = strFilter. This would be the preferred method, but if there is a lot of variability in these queries you may not be able to do it this way.

Pat
Jul 8 '10 #3
AccessIdiot
493 Contributor
I apologize for being a total newb (my username says it all). My select case is set up a bit different. Right now it looks like this:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub cboSelectQuery_AfterUpdate()
  4.     Select Case Me.cboSelectQuery
  5.     Case 0
  6.     DoCmd.OpenQuery "qry_NestCount"
  7.     Case 1
  8.     DoCmd.OpenQuery "qry_NestCountType"
  9.     Case 2
  10.     DoCmd.OpenQuery "qry_NestCountIsland"
  11.     End Select
  12.  
  13. End Sub
and it just launches the query. I would love to have the result displayed on the form itself, or in a report or something.

Maybe I should just build a report with all the canned queries displayed instead of trying to get fancy with dynamic queries.

Thanks for your help.
Jul 8 '10 #4
patjones
931 Recognized Expert Contributor
Well you have over 400 posts, so I wouldn't call you a total newbie! Anyway, what you have is very close to what I suggested, except you want to show the query results in a subform. Since you have all the queries setup, you could do something like this:

Expand|Select|Wrap|Line Numbers
  1. Select Case Me.cboSelectQuery
  2.     Case 0
  3.        Forms![subform name].RecordSource = "qry_NestCount"
  4.     Case 1
  5.        Forms![subform name].RecordSource = "qry_NestCountType"
  6.     Case 2
  7.        Forms![subform name].RecordSource = "qry_NestCountIsland"
  8. End Select
  9.  
  10. Forms![subform name].Requery

Of course, you're going to need to set the subform up with all the proper fields, but that shouldn't be too tough.

Pat
Jul 8 '10 #5
nico5038
3,080 Recognized Expert Specialist
I would probably create a form with a tab control holding on each tab a subform with the query to show the results.
Finally you can add dynamically a Filter to these subform to limit the results e.g. per measuring period.

Idea ?

Nic;o)
Jul 8 '10 #6
AccessIdiot
493 Contributor
@zepphead80
400+ posts because I ask a lot of dumb questions. :-)

For example, I'm not even sure how to set up the subform. I mean, one query is doing a count (count Nest_IDs), another is doing a sum (sum Num_Eggs), etc. Really I'd be happy with a report that showed all the data, then had some text boxes that showed the results of the queries. But apparently you can't set an unbound textbox control source to a query? I have to build the function again?
Jul 8 '10 #7
patjones
931 Recognized Expert Contributor
No but you can set the text box Control Source to an aggregate function. For instance:

Expand|Select|Wrap|Line Numbers
  1. Me.txt = DSum("order_quantity", "tblOrders", "customer_ID <= 5")

This calculates the sum of the order quantity column in the orders table, but will include customer ID's only up to and including 5. There are other domain aggregate functions like DCount, DMin, DMax, DAvg, etc. and they would work nicely in a report where you want to summarize data.

Pat
Jul 8 '10 #8
AccessIdiot
493 Contributor
Okay, I'm trying a different approach. Tell me if I'm crazy (or just inefficient :-) ).

I have three combo boxes. The first is unbound, with a value list of "Nest Type" and "Island".

When "Nest Type" is chose I want a 2nd combo box to appear that lists the nest types (bound to a look up table). If "Island" is chosen I want the 2nd combo box to list the Island names (bound to a different look up table).

Then the user hits the "apply filter" button and I have either a subform that shows the filtered records (from the main table) in table view OR launches a filtered report (the latter would be easier to print or export, but right now I just want something that works).

So I'm thinking three combo boxes. The first is the 'filter by' one and the other two are hidden until a choice is made in the first one.

Problem is I'm not sure where to put the code. I know I need something on the after update of the first combo box and probably also something on the form launch? There are so many examples out there I think I'm confusing myself with what to put where. Any help appreciated!
Jul 12 '10 #9
nico5038
3,080 Recognized Expert Specialist
Check out these insights:

http://bytes.com/topic/access/insigh...filtering-form

http://bytes.com/topic/access/insigh...mbo-list-boxes

Thanks to NeoPa :-)

Nic;o)
Jul 12 '10 #10

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

Similar topics

6
2315
by: Jules | last post by:
Hi: I have an Access 97 Search form set up - a couple of combo boxes, a couple of text fields and a command button. I want the command button to run an SQL script and then open the results form. I can get the button to open the other form but I can't get it to run the module with the subroutine in it. This is my first sorti into programming Access so be kind - I have some SQL and ASP experience but these modules are a problem for me.
5
2456
by: Filips Benoit | last post by:
Dear all, How can i populate a combo with the field-caption-names of 1 table? Thanks Filip
5
11695
by: jdwyer05 | last post by:
Hello, I am trying to populate a combo box with only unique values. Currently I am using an access database and VB6 Enterprise. The program populates the combo box fine however, there are several repeated values in this column. What i would like to do is just show one instance of that particular record. For example: if the column has the values: Accounts Payable, Process Control, Shipping, Accounts Payable i would like the combo...
2
2030
by: mpmason14 | last post by:
i know there is a way to populate one combobox based on another, but i've never done it myself and am looking for some help. i have a table that has SwitchNo and NumberofPorts as two columns. i want to create a union query to display the correct numberofports for the selected switch in switchno. ex) SwitchNo - 1 Numberofports - 24 switchno - 2
2
1655
by: lottaviano | last post by:
I have a form with two combo boxes. The value chosen in the first combo box (cbo1) is supposed to change the values that appear in the second combo box (cbo2). This currently works great for the first record entered by the user (continuous forms). However in the second record, cbo2 shows the values influenced by cbo1 in the first record, rather than the 2nd record (i.e. it doesn't update). My problem may be that both combo boxes have...
7
22679
by: nareshpulipati | last post by:
Hi all, I am new to VB .net. Iam trying to populate the database item into combo box. Database Type:SQL(ODBC) My code retuns no value in combo box Public Class Form1 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim Cmd As Odbc.OdbcCommand Dim Con As Odbc.OdbcConnection Dim Sql As String = Nothing
18
2560
by: jmarcrum | last post by:
Hi everyone! I have a form that when the user opens it, the Date combo box on the form is populated with every month of the year. But I don't want it to do that! I want it to populate with the next 3 Sundays chronologically for the user to select from. How do I need to change my code? Here's my OnLoad event for the form... Private Sub Form_Load() Dim intSunday As Integer 'set the rowsource type Me.cmbDate.RowSourceType =...
2
7997
by: Coolboy55 | last post by:
I'm creating a report with 3 source queries. Each source query returns distinct values of the same field name (SkillID). How do I display the distinct results of all 3 queries on the same report? Thanks! CB55
4
9249
by: =?Utf-8?B?R3JlZw==?= | last post by:
Can someone give me e simple example of to populate a combo box / list box using an ArrayList? THanks.
7
3343
by: RG360 | last post by:
Hello. I am new in Access and I need assistance from Pro's I have a data entry form from 2 main tables and they have relationships with other tables. My main table only contains Field ID's, because all of these fields are referenced from other tables. On my form, these fields are Combo Boxes, wherein you can add/select from the list to populate the table. All works fine, except I would like to create a combo box to find records based...
0
8831
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
9548
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
9325
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
8244
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
6796
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
6076
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
4607
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
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
2215
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.