Union Query Prompts For Parameters - Returns All Records With Parameter Entered!
May 17, 2006
Hello all,
I realise this issue is a common one and it is usually down to simple typos (I've looked at several similar posts) but none of the advice I've seen has solved my problem. I've designed the following Union Query:
SELECT [Email],[Title],[First_Name],[Last_Name],[Company],[Phone],[Country],[TEST_AND_MEASUR],[REC_AND_PROD],[LOG_AND_TRANSC]
FROM [Region 1]
UNION ALL SELECT [Email],[Title],[First_Name],[Last_Name],[Company],[Phone],[Country],[TEST_AND_MEASUR],[REC_AND_PROD],[LOG_AND_TRANSC]
FROM [Region 2]
UNION ALL SELECT [Email],[Title],[First_Name],[Last_Name],[Company],[Phone],[Country],[TEST_AND_MEASUR],[REC_AND_PROD],[LOG_AND_TRANSC]
FROM [Region 3];
It should be very simple and I've checked it over and over, but when I run the query an Enter Parameter dialog appears prompting me to enter Email.
If I just click OK I get all the records but with the email field blank.
Similarly if I type x@y.com it returns all records but with the email fields all containing x@y.com
Advice would be very much appreciated!! Thank you in advance.
Abi
View Replies
ADVERTISEMENT
May 15, 2013
I had created a query that I was attempting to reference a text field in a form that was open when the query is run. It wasn't working and whenever I opened the form it would prompt for the parameter before opening the form.
I ended up deleting the query to try again from scratch. But the form still asks for the parameters whenever I open the form. Why is Access still prompting me for the parameters?
View 14 Replies
View Related
May 20, 2005
I have a front end that is connected to three back end files. The front end is on my local computer while the back end files are on a network drive.
There are a lot of calculations that go into the queries and intermediate queries. For a report, I have based it on a UNION query.
But when trying to design the report it takes about 45 seconds just to do any one thing, e.g.;
- Add Groupings
- Add Grouping Headers//Footer, sorting option
- Add bound textbox
:eek:
Needless to say this is very annoying.
:mad:
The union query itself runs fine (takes about 15 seconds to run) and returns about 12,000 Rows. The union query looks like this (I changed the field names to make it read easier, hopefully);
SELECT a1, a2, a3, a4, a5
FROM qry_A;
UNION SELECT ALL a1, b2 AS a2, b3 AS a3, a4, a5
FROM qry_B;
UNION SELECT ALL a1, c2 AS a2, c3 AS a3, a4, a5
FROM qry_C;
UNION SELECT ALL a1, d2 AS a2, a3, a4, a5
FROM qry_D;
UNION SELECT ALL a1, e2 AS a2, a3, a4, a5
FROM qry_E;
UNION SELECT ALL a1, f2AS a2, tblG.f3 AS a3, tblG.f4 AS a4, a5
FROM qry_F;
One solution I came across when searching the forums was to use an Append Query to append the query results to a table and base my report on that. This does indeed fix the problem.
But what I was wondering if it was is my query design that is causing it to be slow or is it just the fact that I am returning 12,000 rows?
:confused:
In case it matters, I wanted to mention that I can’t use the report wizard to create the report. When I select the union query, the fields will be showed for awhile then they just disappear. That in and of itself doesn’t cause any trouble since I am creating the report using the design view and not the wizard.
View 7 Replies
View Related
Oct 31, 2005
I am trying to run the below union query, but it keeps asking for FRGHT_BL!FB_CREAT_DTM as a parameter. I want it to only ask for the Start Date and End Date once.
SELECT * FROM qLOC_ID WHERE(((FRGHT_BL!FB_CREAT_DTM) Between [Enter Start Date] And [Enter End Date])) UNION SELECT * FROM qLOC_ID2 WHERE(((FRGHT_BL!FB_CREAT_DTM) Between [Enter Start Date] And [Enter End Date])) UNION Select * From qLOC_ID3 WHERE(((FRGHT_BL!FB_CREAT_DTM) Between [Enter Start Date] And [Enter End Date]));
View 1 Replies
View Related
Mar 15, 2007
I have created a query that will pull the price of a property into the cost field combo box on a booking order subform depending on the values of the start date and property number enter onto the same form.
The query gets the price from the property price table matching on the property no i've selected on the booking order subform and also the start date i've entered on the booking order subform which needs to be between the start and end date fields in the property price table.
Fields in the property price are property price no, property no, start date, end date and price.
Also the booking order subform is a subform on a booking form
This is the query i have created:
SELECT [Property Price].Price
FROM [Property Price]
WHERE (((forms![booking order subform]![start date]) Between [property price].[start date] And [property price].[end date]) And (([Property Price].[Property No])=forms![booking order subform]![property no]));
The problem is when i run the query from the cost combo box the query isn't picking up the fields on the booking order subform instead its bring up a seperate meesage box from parameters start date and property number to be enter.
Can someone give me advise how to make the query use the values in the fields on the booking order subform i enter before running the query. cheers
View 2 Replies
View Related
Feb 12, 2014
I am trying to copy the parameter value that is entered to a variable so that it can be used to run other queries without typing it in over and over. Once my form is finished it will run 4 queries, and the current setup is that I would have to retype the parameter each time.
View 9 Replies
View Related
Dec 12, 2014
I have a report that is fed by a parameter query. When a command button (Command23) is clicked a parameter box opens and the user enters a subsystem number. A report for that subsystem then opens.
I want to open the report with VBA and show a message if the user has failed to enter a subsystem number in the parameter box and just clicked OK.
The problem is I don't know how to refer to the parameter box and detect if it has been left empty before clicking OK. I first tried to use IsNull in an If statement with Command23.Value, but now realize it is the value in the parameter box I am after, not the "value" of Command23.
How can I change my code to detect if the parameter box has not been filled out?
Private Sub Command23_Click()
If IsNull(Command23.Value) Then
MsgBox "You did not enter a Subsystem", vbOKOnly, "No Criteria Entered"
Else
DoCmd.OpenReport "rptTESTInfoBySubsystem", acViewReport
End If
End Sub
View 1 Replies
View Related
Sep 17, 2013
I have an append query that currently looks like this URL...This query automatically adds the machine parameters for a product code and lot number into the running condition log. This is so the user does not have to manually go in and tediously select each machine parameter.
The running condition log also has a date field to specify what day and record number the machine parameter's value was recorded on. When I run the query the appended rows look like this. The product and lot are defined by user parameter and there are actually about 36 machine parameters
Code:
Productstockcode LotNo Day Record Parameter ActualCond
PE-500 130816m71 StockTemp
PE-500 130816m71 Zone 1
PE-500 130816m71 Zone 2
My question is: how do I modify the query to automatically add the date and record number in one shot? It needs to be user defined at the time of the query because this data is not stored anywhere else in the database. For each 36 machine parameters the day and record would be the same.
View 3 Replies
View Related
Aug 20, 2014
The following code throws an error:
DoCmd.SetParameter "Region", "apac"
Name of the Parameter: Region
Value for the Parameter: APAC
Location of the Parameter: Query_Form
How to pass a parameter for a Parameter Query in Run-time? (Without using form or something)
View 1 Replies
View Related
Oct 31, 2013
I have two text boxes for which I am trying have show and error message when the proper data is not entered. One text box is for PLANID and the other is for Date. I would like the PLANID to be checked 1st. The PLANID needs to be either 7 digits or 10. If it is not, the message would be "Please enter a valid PLANID". If it is 7 or 10 digits, then it should check the Date text box.
If it is blank, the message would be "Please enter a valid Date". If they are both blank, the PLANID message should appear 1st. Below is what I have written. The problem that I am having is that when the PLANID is 10 digits and the date is blank, the "Please enter a valid PLANID" message is showing rather than the "Please enter a valid Date" message.
Private Sub Btn_Refresh_Data_for_One_Plan_Click()
Me.txtboxPLANID.Value = UCase(Me.txtboxPLANID.Value)
If ((Len(Me.txtboxPLANID.Value) = 7 And Len(Me.txtboxPLANID.Value) = 10) And (Not IsNull(Me.txtboxPLANID.Value)) And (Not IsNull(Me.TxtboxDate.Value))) Then
Dim stDocName As String
stDocName = "Mcr_RUN_MATCH_DIFFERENCES"
[code]....
View 9 Replies
View Related
Aug 30, 2005
Obvious neophyte issue here, sorry...
I have a table, PURCHASE_ITEMS with 3 fields: ID, TYPE, NAME
Another table, ITEM_TYPES with 2 fields: ID, TYPE
TYPE in both tables is a text field and there is a one-to-many relationship between them.
When I run a query on PURCHASE_ITEMS, I can see all 25 records. When I set a criteria for TYPE to one of the types, no records appear, even though there are 5 or 6 of that type.
Can anyone help me with this absurdly simple problem that I can't seem to get my brain around?
View 1 Replies
View Related
Jul 29, 2007
I hope this doesn't sound too simple for this forum, I'm only a newbie!
I have a select query that will display the recordset that meets the criteria (OK I know that's not a big deal) but...I want to know if, when there are no records that meet the criteria, can I open a form (dialog box maybe) that will say there are no records found instead of showing a blank recordset. Once again I hope this is not so blindingly obvious that I have to start watching my coffee intake
Thanks in advance
View 2 Replies
View Related
Jul 15, 2013
Suppose I have two tables with fields as follows:
Assigned Courses (Courses that employees should do)Employee number
Assigned Course Name
Fulfilled Course (Courses that employees have done)Employee number
Fulfilled Course
Now I need to do a query that tells me which employees haven't done. Is there anyway to do that that is not an exclude query?
View 4 Replies
View Related
Mar 5, 2012
I have a query that runs just fine and takes about 1 minute to run on average. I have vba code that uses Dlookup to determine if the query returns any records. The problem is that each time it runs it has to crunch all the data, all I care about is if there is any result at all. Is there a way to get the query to stop after it finds one record to speed things up greatly?
View 2 Replies
View Related
Jun 30, 2014
A have a report that is based on a query that works fine when the query returns records.
However if the query (legitimately) returns no records then the report fields (numeric) are blank.
How can i get the query or report to show either "0" or "no data" when no records are returned? I have tried the NZ function but that didn't work so i don't think that is the right approach here?
View 3 Replies
View Related
Jun 7, 2013
I have a tabbed navigation form. I have a form on one of the tabs, [tab1frm] that a query that consists of 6 fields that are each from a different query.as the record source. This shows a percentage field, an image field, and a count field for current month and then then the same fields for year-to-date.
The problem is that when there are no records for the current month, the whole form [tab1frm] is blank. I read that if no records are returned this can happen, but since there are always records returned for year-to-date, I don't know why its happening. Is there any way to make blank fields show up or to show the most recent records so the form is never blank?
View 6 Replies
View Related
Jul 17, 2013
[URL]
My problem is when i use this form as a sub form, it makes the main form close as well. How can I make the main form stay and only the sub form close.
View 6 Replies
View Related
May 12, 2014
I'm trying to write record set contents to excel. My query runs perfect in access query wizard, but recordset showing as null. My VBA code
Code:
Dim cnn As ADODB.Connection
Dim recordst As ADODB.Recordset
Dim strSQL As String
Dim strPath As String
Dim appXL As Excel.Application
Dim wb As Excel.Workbook
[Code] ....
View 5 Replies
View Related
Oct 30, 2012
(Example of my data)
Order ID Customer ID Purchase Amount
1 17 $14.95
1 17 $7.35
2 21 $11.90
3 27 $64.80
3 27 $31.13
I have two tables with pull in data. What I'm looking for is a query that would combine the customers purchase and sum the purchase amount field. The tables are unioned as some customer data is in one table but not the other and joining them excludes some of this data. Ultimately I would like to see is
Order ID Customer ID Purchase Amount
1 17 $22.30
2 21 $11.90
3 27 $95.93
View 1 Replies
View Related
Aug 5, 2014
In the following code I have a parameter 'RegionPrefix' that filters my data by the first 2 characters of the 'Queue' field. How do I populate the 'RegionPrefix' parameter so it returns all of my data? Currently if I leave it blank it returns nothing.
Code:
PARAMETERS RegionPrefix Text ( 255 );
TRANSFORM Format(Avg([Abandonment Rate]),"Percent") AS ABAN
SELECT [Call Summary Table].Year, [Call Summary Table].Month
FROM [Call Summary Table]
WHERE (((Mid([Queue],1,2))=[RegionPrefix]))
GROUP BY [Call Summary Table].Year, [Call Summary Table].Month
PIVOT [Call Summary Table].Queue;
View 3 Replies
View Related
Oct 2, 2013
I have a complex database app that has a form called from the main form. It requires two inputs: BeginningDate and EndingDate and I use a calendar picker for date selection. Using data assigned to a variable, I build the SQL query in VBA. The result is:
Code:
SELECT [1733_All Print Orders].[Application], Sum([1733_All Print Orders].[TotalImages]) AS SumOfCCPC
FROM [1733_All Print Orders]
WHERE [Application] = 'CCPC' AND [StatementDate] >= #9/3/2013# AND [StatementDate] <= #9/30/2013#
GROUP BY [1733_All Print Orders];[Application]
[1733_All Print Orders] is a defined query that combines 4 tables together and there are data that falls within the dates for CCPC. But the query returns no records.
I pasted the query to the query builder and using different combinations, I isolated that the [StatementDate] >= #9/3/2013# portion is what returns no records
To complicate matters even worse, prior to today, it worked. I made some adds and changes to another area of the application, but did not touch this code.
View 1 Replies
View Related
Dec 10, 2007
I have two tables, and I made a union query (tbl1 UNION ALL SELECT ...tbl2). Problem is, I have two entries that are identical in both tbl1 and tbl2, but I want to include BOTH of them in the union query. Even though I used the ALL operator, only one set shows up!! I'm pulling out my hair trying to figure this out. Please help, and thanks so much in advance!:(
View 2 Replies
View Related
Nov 25, 2013
How can I add the resulting records from a union query. The results of the union are something like this:
Quantity Item
2 Cats
3 Cats
1 Dog
4 Mice
What I need to display is
Quantity Item
5 Cats
1 Dog
4 Mice
How can I get the query to "do the math"?
View 3 Replies
View Related
May 8, 2007
Hi All,
I am having an issue with a parameter query, let me try and explain...
I have a table (tblsitelogs) which contains records with dates on. I want to be able to query between 2 dates (from a form which the user specifies), and then export the data from the query, to an excel spreadsheet.
I browsed earlier and found this code to help me export the query to excel: http://www.databasejournal.com/features/msaccess/article.php/3563671. I am experienced in VB (although reletively new to Access), so I have adopted the code and tested it, and it works fine when run by itself.
Here is the query (qryReport)..
"SELECT tblSiteLog.ExchangeCode, tblSiteLog.ExchangeName, tblJobDetails.Phase, tblSiteLog.JobType, tblSiteLog.JobItem, tblSiteLog.Engineer, tblSiteLog.LogEntryDate, tblSiteLog.Result, tblSiteLog.EntryDetails, tblSiteLog.EnteredBy" & _
" FROM tblJobDetails INNER JOIN tblSiteLog ON tblJobDetails.JobID = tblSiteLog.JobID" & _
" WHERE (((tblSiteLog.LogEntryDate) Between " & txtStartDate & " And " & txtEndDate & "));"
When I then run this code
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryReport", dbOpenSnapshot)
I get an error on the bottom line, I get the error:
"Too few parameters. Expected 2".
I have researched and this appears to be an almost normal issue because of the query being a parameter-based query.
I've tried typing in the query in SQL, into VB and then running that instead, but it doesn't seem to filter, it will just display all results.
Feel free to ask more questions into this, I am probably only touching the surface of the problem here. Any help greatly appreciated!
Thanks,
Taz
View 7 Replies
View Related
May 7, 2014
I have a database that has over 20 tables in it and am using Access 2000. Unfortunately I cannot change the structure as it performs specific functions, so I am stuck with it.
I have created a Union Query from these tables yaking data from 5 fields using the Serial Number entered by the user.
SELECT[Workstation].UnitPart,PropertyTag,UnitSerial,Date,Technician
FROM[Workstation]
WHERE((([Workstation].UnitSerial)=[Enter Serial No.];
UNION
SELECT[LAPTOP].UnitPart,PropertyTag,UnitSerial,Date,Technician
[Code] ....
I use a bar code scanner to scan the serial number, and it goes through the tables and returns the results along with the other specified fields.
I would like to scan up to 16 or more different serial numbers and have it return the results. Perhaps scan the first 16 serial numbers, then run the query? Is that possible. The serial numbers are unique and will return a combination of laptops, printers, monitors, etc...
I have created a report from the above union query and it works perfectly with only one serial number entered.
View 14 Replies
View Related
Jul 20, 2006
The code pasted below creates a union query for a set of tables (J000171, J000174, J000178 etc) and stores the results of the query in a table called temp.
The first piece of code queries the ‘status’ field of a table rjobs for those records with a ‘status’ field of “Live”. Another field within this rjobs table, ‘JobID’, happens to be the name of a table where additional information relating to that job record is held eg. J000178 All of the tables selected in the query on rjobs are then included in the union query.
The second piece of code stores this information in a table called temp
I would like to be able to do 2 things with this;
1.add an additional field to the union query which holds the JobID field value from rjobs (or alternatively the table name from which the data originates eg J000178 etc as that is the same as the JobID file din rjobs)
2.create an option to clear the info in the temp table. Currently additional info is appended, so whenever the query is refreshed new data is simply added to old data. I would like to be able to clear that data where possible.
The union query is run from the on click of a command button on a simple form. Perhaps an additional button could be used to clear the records from the table temp.
Any ideas greatly appreciated.
Here is the existing code …
Option Compare Database
Option Explicit
Private Sub Command0_Click()
Dim db As Database
Dim rsRjobs As Recordset
Dim rsRapps As Recordset
Dim LengthofUnionSQL As Long
Dim sql As String
Dim UnionSQL As String
Set db = CurrentDb
Set rsRjobs = db.OpenRecordset("Select * from rjobs where Status = 'Live'", dbOpenSnapshot)
Do While Not rsRjobs.EOF
UnionSQL = UnionSQL & "Select ObjectID, SearchNo, DateSearched, Consultant, from " & rsRjobs!jobID & " Union "
rsRjobs.MoveNext
Loop
'following two lines are to remove the trailing word Union from the string unionsql
LengthofUnionSQL = Len(UnionSQL)
UnionSQL = Mid(UnionSQL, 1, LengthofUnionSQL - 7)
' Now variable Unionsql will hold the value something like
' Select ObjectID, SearchNo, DateSearched, Consultant from J000145
' Union Select ObjectID, SearchNo, DateSearched, Consultant from J000146
' Union Select ObjectID, SearchNo, DateSearched, Consultant from J000147
MsgBox UnionSQL
Set db = CurrentDb
Dim rsUnionquery As Recordset
Dim rstemp As Recordset
Set rstemp = db.OpenRecordset("temp", dbOpenDynaset, dbSeeChanges)
Set rsUnionquery = db.OpenRecordset(UnionSQL)
Do While Not rsUnionquery.EOF
rstemp.AddNew
rstemp!ObjectID = rsUnionquery!ObjectID
rstemp!SearchNo = rsUnionquery!SearchNo
rstemp!DateSearched = rsUnionquery!DateSearched
rstemp!Consultant = rsUnionquery!Consultant
rstemp!jobID = rsUnionquery!jobID
rstemp.Update
rsUnionquery.MoveNext
Loop
End Sub
View 2 Replies
View Related