Access 'No Records Found' when Records Exist - ms-access

I have a form in Access 2010 that's used as a search form to filter records matching specific criteria.
I transferred information in the backend from one set of tables to another. Now, the filter doesn't work. Even if I leave all the criteria blank - ie. set it to bring up all records - it tells me, 'No records found.'
I've remapped the tables a few times, made sure they all have information, and are linking and opening properly. What could be preventing Access from finding the records?
Here's the filter query, if it helps any. It doesn't appear to be filtering properly, even though it works fine with the old tables.
SELECT Activity.*, ActivityCash.*, EngSchDates.*, Monitoring.*, Procurement.*,
LookupDistrict.*
FROM ((((Activity LEFT JOIN LookupDistrict ON Activity.District =
LookupDistrict.District) INNER JOIN ActivityCash ON Activity.GWP = ActivityCash.GWP)
INNER JOIN EngSchDates ON Activity.GWP = EngSchDates.GWP)
INNER JOIN Procurement ON Activity.GWP = Procurement.GWP) INNER JOIN Monitoring ON
Activity.GWP = Monitoring.GWP ORDER BY Activity.District,
Activity.[ProgramYear], [Activity].GWP;

In general, to debug these types of problems, try removing one table at a time from the FROM clause (and SELECT) until you get your results back.

Remove AND [Activity].[Designer] like '*' from the query.

Related

How to query for something that doesn't exist?

I am trying to query a sample database to look for sites without a domain.
We know which site a domain is associated with by domains.site = sites.id. There is no similar variable from site to domain.
So, I tried this (and a couple other joins / where filtering). Either, it's outputting about 50x the number of actual number of entries for either table, or it's outputting nothing. (This one's the former)
SELECT sites.name, domains.domain FROM sites
INNER JOIN domains
ON sites.id != domains.site
WHERE sites.is_deleted = 0 AND sites.id != domains.site
And this one's an example the latter, which outputs nothing
SELECT sites.name, domains.domain FROM sites
LEFT JOIN domains
ON sites.id != domains.site
WHERE sites.is_deleted = 0 AND site = NULL
I'm clearly missing something, to be able to go through the combinations, where only the site name and NULL are outputted (due to there being no domains associated with the site).
Of course, it could be a trick question, and there are simply no sites without domains.
For your kind of query you need to start with the query that should work if the data existed, using a LEFT JOIN, then add the condition that the data don't exist. So:
SELECT sites.name, domains.domain FROM sites
LEFT JOIN domains
ON sites.id = domains.site /* <--- this is where you got it wrong */
WHERE sites.is_deleted = 0
AND domains.site IS NULL;

Access Report from Query inexplicably multiplies columns

I have a weird problem. First off, I'm not well versed in Access, but I'm using it for a project to track visibility of log sources and detections and map them to the MITRE ATT&CK Framework. I tables such as Techniques to track the MITRE Techniques, Data_Sources to track the various sources used by those Techniques, and Data_Sources_Coverage that has a visibility ranking for each data source for the company. I have a query built with the below SQL (probably a little messy):
SELECT Technique.Name, Technique.ID, Technique.[Tactic ID], Count(Technique.[Data Sources].Value) AS Technique_Sources, Count(Data_Source_Coverage.[Data Source]) AS Sources_Visible
FROM (Data_Sources INNER JOIN Technique ON Data_Sources.Name = Technique.[Data Sources].Value) INNER JOIN Data_Source_Coverage ON Data_Sources.Name = Data_Source_Coverage.[Data Source]
WHERE (Data_Source_Coverage.Coverage)>0)
GROUP BY Technique.Name, Technique.ID, Technique.[Tactic ID];
The query works great, prints the results as I expect them. However, when I generate a report from that query things go off the rails. The report inexplicably (I did nothing to the data), multiplies the Technique_Sources column by the Sources_Visible column and displays that in the Technique_Sources Column, and then every entry in the Sources_Visible column becomes a '1'. Pics below. Thanks for the help.

Listbox is not able to show items based on another list

