Dynamic Sequencing of data in MS Access Reports - ms-access

So, I have this Report:
And this Query:
The report pulls all of it's data from the query. The fields STA1, STA2, STA3, and STA4 are from the Job Order table in which each job has an order set based on Work Stations (Named CU01, CU02, BR01...).
I have attempted to make macros that essentially say
If Reports![Production Router LBPW]![Work Station 1]="CU01" Then Reports![Production Router LBPW]![Run Time 1]=Query![Query Laser Hours by P/N]![Total Laser Hours]
If I understand properly, a series of statements like that could essentially associate each work station with a specific type of time data (Cutting, Bending, Inserting, and Welding), effectively rearranging my fields to automatically display the time data I want in the places I want them. Alas, I don't know enough about macros to make that work and I know even less about VBA. If I can be filled in on a couple lines of code, or something, that would allow me to accomplish this, I'm sure I may be able to figure it out from there.

One approach would be to create various queries, for example:
QueryCU01
SELECT [Cuttime] As Pos1, [Weldtime] As Pos2, [Rivettime] As Pos3, Bend As Pos4
FROM JobOrder
You report would then refer to Pos1, not CutTime. The labels could also be textboxes, so they update automatically as well, for example:
SELECT [Cuttime] As Pos1, "Cut" As lbl1, [Weldtime] As Pos2, "Weld" As lbl2
[Rivettime] As Pos3, "Rivet" As lbl3, Bend As Pos4 "Bend" As lbl4
FROM JobOrder
It is possible that you could simplify further by normalizing your tables.
Tasks table
Job Action Time Machine SortOrder
1 Cut 10 AB 3
1 Bend 4 CD 1
1 Rivet 30 EF 6

So, what I've done is use a series of Switch functions in my query so that the data that is pulled into each query is inserted into each field by a logical statement. For operation name, the logic is as follows:
OP2: Switch([ST2]="PE01","Insert",[ST2]="PE02","Insert",[ST2]="BR01","Bend",[ST2]="BR02","Bend",[ST2]="WE01","Auto Weld",[ST2]="WE02","MIG Weld",[ST2]="WE03","TIG Weld",True,"N/A")
Which essentially means, If ST2=PE01, Then OP2=Insert, elseif ST2=BR01, then OP2=Bend...
Then I set up another swith that says If OP2=Bend, Time2=BendTime... So on and so forth. This way each field contains a value that is entered based on the logical statements and the order of the jobs is determined by the order that I've set when I enterred the station names in the Job Order Table.

Related

Access 2013 Count

I am working on a report in Access 2013 I need to seperate the first 20 records in a column that contain a value and assign a name to them. Such as at 1-20 I need it to insert Lot 1 at 21-40 need to assign Lot 2 etc... The report needs to be separated by lots of 20. I can also just insert a line when it reaches sets of 20 without a name if that makes it easier. Just need something to show a break at sets of 20.
Example: As you can see the report is separated by welder stencil. When the count in the VT column reaches 20 I need to enter a line or some type of divider to separate data. What our client is asking for is we separate the VT in sets of 20. I don't know whats the easiest way to accomplish this. I have researched it but haven't found anything.
Example Report with Divisions
Update the report's RecordSource query by adding "Lot" values for each row. There are multiple ways of doing this, but the easiest will be if your records already have a sequential, continuous numerical key. If they do not have such a key, you can research generating such sequential numbers for your query, but it is beyond the scope of this question and no details about the actual data schema were supplied in the question.
Let's imagine that you have such a key column [Seq]. You use the modulo (mod) and/or integer division operators (\ - backslash) to determine values that are exactly divisible by 20, e.g. ([Seq] - 1) mod 20 == 0.
Generate a lot value for each row. An example SQL snippet: SELECT ("Lot " & (([Seq] - 1) \ 20)) As LotNumber ...
Utilize Access report sorting and grouping features --grouping on the new Lot field-- to print a line and/or label at the start of each group. You can also have the report start a new page at the beginning or end of such a group.
The details about grouping can be found elsewhere in tutorials and Access documentation and are beyond the scope of this question.

What ID does a ComboBox reference?

I am attempting to maintain and fix a horribly out-of-date CRM designed by an ex-employee ~4-5 years ago in Access 2007. I have brought it into Access 2013 and fixed a ton of stuff up, but I am still running into many problems.
I spent a good 4 hours today attempting to figure out why certain values didn't line up. These values were being pulled from a SELECT statement on a Combo Box over a stored Query which simply returns a table with a few extra rows. Great.
However this value (a number) doesn't appear to correlate with what we expect. I enter in one value, save the ticket, and a completely different value gets stored into the table. Opening up the ticket, I see the value that I expect. Digging deeper, I found the following difference:
Set value_1 = Me.RegistrationID // What's being stored in the table
Set value_2 = Me.RegistrationID.Column(0) // What we expect
Surprise surprise! This is a Combo Box and some value is being stored in the table. The Control Source is "RegistrationID" and the Row Source is the query in question.
However I do not know what it is! This specific value correlating to the Combo Box appears to pull the correct data when we later open the tickets. However I have a strong feeling that this could be why many tickets from before one of the rows was deleted all appear to have invalid RegistrationID's.
How badly can this break?
How easily can we correct tens of thousands of tickets?
How can I fix this to store the correct value?
This is what I expect is happening.
Your combo box row source is based on a Select query which returns and displays multiple rows. For example:
Select RegistrationID, CustomerID, CustomerName From MyTable;
The Control Source for the combo box is bound to RegistrationID which is part of the Forms Record Source.
The issue is the bound column. If we set the bound column in our example to 1, then we get the behavior your are describing with:
Set value_1 = Me.RegistrationID - Set's value to CustomerID (may appear correct)
Set value_2 = Me.RegistrationID.Column(0) - position 0 from our query (RegistrationID)
Further building on our query example, you can say:
Me.TextBox1 = Me.RegistrationID.Column(0) - RegistrationID
Me.TextBox2 = Me.RegistrationID.Column(1) - CustomerID
Me.TextBox3 = Me.RegistrationID.Column(2) - CustomerName
The RegistrationID is what normally should be stored in the table.
As long as your form shows any values that directly relate to this RegistrationID you're fine.
I would start by checking to see under the format setting to see if column widths are set properly and I would also check under the data section to see if the bound column is correct. I might also throw in an after update macro/vba sub routine that saves the record. Hope this helps.

