473,785 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create report with Combo boxes selections?

46 New Member
Question: How do I create a Report based off the values/selections of mutliple combo boxes in a form?

I have tried this several times with several failures and have used multiple
codes to try this and each has been unsuccesful.

I will try to explain my database and its contents
Tabels and Fields ((PK) indicates the primary Key):
tblAssets: ID(PK), AssetNumber, SerialNumber, ModelName, ComputerName,
DeploymentDate, Active, UserName, OfficeName,OSNa me
tblContacts: ID, Company, LastName, FirstName, Initial, EMailAddress,
JobTitle, BusinessPhone, Address, City, State, Zip, Country, Username(PK)
ChargeCode, LocationCode
tblLocation: LocationCode(PK )

tblModel: ModelID(PK), ModelName

tblOfficeVersio n: OfficeID(PK), OfficeName

tblOSVersion: OSName(PK)

So initial i have tried to create a form with two combo boxes. cboModel and
cboLocation and with a cmdbutton that open rptModel. Upon opening I want to
see how many of each model is at each location.

Exaple: Location: OH01
Model: Dell 630 = 20
IBM M50 = 15

I have tried multiple codes with no success. Please help I have been posting
this problem for 3 weeks with very little help. Not that people have tried
but it seems that this is an issue that isnt covered very often. Thank you
for any help and if there are any questions please ask. I can also provide a
code if that helps, but like I said I have tried various differant codes with
no success.Thanks!
Mar 2 '09 #1
30 2626
OldBirdman
675 Contributor
I have tried this several times with several failures and have used multiple codes to try this and each has been unsuccesful.
What are you trying that does not work?

tblContacts: ID, Company, LastName, FirstName, Initial, EMailAddress, JobTitle, BusinessPhone, Address, City, State, Zip, Country, Username(PK)
Using Username for a Primary Key (PK) implies that your table structure, and therefore the database design is not correct, and needs a complete revision. Is this what doesn't work? See Database Normalization and Table Structures for information about designing tables and creating relationships.

So initial i have tried to create a form with ...
You cannot create a form? Or you cannot create a form with comboboxes?

Please tell us what you have that works. Then what you have tried that doesn't work, for example, "My Report is always blank", or "My report shows all records, and ignores my comboboxes", or "My comboboxes don't work".
Mar 2 '09 #2
vanlanjl
46 New Member
Okay- 1.) the reason I use "username" as my primary key is becuase it links to the tblAssests. This way a computer asset is linked to a user by the username.

Okay the first time i tried this i used the following code "On Click" for cmdApplyFilter:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdApplyFilter_Click()
  5.     Dim strModel As String
  6.     Dim strContactName As String
  7.     Dim strFilter As String
  8. ' Check that the report is open
  9.   DoCmd.OpenReport "rptContacts", acPreview, , strFilter
  10. ' Build criteria string for Office field
  11.     If IsNull(Me.cboModel.Value) Then
  12.         strModel = "Like '*'"
  13.     Else
  14.         strModel = "='" & Me.cboModel.Value & "'"
  15.     End If
  16. ' Build criteria string for Department field
  17.     If IsNull(Me.cboContactName.Value) Then
  18.         strContactName = "Like '*'"
  19.     Else
  20.         strContactName = "='" & Me.cboContactName.Value & "'"
  21.     End If
  22. ' Combine criteria strings into a WHERE clause for the filter
  23.     strFilter = "[Model] " & strModel & " AND [ContactName] " & strContactName
  24. ' Apply the filter and switch it on
  25.     With Reports![rptContacts]
  26.         .Filter = strFilter
  27.         .FilterOn = True
  28.     End With
  29. End Sub
  30.  
My two cobo boxes:
cboModel
Expand|Select|Wrap|Line Numbers
  1. SELECT tblModel.[ModelID], tblModel.[ModelName] FROM tblModel ORDER BY [ModelName]; 
  2.  
cboContactName:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Query1].[Contact Name] FROM Query1 ORDER BY [Contact Name]; 
  2.  
Query1:
Expand|Select|Wrap|Line Numbers
  1. SELECT IIf(IsNull([LastName]),IIf(IsNull([FirstName]),[Company],[FirstName]),IIf(IsNull([FirstName]),[LastName],[LastName] & ", " & [FirstName])) AS [File As], IIf(IsNull([LastName]),IIf(IsNull([FirstName]),[Company],[FirstName]),IIf(IsNull([FirstName]),[LastName],[FirstName] & " " & [LastName])) AS [Contact Name], tblContacts.*
  2. FROM tblContacts
  3. ORDER BY IIf(IsNull([LastName]),IIf(IsNull([FirstName]),[Company],[FirstName]),IIf(IsNull([FirstName]),[LastName],[LastName] & ", " & [FirstName])), IIf(IsNull([LastName]),IIf(IsNull([FirstName]),[Company],[FirstName]),IIf(IsNull([FirstName]),[LastName],[FirstName] & " " & [LastName]));
  4.  
The second cmd button cdmRemoveFilter :
Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdRemoveFilter_Click()
  2.  
  3.     On Error Resume Next
  4. ' Switch the filter off
  5.     Reports![rptContacts].FilterOn = False
  6.  
  7. End Sub
  8.  
So I open the form and select in cboModel D630 then I either leave the second one blank or select a Contact Name ( that I know has a Dell 630) and then I click the "Apply Filter" cmdbutton. A small form titled "Enter Parameter Value" open asking for a Model to be inputed and same for Contact name. I input correct values and or leave the contact name blank and I get a blank form.

This is the first code I tried and this is a horrible example becuase I really do not want to search users. The "Contact Name" combo box should be replaced with something like "OSVersion" , "Location", or even OficeName". But i was just trying to get something to work.