I am currently trying to set up a GUI frontend for easier querying for colleagues.
I have tried researching and following instructions from various sources but still not able to make it work.
I have two lists.
1) This is the row source query for the first list(List0):
SELECT Test_Case_ID.Test_Case_Unique_ID, Test_Case_ID.Test_Case_Description
FROM Test_Case_ID
ORDER BY Test_Case_ID.[Test_Case_Description];
2) This is for the second list(List2):
SELECT Reference_ID.Reference
FROM Test_Case_ID INNER JOIN (Reference_ID INNER JOIN Test_Result
ON Reference_ID.Reference_Unique_ID = Test_Result.Reference_Unique_ID)
ON Test_Case_ID.Test_Case_Unique_ID = Test_Result.Test_Case_Unique_ID
WHERE (((Test_Case_ID.Test_Case_Description)=[Forms]![Form1]![List0]));
I have a an event procedure for List0:
Private Sub List0_AfterUpdate()
Forms![Form1]![List2].Requery
End Sub
However, there are no outputs on List2 even after clicking on items in List0. Can I have some advice to fix it? Thank you
Firstly, check that the bound column of your list box List0 corresponds to your Test_Case_Description field.
With the form open and populated with data, you can also run a number of tests 'manually' by creating a separate query containing the SQL for your list box row source and verifying whether or not it returns any results:
select
reference_id.reference
from
test_case_id inner join
(
reference_id inner join test_result
on reference_id.reference_unique_id = test_result.reference_unique_id
)
on test_case_id.test_case_unique_id = test_result.test_case_unique_id
where
test_case_id.test_case_description = [forms]![form1]![list0]
You can also use a query with the following SQL code to test the value returned by [forms]![form1]![list0] and ensure that it returns the value that you expect for use in your selection criteria:
select
t.test_case_description,
[forms]![form1]![list0] as listboxvalue,
t.test_case_description = [forms]![form1]![list0] as testmatch
from
test_case_id t

Query in access not returning correct result due to join?

I'm having a bit of difficulty wrapping my head around some queries that I need joined correctly to each other, in order to get the correct result.
Basically I got a database with a sewage network in it, the network has manholes with IDs and pipes with IDs, all pipes are defined with one UpstreamManholeID (OpstroemKnudeID) and a DownstreamManholeID (NedstroemKnudeID) (Knude table = manhole).
When I try to make a query based on observations in the pipe, I keep getting the same PipeID listed for pipes with different Upstream and downstream ID. As shown in the picture below, probably because it only checks for the upstream manhole id before choosing a pipe id.
I tried changing the query, but that returns blanks in the PipeID instead.
To sum up, I need to list the PipeID based on both upstream and downstream node, as it is, I can only get it to check for either upstream or downstream.
I'm having a hard time explaining, so feel free to ask any clarifying questions you need.
At the moment I'm running two queries, one calling the other, in order to get the almost correct result.
SELECT TVInspektion.Startpunktnr AS OpstrømsKnudenavn, TVInspektion.Slutpunktnr AS NedstrømsKnudenavn, Knude.ID AS OP, Knude_1.ID AS Ned
FROM (TVInspektion LEFT JOIN Knude ON TVInspektion.Startpunktnr = Knude.Knudenavn) LEFT JOIN Knude AS Knude_1 ON TVInspektion.Slutpunktnr = Knude_1.Knudenavn;
SELECT [Copy Of Vurderes].OP, [Copy Of Vurderes].OpstrømsKnudenavn, [Copy Of Vurderes].Ned, [Copy Of Vurderes].NedstrømsKnudenavn, Ledning.ID
FROM [Copy Of Vurderes] LEFT JOIN Ledning ON ([Copy Of Vurderes].Ned = Ledning.NedstroemKnudeID) AND ([Copy Of Vurderes].OP = Ledning.OpstroemKnudeID);
That returns the following result:

Change Tracking in SQL: NULL value when using COLUMNPROPERY

I'm attempting to write a SQL query that monitors changes on a table using CHANGE TRACKING.
My query is working up to the point that I want it to also monitor which columns have changed.
I'm getting a null value on COLUMNPROPERTY which I suspect means I don't have the correct permissions. This is the first time I've attempted this type of query so would appreciate any guidance on where I've gone wrong.
Many thanks
Jodie
SELECT
CT.TableCalendar,
P.txtDescription, CHANGE_TRACKING_IS_COLUMN_IN_MASK (COLUMNPROPERTY(OBJECT_ID ('P'), 'txtDescription', 'ColumnID'), CT.SYS_CHANGE_COLUMNS) changeDescription,
P.txtStartDate,
P.txtStartTime,
P.txtEndDate,
P.txtEndTime,
P.txtLocation,
P.intAllDayEvent,
P.intCategory,
P.intSubcategory,
P.txtCreatedBy,
CT.SYS_CHANGE_OPERATION,
CT.SYS_CHANGE_VERSION,
CT.SYS_CHANGE_COLUMNS,
CT.SYS_CHANGE_CONTEXT,
U.txtFirstname,
U.txtSurname
FROM
[dbo].[TableCalendar] AS P
RIGHT OUTER JOIN CHANGETABLE(CHANGES [dbo].[TableCalendar], #last_sync_version) AS CT ON P.TableCalendarID = CT.TableCalendarID
INNER JOIN [dbo].[TableUsers] AS U ON [txtCreatedBy] = U.txtUserCode
This query was correct, unfortunately the application I was trying to track changes on was written in a way that meant if you edited one field it updated all of them in that table.