Sum Values from Dataset based on condition: Report Builder

I have a report where users can select items from various location. And I have 3 datasets performing calculations where the third dataset takes the sum where item number is 4942200 and then calculates the values (as shown below):
=SUM(IIf(Fields!masterno.Value= "4942200",Fields!Owned.Value,0))+SUM(IIf(Fields!masterno.Value= "4942200",Fields!Subbed.Value,0))
This is returning error for some reason. The subbed column is toggled based on parameter (visibility). But before I add the toggle functionality, I want to make sure this is working. Can anyone help. I have also tried:
=SUM(IIf(Fields!masterno.Value= "4942200",Fields!Owned.Value+Fields!Subbed.Value,0))
This seems to fail as well. Help would be greatly appreciated.
I would wrap a CDec around Owned, 0 and Subbed, e.g.
=SUM(IIf(Fields!masterno.Value= "4942200",CDec ( Fields!Owned.Value) ,CDec (0 ) ))+SUM(IIf(Fields!masterno.Value= "4942200",CDec (Fields!Subbed.Value ) ,CDec ( 0 )))
If Owned and Subbed are already Decimals, those CDec's may be redundant. On the other hand SSRS doesnt expose this info and they can change at the whim of the data source.

MS Access Query using IFF to compare values

I am trying to build a query which will look at the data in two fields in two different tables and check to see if the data is the same, if it is I want it to return the number of times it is matched, if it isn't I simply want it to return the text saying "No viewings".
I have constructed this query in my access database which has the field from the first table "Property" and the second field I want it to compare the data with, "Viewings". I have build the following expression using the build tool, however I am stuck to make it work since every time I get this error message when trying to run the query: "Your query does not include the specified expression 'Property Viewed' as part of an aggregate function."
totalViewings: IIf([Viewings]![Property Viewed]=[Property]![ID],Count([Viewings]![Property Viewed]=[Property]![ID]),"No Viewings")
Any help how to overcome this error would be very appreciated.
Thanks
I would suggest doing something like this:
1) Assuming this is something you are developing yourself, make sure your data structure is all in order first. Since I dislike relatively code-hostile identifiers, I'd have the tables as so -
Properties - PropertyID (AutoNumber, primary key), HouseNumberOrName, Street, etc.
Viewings - ViewingID (AutoNumber, primary key), PropertyID (Number/Long Integer), ViewingDate, etc.
In the Relationships view, Properties.PropertyID would then be set up to point to Viewings.PropertyID in a one-to-many relation.
2) Your actual query I would then break into two, the first to compile the data and the second to format it for display. The first would go like this, saved as ViewingCounts...
SELECT Properties.PropertyID, Count(Viewings.PropertyID) As ViewingCount
FROM Properties LEFT JOIN Viewings ON Properties.PropertyID = Viewings.PropertyID
GROUP BY Properties.PropertyID;
... and the second like this, saved as ViewingCountsForDisplay:
SELECT Properties.*, IIf(ViewingCount = 0, 'No viewings', ViewingCount) AS Viewings
FROM Properties INNER JOIN ViewingCounts ON Properties.PropertyID = ViewingCounts.PropertyID
ORDER BY Properties.PropertyID;

grab mysql result based on field values

I am taking over designing a CMS from another programmer. As the site is filling up, we're finding loops in mysql queries causing long hangs. I have found a temp solution for this one, but am wondering if there is a quicker way of doing it?
take the table (tracks resources):
id resource click
1 res_1 192
2 res_2 12
3 res_3 300
what we need to get is a popularity of the resource - res_click/total_click
what he had was a while loop:
while ($item = mysql_fetch_array ($result)) $total_clicks = $total_clicks + $item[0];
As there could be 100 or more resources to a page, this was running for each resource, and it is causing major hangs.
My solution is to get a sum:
SELECT SUM(click) FROM uri
SELECT click FROM resource WHERE id=$x
then divide them both.
But this two calls are still running for around a 100 items per page. Is there a way I can have a field in mysql that is the result of a formula based on another another, like in excell? So I could add a field "percentage", tell mysql that it is the sum of click divided by the current click value, then every time click is updated the 'percentage' field is automatically updated?
any help would be appreciated,
cheers ;)
you can create a view on your table that present the sum you want