-----------------------------------------------------------------------------------------------------------------
Form2
cboModel: row source
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblModel].[ModelID], [tblModel].[ModelName] FROM tblModel ORDER BY [ModelName]; 
  2.  
cboLocationCode : row source
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblContacts].[UserName], [tblContacts].[LocationCode] FROM tblContacts ORDER BY [LocationCode]; 
  2.  

command button "on click"
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command7_Click()
  2. strWhere = "1=1 "
  3. If Not IsNull(Me.cboModel) Then
  4.   strWhere = strWhere & " AND [Model] =""" & Me.cboModel & """ "
  5. End If
  6. If Not IsNull(Me.cboLocationCode) Then
  7.   strWhere = strWhere & " AND [LocationCode] =""" & Me.cboLocationCode & """ "
  8. End If
  9.  
  10. DoCmd.OpenReport "tblContacts", acPreview, , strWhere
  11. End Sub
  12.  
So with this one there are a couple of problems. The first problem is in the cboLocationCode . The drop down list in the combo box shows mutliple values of the same location. For example there are multiple users that work in Location OH01, but I want the list in the combo box to list only once OH01.

After selecting values for each combo box I select the cmd button and again iget the small "Enter Parameter Value" but only for the Model and then I get a blank form.


Thank you for your quick respose OldBirdMan
Mar 2 '09 #3
OldBirdman
675 Contributor
You can't get the report right until you get the form/comboboxes right.
The first problem is in the cboLocationCode . The drop down list in the combo box shows mutliple values of the same location.
Of course it does. Your query
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblContacts].[UserName], [tblContacts].[LocationCode] FROM tblContacts ORDER BY [LocationCode]; 
selects each user and location. If this query results in a location with multiple users, what did you want to happen to those UserNames.
I don't know how you developed this (and the other) SQL statements, but the first requirement for them is that they must do what you want when used in the Query Design window. Open this window from the database window Tab=Queries, then "Create query in Design view", choose SQL view, and paste the SELECT statement. Switch to DataSheet view, and this will show the results of this query. If it isn't what you want here, it isn't going to work as the RowSource for your combobox. Fix it using Design View, then DataSheet view, until it is correct. Switch to SQL view, and copy this as rowsource for your combobox.
Mar 2 '09 #4
vanlanjl
46 New Member
I assuming you mean to change the criteria in the desighn veiw? I have a Access 2007 book and it only shos me mathmatical criteria or exact search criteria like for specific words. Is there more that I ma missing?
Mar 2 '09 #5
OldBirdman
675 Contributor
Can you go to the query design grid?
Mar 2 '09 #6
vanlanjl
46 New Member
Expand|Select|Wrap|Line Numbers
  1. SELECT tblContacts.UserName
  2. FROM tblContacts
  3. WHERE (((tblContacts.LocationCode)="OH01"))
  4. ORDER BY tblContacts.LocationCode;
  5.  
Im not sure if this it? This code has a specific location in it and i want the user to select the location. The location can always change and I would like it to at least sya the location once and then all the users or models or whatever
Mar 2 '09 #7
vanlanjl
46 New Member
Not sure what you mean by query design grid. My options are as follows:
design veiw
SQL veiw
Datasheet veiw
Pivottable veiw
Pivotchart veiw
Mar 2 '09 #8
OldBirdman
675 Contributor
When you design forms, you use Form Design, and switch between Design View and Form View. When you design Reports, you design in Design View, and switch to Print View. You should be able to go to query design the same way.
Mar 2 '09 #9
vanlanjl
46 New Member
Expand|Select|Wrap|Line Numbers
  1. SELECT tblContacts.UserName, tblContacts.LocationCode
  2. FROM tblContacts
  3. ORDER BY tblContacts.LocationCode;
  4.  
Would this work?
Mar 2 '09 #10

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

Similar topics

4
1541
by: Steve Chatham | last post by:
I have a page where I have some combo boxes on it. A click on each one spawns another box, and another until each area has been selected, or until they choose to pull all items into a datagrid from that category. For instance: say the first combo has in it: meat dairy
3
1507
by: ducky | last post by:
I need help with opening a report when a button is clicked, but I only want to open the report with the Object I have chosen in the combo box. This is what i have so far: 'If 2 is selected open the report with onlythe selected Vehicles' ElseIf fraLabelTypeSelection = 2 Then DoCmd.OpenReport "rptLabels", acViewPreview, , VehicleMake = Forms!frmLabelSelection!cboVehicle Else MsgBox...
4
2361
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. The idea behind the database is for a user to search/ select desired information in any kind of combination between the 4 combo boxes. Then the user clicks a button (btnSearch) and subsequently a query ("Search Function") is run that shows all 4...
6
3683
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
2908
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a main form (RD Form) with 4 combo boxes (i.e. cbo1, cbo2, etc) and a subdatasheet (the subform...let's call it subInfo) below the combo boxes on the RD Form. I hope this eliminates any confusion of the
6
9429
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report. I've tried using a macro with the code: Macro Name: cmdGenerateReport : On Click Action:...
2
4618
by: SHAWTY721 | last post by:
I have a form that contains two combo boxes that are related to each other. I need to find a way to populate my text box based on the criteria of the two combo boxes so the appropriate number appears in the text box.
4
8982
kcdoell
by: kcdoell | last post by:
Hello: What is the best way to stop a report from running if the query is empty? Currently, I have a form that has a command button on it. The user has to make selections from 3 combo boxes on the form and then via the cmdbutton the report opens in preview mode. I want to stop it from executing if the query is empty. I thought I could do this by checking the record count by the following code but I error out with the following message: ...
12
4047
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just not several, to report using this code i found - Private Sub cmdPreview_Click()
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
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
10346
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
10096
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
9956
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
8982
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
7504
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
5386
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...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.