Sorting records on a form in MS Access 2010 - ms-access

I had a question last week about how to do a sort of ascending ID numbers by year for a SQL query.
Doing a secondary sort by year in a SQL query
I followed those instructions and the result was great for my table. The data in the resultant query was used to create a table that was then linked to a form. Unfortunately, as I add new records to the table, am I seeing that the sort is not respected after data entry (that is, new records are automatically displayed first when browsing records with the form instead of last). Is there a way to do a sort with ascending ID numbers and year within the form itself? When I try to use the ORDER BY year (date) expression in the form properties I'm getting an "undefined function in expression" error.

Since you already create a new table from the data, you could add a new column to that table containing the "year(date)" result. That way, you have a real column you can ORDER BY on. (ORDER BY yearcol, id)
When inserting, fill it with the current year.

Related

Restricting Table to one Row Only Access database

I have created a table which holds a date range like startdate and enddate.This is then referred to in query for the date criteria through a Dlookup. The table is filled through a form which is bound to this table.The problem now is if I change the dates,it creates another record in the table and this creates chaos on the query.How do I ensure that there is only one row in the table?
If you want only one record in table then edit existing record, don't enter dates into New Record row. Set form AllowAdditions and AllowDeletions properties to No.
Could instead of saving dates to a table, keep form open and have report reference form controls for criteria. This would also eliminate DLookup. Domain aggregate functions can slow performance.

MS Access Control Source DLookUp

I haven't been able to make a DLookUp function work in an Access report. I can't figure out what I'm doing wrong.
The report is getting its dataset from a query called Aggregate Query. This query builds a dataset from 20 related tables using CustomerID as the primary key in one table and as a foreign key in the other 19. CustomerID is specified by an open Form with the desired customer's record displayed, including the CustomerID field.
This means Aggregate Query has several rows for one specific CustomerID. One field, Needs Notes, will have the same content on every row. What I'm having trouble with is getting only one of these rows displayed in the subreport, and subsequently on the parent report.
If there are six rows, say, in Aggregate Query, then the same Needs Notes field is repeated six times. I want it to appear only once in the subreport.
I couldn't choose only the first row from Aggregate Query. If this can be done that'd be great. I don't know.
So I created another query, Need-notes Only Query, which always gives me only one row every time. So far so good. Now I want the contents of the Needs Notes field to appear all by itself in the subreport. To do this I selected the text box and entered the following into the Control Source parameter:
=DLookUp("[Needs-notes Only Query]![Needs Notes]","Needs-notes Only Query")
No dice. I get six rows saying #Error.
Is there a way I can get just one row of the Needs Notes field into my report?
Split field and table names:
=DLookUp("[Needs Notes]","[Needs-notes Only Query]")

Database structure for variable column names [duplicate]

I am writing a script which will counts the number of ticket as per as different conditions and store the count in a summary table. I am unable to understand how to structure my table since there will be more than 1 variables.
The script will run every week and with each execution a new week will be added. Once the new month starts and scripts execute, a new month will be added and once new year starts a new year will be added. So in a nutshell I have columns which are also variables. Not sure how to handle it and structure my db.
Have columns Date Service Count.
Like so.
Date Service Count
16 May 2016 Service1 35
Then when you go to display them in the report pivot them as you want. Probably better to make date an INT and either an auto number PK or composite PK of Date and Service.
Wrong approach. Do not splay an array across columns. Instead have rows for the data. This lets you trivially "add" another month.
For displaying, well that is an application problem, no a MySQL problem. Sure, you can write specialized queries to "pivot" the data from rows to columns, but it is messy.

Determine table based on prompt

PostPosted: 09 May 2014 22:26
Post subject: Determine table based on prompt
Hello,
I have three fact tables. First table holds current data, FACT_CUSTOMER_CURRENT. Other two tables hold historical snapshots. For example, one of these table holds last 60 days' records- FACT_CUSTOMER_DAILY. The other table holds data for the last day of the months.-FACT_CUSTOMER_MONTHLY
I want to add a date prompt. If the user selects yesterday as a prompt value, report should bring value from first table which holds current data (FACT_CUSTOMER_CURRENT). If user enters 28.02.2014, the report should retrieve data from FACT_CUSTOMER_MONTHLY. I tried to use context and aggregate awareness, but I could not be successful.
Can you help me?
Kind regards
There's no direct, easy way to do what you want.
Aggregate Awareness is useful for selecting a table based on the selection of objects in a query, but it does not support dynamic selection of tables based on values in a prompt.
If yesterday's data will only exist in fact_customer_current, then you can use this method: In your report, create a UNION query. One query includes objects from fact_customer_current, and the other from fact_customer_monthly. They both have an identical prompt on the appropriate date field. When a user enters yesterday's date, the first UNION query will return data but the second one won't. Likewise for date before yesterday, the first UNION will return no data but the second one will. This solution requires that the tables are correctly indexed such that a query on a date that isn't in the table will return quickly.

query to aggregat data by day to generate charts - rows unkown

I started building a search engine monitor. I'm pulling data from the google rest api into a mysql database with the following fields: date, search-keyword, domain, url, position.
Now I got into trouble querying and outputting the data for charting. The results go up and down, new results from google come into the list which haven't been there on the first day. However for charting I have to assign the first days at least blank values to output a chart.
What I do right now: First I select every domain showing up in the period. Lets say the for the keyword searchengine I get the domains wikipedia.org, ixquick.com, yahoo.com, searchenginewatch.com When I make another request for ever domain to query an array of rankings grouped by day. leading to the ...
Problem: Is where any query (mysql/nosql) which returns for each day an average and if where is no row a default value e.g. blank?
Result should look like:
dates={01/01/2014,02,03,04,05,06,07,08,...,31}
wikipedie={1,1,1,1,1,1,1,1,...,1}
yahoo = {"","",7,5,3,3,3,...,3}
You can create a date table, select the date range you'd like, and outer join your data to it, filling in 0s for values that do not exist for a given term/date.
Edit:
Some more details.
1) Create a table that has a row for every date +- 10 years (or whatever is appropriate). You can make this one column if you'd like, or many columns (date, month, year, etc.). The second approach makes this extensible if you want to summarize by various rollups in the future.
2) Outer join your table to the date table and use a NVL statement to coerce any null averages to 0.
3) Profit!
If your results are grouped by date, how can MySQL know there's (for example) 31 days in that month?
On the other hand, you can somehow fill the holes in PHP by loop through the array and fill a zero if the value does not exist.