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!
30 2626
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".
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: -
Option Compare Database
-
Option Explicit
-
-
Private Sub cmdApplyFilter_Click()
-
Dim strModel As String
-
Dim strContactName As String
-
Dim strFilter As String
-
' Check that the report is open
-
DoCmd.OpenReport "rptContacts", acPreview, , strFilter
-
' Build criteria string for Office field
-
If IsNull(Me.cboModel.Value) Then
-
strModel = "Like '*'"
-
Else
-
strModel = "='" & Me.cboModel.Value & "'"
-
End If
-
' Build criteria string for Department field
-
If IsNull(Me.cboContactName.Value) Then
-
strContactName = "Like '*'"
-
Else
-
strContactName = "='" & Me.cboContactName.Value & "'"
-
End If
-
' Combine criteria strings into a WHERE clause for the filter
-
strFilter = "[Model] " & strModel & " AND [ContactName] " & strContactName
-
' Apply the filter and switch it on
-
With Reports![rptContacts]
-
.Filter = strFilter
-
.FilterOn = True
-
End With
-
End Sub
-
My two cobo boxes:
cboModel -
SELECT tblModel.[ModelID], tblModel.[ModelName] FROM tblModel ORDER BY [ModelName];
-
cboContactName: -
SELECT [Query1].[Contact Name] FROM Query1 ORDER BY [Contact Name];
-
Query1: -
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.*
-
FROM tblContacts
-
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]));
-
The second cmd button cdmRemoveFilter : -
Private Sub cmdRemoveFilter_Click()
-
-
On Error Resume Next
-
' Switch the filter off
-
Reports![rptContacts].FilterOn = False
-
-
End Sub
-
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 -
SELECT [tblModel].[ModelID], [tblModel].[ModelName] FROM tblModel ORDER BY [ModelName];
-
cboLocationCode : row source -
SELECT [tblContacts].[UserName], [tblContacts].[LocationCode] FROM tblContacts ORDER BY [LocationCode];
-
command button "on click" -
Private Sub Command7_Click()
-
strWhere = "1=1 "
-
If Not IsNull(Me.cboModel) Then
-
strWhere = strWhere & " AND [Model] =""" & Me.cboModel & """ "
-
End If
-
If Not IsNull(Me.cboLocationCode) Then
-
strWhere = strWhere & " AND [LocationCode] =""" & Me.cboLocationCode & """ "
-
End If
-
-
DoCmd.OpenReport "tblContacts", acPreview, , strWhere
-
End Sub
-
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
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 - 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.
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?
Can you go to the query design grid?
-
SELECT tblContacts.UserName
-
FROM tblContacts
-
WHERE (((tblContacts.LocationCode)="OH01"))
-
ORDER BY tblContacts.LocationCode;
-
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
Not sure what you mean by query design grid. My options are as follows:
design veiw
SQL veiw
Datasheet veiw
Pivottable veiw
Pivotchart veiw
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.
-
SELECT tblContacts.UserName, tblContacts.LocationCode
-
FROM tblContacts
-
ORDER BY tblContacts.LocationCode;
-
Would this work?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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...
|
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
|
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
| |
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:...
|
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.
|
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:
...
|
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()
|
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...
|
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,...
| |
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...
|
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: 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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |