Access SQL Subqueries

Oct 5, 2006

Hello,

I am having a problem getting the expected results from a SQL subquery. The point of the query is to return all users and user titles that have not been entered into the database for the current month (not in tblHours). Some users have 2 titles and some just one title. Each month we enter hours worked per title so we can track labor progress. The problem lies w/ the individuals w/ 2 titles. The SQL only keys on the user id, but I need to return both user id and title. The variables called iMonth and iYear are passed from the form and the query is executed via a command button. qryTitlesPerUser contains each users title, name, and user id.

Here is the query:


strSQL = "SELECT qryTitlesPerUser.Name, qryTitlesPerUser.title FROM qryTitlesPerUser "
strSQL = strSQL & "WHERE qryTitlesPerUser.UserID AND qryTitlesPerUser.title NOT IN "
strSQL = strSQL & "(SELECT tblHours.UserID, tblHours.title FROM tblHours "
strSQL = strSQL & "WHERE tblHours.month = " & iMonth & " AND tblHours.year = " & iYear & ") "
strSQL = strSQL & "ORDER BY qryTitlesPerUser.Name"


Any help would be greatly appreciated.

Ken

View Replies


ADVERTISEMENT

Subqueries/joins/SQL

May 12, 2005

I have a form with a drop down menu of people to filter a report of projects with the managers and up to 3 assistant managers. When I choose someone from the dropdown menu, I want all of their projects to come up on the report. Currently, only the projects that person is managing come up, not the ones they are assistant managing.
In my query that is powering this report, I have joined the manager_id number in table A to an id_num field in table B. To make the assistant managers come up in the report, I need to join the assist1_id, assist 2_id, and assist3_id to id_num also. When I join assist1_id to id_num, I get the following error:
The SQL statement couldn't be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in the SQL statement.
The way I would like to fix this problem is by creating subqueries in the SQL view, but I don’t know how to code it. If you know how or if you know a better way of doing this, please help! :)

View 1 Replies View Related

Two Subqueries In One Statement

Jul 15, 2005

How many subqueries can I put into one SQL statement? I'm trying to run a query that has two subqueries, but it's not working. It works when I create and reference one of the queries separately, but when I put them directly into the statement as subqueries, it gives me a syntax error. It would really save loads of time to have this in one statement. Can someone tell me what I'm doing wrong with this query or tell me if this is possible to use the AS identifier more than once in a query?

qryTwo: WORKS!
SELECT tblEntityDetail.fldEntityID, tblEntityDetail.fldDetailID, tblEntityDetail.fldValue, tblEntityDetail.fldDate
FROM tblEntityDetail INNER JOIN [SELECT tblEntityDetail.fldEntityID, tblEntityDetail.fldDetailID, Max(tblEntityDetail.fldDate) AS MaxOffldDate, tblEntity.fldInactive, tblEntity.fldTypeID
FROM tblEntity LEFT JOIN tblEntityDetail ON tblEntity.fldEntityID = tblEntityDetail.fldEntityID
GROUP BY tblEntityDetail.fldEntityID, tblEntityDetail.fldDetailID, tblEntity.fldInactive, tblEntity.fldTypeID
HAVING (((tblEntity.fldInactive)=False) AND ((tblEntity.fldTypeID)=2))]. AS qryOne ON (tblEntityDetail.fldDate = qryOne.MaxOffldDate) AND (tblEntityDetail.fldDetailID = qryOne.fldDetailID) AND (tblEntityDetail.fldEntityID = qryOne.fldEntityID);

qryThree with separate reference to qryTwo: WORKS!
SELECT qryTwo.fldEntityID
FROM tblDetail INNER JOIN qryTwo ON tblDetail.fldDetailID = qryTwo.fldDetailID
GROUP BY qryTwo.fldEntityID

qryThree without separate reference to qryTwo: DOESN'T WORK!
SELECT qryTwo.fldEntityID
FROM tblDetail INNER JOIN [SELECT tblEntityDetail.fldEntityID, tblEntityDetail.fldDetailID, tblEntityDetail.fldValue, tblEntityDetail.fldDate
FROM tblEntityDetail INNER JOIN [SELECT tblEntityDetail.fldEntityID, tblEntityDetail.fldDetailID, Max(tblEntityDetail.fldDate) AS MaxOffldDate, tblEntity.fldInactive, tblEntity.fldTypeID
FROM tblEntity LEFT JOIN tblEntityDetail ON tblEntity.fldEntityID = tblEntityDetail.fldEntityID
GROUP BY tblEntityDetail.fldEntityID, tblEntityDetail.fldDetailID, tblEntity.fldInactive, tblEntity.fldTypeID
HAVING (((tblEntity.fldInactive)=False) AND ((tblEntity.fldTypeID)=2))]. AS qryOne ON (tblEntityDetail.fldDate = qryOne.MaxOffldDate) AND (tblEntityDetail.fldDetailID = qryOne.fldDetailID) AND (tblEntityDetail.fldEntityID = qryOne.fldEntityID)]. AS qryTwo ON tblDetail.fldDetailID = qryTwo.fldDetailID
GROUP BY qryTwo.fldEntityID

Hopefully I am wording this correctly??? If anyone can help me figure this out, I would greatly appreciate it. Thanks!!

View 6 Replies View Related

Parameter & Subqueries

Mar 24, 2006

Hi, I hope someone can help me out...
I've made a bunch of queries to get the data I need out of my table, they build on each other and I find that my date query is used twice. In date query I prompt for the date, when I run the percent query I get prompted twice.

How can I set this up to only prompt the user once for the date?


Here is roughly how my queries are dependent on each other


'percent query'
/
'Average query' 'date query'
/
'subtract query' 'record count query'
/
'sum query' 'date query'

View 1 Replies View Related

Top/Max/Subqueries ... Losing My Mind

Mar 8, 2008

I've looked at so many options for writing this query that I can't see the forest for the trees and hoping you kind folks will point me in the right direction.

I have a table called services that includes:

service_id
prop_id
service_year (ie: 2007, 2008)
service_date (ie: 3/3/08)

service_id is a unique ID for each service which relates to data I will need to pull from another table.

prop_id relates to a property ID in another table, not unique as multiple services against one property.

The problem that I have is that each prop_id can have more than one service_date for the same service_year. I need to be able to find the latest service_date on a prop_id and its associated service_year and service_id.

Any pointers would be greatly appreciated. BTW, using this in Access 2003 & 2007

View 14 Replies View Related

Can I Somehow Edit A Table Through A Form Which Uses Subqueries?

Dec 19, 2006

Short version of question:

My research has shown that Access will not allow edits through a form that 1) has subqueries in its SELECT clause, or 2) uses aggregation such as First(). Is there any tricky way around this?

Long version of question:

I have a database form that shows an overview of orders for products (it's based on a query that pulls all current orders from the big table). I would like to handle both of these on each row:


Show where we built it last time, and
Allow the user to select where it will be built this time.

The problem is that I cannot figure a way to change the form/query such that it doesn't aggregate to find out where we built it last time, or doesn't rely on subqueries that do just that.

But I feel like there should be some way to do it--since each row displayed does rely on one and only one record in the complete table of orders. Which obviously is the record I want to update.

Is there something I can do that will accomplish this? I really do not want to have to make the user open up another form to see last time or choose this time.

Thanks in advance!!

View 3 Replies View Related

Queries :: Complicated Query (nested Subqueries) For A Trend Graph

Apr 17, 2014

Some essential background first. I have a Balances table which records balances by date. I also have an Issues table where problems are logged. There is a one-to-many relationship between Balances and Issues (i.e. each Balance can have multiple Issues). I also have a Comments table where updates for each Issue are recorded. There is again a one-to-many relationship between Issues and Comments (i.e. each Issue can have multiple Comments)

There are two key date fields in the Issues table :FlagDate (the date an Issue was flagged by a user for investigation)

ResolveDate (the date said investigation was brought to a conclusion)

There is also a date field in the Comments table :UpdatedWhen (the date any given comment was added)

So the basic flow is that an Issue gets flagged (FlagDate), then various comments are added (multiple UpdatedWhen's) and finally the Issue gets resolved (ResolveDate)

I need to incorporate a trend graph which will show the counts ofNew (i.e. new issues flagged as of each day) Cleared (i.e. issues resolved each day)

Updated (i.e. issues not yet resolved but updated each day)

Unchanged (i.e. issues not yet resolved and not updated each day)

Outstanding (i.e. all unresolved issues as of each day)

This is the SQL I've put together to get that table of information on which to base my chart :

Code:
SELECT [tblBalances].[BalanceDate] AS AsOfDate,
(SELECT COUNT([tblIssues].[IssueID])
FROM [tblIssues]
WHERE [tblIssues].[Flag] = True
AND [tblIssues].[FlagDate] = [tblBalances].[BalanceDate]) AS New,

[Code] .....

The subqueries for 'New', 'Cleared' and 'Outstanding' work perfectly; the resultant dataset gives me one record for each date in the Balance table and correctly counts the number of issues falling into each of those buckets.

The problem I have is with the 'Updated' bucket. If a flagged issue happens to be updated twice on the same day (which is perfectly acceptable), it counts this twice as well. I don't want this as I just want to know how many issues were updated on any given day - not how many updates there were.

I tried using COUNT(DISTINCT) in the 'Updated' subquery but it gives me a syntax error - on further research, I don't think it's possible to use the DISTINCT keyword in a COUNT subquery (at least not easily)

I also tried grouping by IssueID within that 'Updated' subquery but it still gives me the duplicate count within the same IssueID (and returns nulls rather than zeroes for those days where no updates occured)

I think I need to add a subquery within the subquery () to only return the latest comment as of the date in question - something along the lines of :

Code:
(SELECT TOP 1 [tblComments].[UpdatedWhen]
FROM [tblComments]
WHERE [tblComments].[IssueID] = [tblIssues].[IssueID]
AND DateValue([tblComments].[UpdatedWhen]) <= [tblBalances].[BalanceDate]
ORDER BY [tblComments].[UpdatedWhen] DESC) AS UpdatedWhen

But how to do this, nor if it is even feasible in Access to begin with.

View 2 Replies View Related

Can Office Access 2003 Runtime-Based Solutions Applies To Access 2007?

Jan 29, 2007

Hello,

I have installed Microsoft Access 2003 and Microsoft Access 2003 Developer Extensions. I can create Access application by using the Package Wizard.
But after I upgrade from Microsoft Access 2003 to Microsoft Access 2007.
I can't use the Package Wizard.

How can I do to solve this?

Thanks.

View 1 Replies View Related

Automated Access Launch Causing Access Window To Fail To Hide

Jul 10, 2006

Hi,
I have been using "fSetAccessWindow (SW_HIDDEN)" in the open event of my
main switchboard to hide the grey Access screen from being visible behind
forms, reports, etc in this db. But when I started using a .vbs script file
to launch the db, the Access window stopped being hidden. (The reason I use
the script for launching is that it temporarily sets the db's security level
to 1 which stops the macro security warning from coming up.) Apparently MS
knows about this happening and released a technique to rectify the situation,
but I don't understand their instructions. It looks like they expect one to
have more understanding than I have. Could someone help me get this
impliemented? Here is the article:
http://support.microsoft.com/kb/167659/en-us
Thanks!

View 2 Replies View Related

How To Access Ms-Access WorkGroup Tables To Change Database Login Password

Apr 13, 2007

Hi!
This is Kishore, working on VB Project which is using MS-Access95 as backend.
Now, i want to change the Database login Password.
Could anyone guide me in this context.

Regards,
Kishore

View 4 Replies View Related

Using Access's User And Group Accounts Or Using A Login Form To Access Database?

Sep 9, 2005

Using Access's User and Group Accounts or Using a Login Form to access database?

I've been researching on how to make a database secure. How to create User and Group Accounts on access, I see the step by step instructions and tried it out myself.

I also saw some sites where they give an example of a Login Form and how to create one.

My question is do you need to create both. First create the users and groups to permit or deny access to certain forms and then have a login form?

But would that mean that they'd have to login twice? Once when the database opens because it activates the db security that was created and then login again in the login form that was created?

Also when the user logins in and clicks on the cmd button on the form which opens up another from, frmWorkLog, I have an Employee field. This field I want it to have the user's name entered automatically and "locked". So that info, employee name, is extracted from the user's login. So then the user can only see his or her records only and no one elses.

How would I go about creating that. Hope I made my explanation clear.

Thanks in advance.

View 3 Replies View Related

Locking User Access To Database Objects (MS Access 2000 And 2003)

Apr 15, 2007

I have two database applications and they are:
- the (A) application is for administration use.
- the (B) application is for normal users use.

the idea is that: I made the (A) application for administrators who have full control over the database objects (tables, forms, queries, and so on ...).

the (B) application I have created for normal users who will have only to use forms to insert some data and display data only.

but the two applications has a respective table called "vacation request" table. where I linked them, so the both administrators and users can share the data.

The real question is that: How can I prevent the users from seeing the database objects in their application. I used the database options which have helped me in hidding the database objectives when the users open the application, but unfortunately they managed to access to the database objects by pressing the special keys.

I would like to have an access to the (B) application when I want to make some modifications to the forms and then lock it from users where they only have to use the forms for requesting vacations and view the vacations.

View 1 Replies View Related

Remove Access Parameters Request For Simple Access Search Form

May 3, 2014

I have a simple access search form , that's based on a query that fill parameters from the form textboxes, when the access form loads its keeps prompting for parameters value which looks ugly .. I want to open the form, displaying all the records in the table and filter when i click search ..

I have a data entry entry form, that i want to generate success message after successful insert in database. I have done it in the button event if no error happens, still if i left all fields blank and clicked save, it displays the message ..

I need to change that to display please fill the textboxes then click save , and display success message when the row is actually inserted ..

Check the following attachment for sample.

View 14 Replies View Related

Forms :: Multi Select Listbox Access 2003 Code Gives Syntax Error In MS Access 2010

Oct 24, 2013

I've been using the following code successfully in Access 2003 & now I need to migrate to Access 2010. The purpose of the code is to use the items that the user selects in the list box to build the criteria of a query. Access 2010 keeps giving me a syntax error when I try to run the query & I don't know why:

My code is:

On Error GoTo Err_Command151_Click

' Declare variables
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String

[Code] .....

The syntax error I get in Access 2010 is:

Syntax Error in query expression 'SELECT * FROM
qryContractListSummarybyDateContract3TYPEBREAK WHERE
qryContractListSummarybyDateContract3TYPEBREAK.Rep ortableName IN('Adbri
Masonry NSW');'

View 12 Replies View Related

Table Problems Moving From Access 2003 -&gt; Access 2007

Jun 19, 2007

Attached is a screenshot of the relationships in a database I built a couple of years ago. It's worked absolutely fine in Access 2003 and currently has over 18,000 customers with associated information in it.

However, when I open the database in Access 2007 the performance is awful. All the forms are very slow to respond when tabbing between form elements. I've experimented by reducing the number of form elements calling on related data on a given page and whilst this improves performance it reduces usability - something I don't want to compromise on especially since Access 2007 should be able to cope with this.

My next question is therefore whether I've got the most efficient underlying table design and I can't see any other way of doing it than my current method so I'd be grateful for any feedback or advice anyone has.

View 2 Replies View Related

Importing Excel To Access Keeping Relationships In Access Tables

Sep 13, 2007

I have a stock control database which i have nearly completed. This has Manufacturer, which is linked to products, which is linked to Sub Product(which also has field partCode). i.e. Manufacturer1 can have 3 products, and each of these products could have 5 subsystems and partcodes. Each partcode is unique to that subsystem/product/manufacturer.

I then have a pricing spreadsheet in excel, which has many tabs. A new column has been added for each item for Manufacturer,Product,Subsystem and Partcode.

I need to import these manufacturers,products,subsystems and partcodes, but into the tables with the correct relationships, i.e. product1 and product2 are products of manufacturer1 and so cannot come under manufacturer2, and so on.

I hope this makes sense, Thanks in advance for any help you can give!

Emily

View 14 Replies View Related

Subform Referenceing Problem Between Access 2000 And Access 2003

Apr 19, 2005

I am working on a massave aplication that has been running in Access 2000, but recently several of the file sharing users have installed Access 2003 because of the limited availability of Access 2000. All the users are using the same file off the server.

The problem we are having is that when we reference a subform in the "[Forms]![FormName]![SubformName]![FeildName]" Access 2003 does not recognize it and returns an error. I have found that if I will modify it to "[Forms]![FormName]![SubformName].[Form]![FeildName]" it is recognized in both 2000 and 2003.

To try and change every instance of a subform reference will take forever and I am garuteed to overlook something. We reference subforms all over our program, missing any one of them would be a disaster. Before I went to the tedious task of looking through everything I just wanted to throw the situation out there and see if any of you had any great ideas on how to get it fixed efficiently. I would apreciate any ideas.

View 5 Replies View Related

General :: Only Open MS Access Form Without Access Running In Background?

Aug 7, 2013

I have made a form on access which will be used by other employees within the company, however they have never used access before and they are wanting to access only just the form as I feel with Access and all the tools in the background will confuse them, plus I don't want them editing the data base its self.

Is there a way to only bring up the form, unless I obviously need to edit the date base.

I've done some research on Google and it seems I need to use:

SW_SHOWMINNOACTIVE

However I can not seem to find how I would use this or where?

and also if i did find a way to only bring up the form, how would I be able to switch it from that veiw to the veiw I edit in?

View 2 Replies View Related

Upgrade From Access 2000 To Access 2003 Problem

Jun 6, 2005

I upgraded a 2000 db to 2003 recently. When I ran the function below it gave me an error on the line in green. Any thoughts? Thanks.
Const FIRSTROW = 13

Dim wsp As Workspace, dbv As DAO.Database, tblResolve As DAO.Recordset
Dim tblVchs As DAO.Recordset, tblImpTmp As DAO.Recordset
Dim ObjXLApp As New Excel.Application
Dim FileToOpen As String, WhereCriteria As String, ImportTemp As String, tmpVch As String
Dim TotalDupes As Integer, TotalGood As Integer, TotalRejects As Integer
Dim TotalBlank As Integer, R As Integer, C As Integer
Dim BadSheet As Boolean, ImpFail As Boolean
Dim tmp, tmpType, tmpCtr, tmpRsn


If Forms![Import Block Vouchers]![Import Program] = "0" Then
MsgBox ("You must select a Program to load.")
ObjXLApp.Quit 'Exit from MS Excel
Exit Function
End If

View 5 Replies View Related

Problems When Using A DB Created In Access 2002 (XP) In Access 2003

Jun 17, 2005

I have an Access DB that I created in Access XP. It works perfectly when used in Access XP. When used in an Access 2003 environment some of the functions don't work anymore. I have users who use Office XP and users who use Office 2003. Does anybody know how to make this DB work in Access 2003 without having to do wholesale code changes?

I have already changed the security to "Low" to bypass the security feature built in in Jet 4.0 but it didn't help. I might have to uninstall Windows XP SP2 to make it work because I know that the application works in an Office 2003 environment with Windows XP SP1 only. But I'm trying to avoid having to uninstall XP SP2 because it's a pain. Any ideas would be greatly appreciated.

Thank you.

My workstation environment is as follows:

OS: Windows XP SP2
Office: Office 2003 SP1
Jet: 4.0

Raneil

View 2 Replies View Related

Access 2003 Buttons Not Working In Access 2000

Sep 14, 2005

Hi,

I've created a database in access 2003 with the default file format being Access 2000. Everything works fine on my computer and many others, all of whom are running different versions of access (2000, 2002 & 2003).

I have not had any problems with this database until recently and in the last few weeks we have had 2 users, both of them being Access 2000 users who have had the same problem.

The problem they are having is that when they click on any of the switchboard items, the buttons depress an then come back up again when the cursor is moved away, but nothing else happens - no action, no error message - nothing!!! Its the same for all of the buttons on the switchboard.

Does anyone know what is causing this? I have another computer with Access 2000 on it and this works fine, as it does on several other computers runiing Access 2000, I just cannot understand why it is not working on these 2 particular machine.......

Many thanks in anticpation.

Steve

View 3 Replies View Related

Access 2003 Saves DB In Access 2000 Format?

Sep 20, 2005

I have recently installed access 2003 w/access 97 installed both are on my hard drive. When I create a new db in access 2003 it saves it in an access 2000 format. Does any one know why it does this?

Thanks--Appreciate any help

View 2 Replies View Related

Access 2000 Database Not Working Under Access 2003

Dec 7, 2005

i am trying to use access 2000 database onto to access 2003. When i try to click design mode to change something it gives me this message:

You dont have permissions to modify.

If i run it on access 2000 it runs fine.

Someone please help.

View 5 Replies View Related

Deploying Access 2003 Project In Different Access Versions

Dec 28, 2005

Hello,

I have two questions related to deplying an Access project I have been working on.

1. I started developing the project in Access 2000, but midway upgraded to Office 2003 and so the remainder of the project has been developed in Access 2003. Things seem to be fine, except that in the top most title bar, after the project name, there appears the following text:

xxxxx: Database (Access 2000 file format)

where xxxx is the name of the .mdb file.

Why is this appearing and should I have done something or do something to make it a Access 2003 format?

2. I am at the point of deplying the db to a small group of users (about 5). Some of them may have Access 2000 or Access 2002. Should I be doing something in particular to make sure things work in their machines.
Any pointers to what may be problems or what I should do will be much appreciated.

Thank you.

View 2 Replies View Related

User Access Denied In Access 2000 Runtime

Mar 11, 2006

We have two computers in a work group. On computer1 I have the back-end and front-end database files in the shared folder and 2 users out of 4 can access the database no problem. When the other users try to access the database they receive the error message "Microsoft Access can't Find The Database 'C:Documents and SettingsAll UsersDocumentsdb.mdb' Make sure you entered the correct path and filename" On computer2 I have the front-end database files in the shared folder and pointing to the same back-end database on computer1. Again 2 users out of 4 can access the database no problem. When the other users try to access the database they receive the same error described above.

I expect that this is some sort of windows permissions issue?
There are some clues to this fact ..
The two users that can't access the database are limited accounts, but I tried making them administrators and this had no affect.
Their shared documents folder does not have a hand underneath it?

Any help on this appreciated as it's really starting to annoy me now!

Thanks.

View 3 Replies View Related

Convert Access 2000 Database To Access 2003

Sep 27, 2006

Hi,

A few years ago I’ve made an access database on access 2000. The problem is that now I’ve installed the office 2003, and I can’t make the database work properly.

At first says that are missing those files: “tshoot.ocx”, “msioff9.ocx” and “msowc.dll”; so, I’ve copy them from another computer using office 2000 and now only complains about “msioff9.ocx” saying that my database contains a reference incomplete to it.

Is there no other way to convert my database do work properly with access 2003? What can I do?

Regards

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved