Update Query Access - ms-access

I am trying to update a field inside one table, "Todays_Deliveries", from another table called "Current_Delivery". The field is a number field called "Remaining" which describes how many units there are of a particular item left on the daily deliveries.
The "Todays_Deliveries" table is generated using an APPEND query from another master table with every delivery stored in it. Everytime the user opens a delivery on a form anything in the "Current_Delivery" table is removed using a DELETE query and then generated based on the delivery selected using an APPEND query from the "Todays_Deliveries" table.
Both tables have identical fields and identical values, given one is generated from the data of the other.
I have tried to create an UPDATE query to update the "Todays_Deliveries" table when a user edits the "Current_Delivery" table but it doesn't work. I recieve no error messages the field just doesn't update. The steps I took were as follows:
Add both tables.
Change to UPDATE query.
Link tables using the Remaining field.
Set the Field: Remaining and
Set the Table: Current_Delivery.
Set Update To: [Todays_Deliveries].[Remaining].
Any advice/help would be greatly appreciated.
EDIT:
BEFORE:
Todays_Deliveries
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1900
Current_Delivery
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1000
AFTER:
Todays_Deliveries
ID Date Time Ref Studio Description Total Remaining
3187 23-Oct-12 10:00 3663 ROCK PINK 1900 1000
UPDATE:
I've got the query working using the below function
UPDATE Todays_Deliveries SET Remaining = DLookup("Remaining","Current_Delivery","[MP-Ref] = Form![MP-Ref] And [Cat No] ='" & [Cat No] & "'")
WHERE "[MP-Ref] = Form![MP-Ref] And [Cat No] ='" & [Cat No] & "'";
Where MP-Ref is the delivery reference that list a number of items, and Cat No is the individual item reference.
The only problem is the other items in the _Daily_Deliveries_ table, the ones not in the _Current_Delivery_ table, have there remaining field set to 0 when I run it. Is there anyway to stop this?

Related

Create a Custom ID in Access

I would like to create a Custom ID in format, "SACYear-Sequential Number", in an Access 2013 Table (Table Name = poledata) when records are appended into that Table.
eg. SAC18-1 (18 means 2018)
I have researched and found the code as below. As advised, I have to add 2 new fields in the Table, alternate_id_seq and alternate_id. However, errors show up for the following lines.
Expression = "SAC" & Year(Date()) Mod 100 & "-"
Look Up A Record In
Select pd.[alternate_id_seq]
FROM poledata AS pd
ORDER BY pd.[alternate_id_seq] DESC;
What's going wrong with them?

Access VBA - getting value of current record

I'm a very new user of Access 2016 - I have a form populated by a query, and I want to create a hyperlink out of one of the text boxes. The link should include the combined values of the workday and taskID fields for the specific record the user clicks on.
My problem is that I can't figure out how to get the value of the current record. The control source for these columns are the values themselves, retrieved via the query populating the form's record source. The following code creates the link I want, but it returns the same workday and taskID values every time, regardless of what I click on, and I can't figure out how to make it respect the current record. Any help would be greatly appreciated!
Private Sub workday_Click()
Dim link As String
Dim workday as String
Dim taskID as string
workday = Format(Me!workday, "yyyy-mm-dd")
taskID = Me!taskID
link = "http://myurl.com/" & workday & "/" & taskID
Application.FollowHyperlink (link)
End Sub
EDIT - hope this helps explain a little better
The main table driving this has workID (PK), Workday, taskID, StatusID, DateLastUpdated, UpdatedByUserID. The query used for my form selects all from this table and joins in metadata tables for Task, Status and User. There are multiple records with the same workday value and the same taskID, but never the same combination of the two. The form has a few filters in the header, and the bottom section is a datasheet. In the datasheet I have a combo box used to update StatusID, all other fields are disabled and locked. My hyperlink click event is on the Workday field, and is working in that it creates the appropriate URL, it's just populated with the same taskID and workday values, eg even if I click on the row for "2016-07-12" "456", I still return "2016-07-11" & "123"
Here's a simplified version of what the data looks like. My goal is that when the user clicks on a workday, they are taken to a hyperlink made up of both the workday and TaskID of the row clicked on.
Workday TaskID
2016-07-11 123
2016-07-11 456
2016-07-11 789
2016-07-12 123
2016-07-12 456
2016-07-12 789
2016-07-13 123
2016-07-13 456
2016-07-13 789
I think I actually solved it - the problem was that since almost all fields were locked and disabled, the current record wasn't technically the row I was clicking on. I set Enabled = Yes for the Workday column, and now it's working as expected.

How can I assign a number to each group and a total number of groups on the dataset to display

I have a dataset that is grouped by the CustomerId with multiple row information for each CustomerId.
I'm trying to create a numbering for each group (customerId) that gets created sequentially and then a total of groups.
So basically I am looking for the report to calculate that there will 5 groups here and then go 1 of 3, 2 of 3, 3 of 3 on the group header row (so I'm assigning a number of each CustomerId and seeing how many are on that Company)....
I have used the page breaks in the past for this but not possible this time around because I cannot break the pages. I have tried using RunningValue but not working so I'm lost here.
Header | Customer A 1 of 3
Details
Header | Customer B 2 of 3
Details
Header | Customer C 3 of 3
Details
Say I have data like this:
And a simple table with a Group based on Customer:
The expression I'm using in the group header row is:
="Customer " & Fields!Customer.Value & " ("
& RunningValue(Fields!Customer.Value, CountDistinct, Nothing)
& " of "
& CountDistinct(Fields!Customer.Value, "DataSet1") & ")"
Which is using a couple of aggregate functions and using these to create a longer string with the Customer detail.
You can see that using CountDistinct is the key here - it's used in RunningValue to get the group ranking and also as an aggregate expression by itself to get the total in the Dataset (where DataSet1 is the Dataset name).
Results look good:
You will of course need to tweak slightly for your field names and your exact formatting requirements.

Microsoft Access 2010 - Filtering by a caculated field in a query-based report

Ok, here's the condensed form. I have three main tables to draw data from:
StudentData - PK is the student's ID Number. Contains contact info, their current status ('00' for none, 'P' for Probation, 'S' for Suspension), and cumulative gpa data.
CourseData - PK is the CRN. Contains just the abbreviated subject and the course number (IE ECON 200)
StudentCourses - PK is an AutoNum. Many-to-Many relationship table between StudentData and CourseData. Also contains stats for the particular student's class (grade, credit hours, etc).
So some sample data would look like:
-
StudentData
ID: 12345678
Name: John Doe; ...[Other contact info]; 00; CumCreditHours: 100; CumCoursePoints: 190
-
CourseData
CRN: 0001; Abbrev: ECON; CourseNumber: 101
CRN: 0002; Abbrev: CSCI; CourseNumber 201
-
StudentCourses
AutoNum: 1
StudentID: 12345678; CRN: 0001; Grade: A-; Credits: 3
AutoNum: 2
StudentID 12345678; CRN: 0002; Grade: B; Credits: 3
-
At this point, this is how I have things set up:
First, a query runs that finds all of the courses a student takes and converts the letter grades into a point value. Another query based on the first sums the point totals and the credit hours. A third query takes those totals and calculates the GPA by dividing their point total by the credit hour total.
Separately, a query runs that calculates the student's cumulative GPA by taking their cumulative points and hours from the StudentData table (again dividing the points by the hours).
Then, another query takes both the semester GPA, cumulative GPA, current status, and cumulative credit hours and calculates the recommended action for the student. So for our example data it would look like:
_
SemesterGPA: 3.33; CumulativeGPA: 1.90; CurrentStatus: 00; CumulativeCreditHours: 100
_
I have the formula to determine their recommended action set up as a series of nested IIF statements that looks like:
IIf([CurrentStatus]="00" And [CumulativeGPA]<2 And [CumulativeCreditHours]>=12 And [CumulativeCreditHours]<=23,"PFY",IIf([CurrentStatus]="00" And [CumulativeGPA]>=1.7 And [CumulativeGPA]<=1.99 And [CumulativeCreditHours]>=24,"P",IIf([CurrentStatus]="00 " And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]<12,"W",IIf([CurrentStatus]="00" And [CumulativeGPA]>=2 And [CumulativeGPA]<=2.5 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"WUP",IIf([CurrentStatus]="00" And [CumulativeGPA]<1.7 And [CumulativeCreditHours]>=24,"SUSP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]>=2 And [CumulativeCreditHours]>=12,"CP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"SPCP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [CumulativeCreditHours]>=12,"RP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,IIf(IsNull([PriorSuspension]),"S(FD)","D(SD)"),"None")))))))))
For our example, John Doe's recommended action would be 'P' since his current status is 00, he has over 24 cumulative credits, and his cumulative gpa is between 1.7 and 1.99.
Now for the problem: I would like to be able to make a report that can filter by the recommended action. I've detailed the issues I've had previously, but in short, the way I have the reports set up now (with the information being displayed in a sub-report inside a report that is based on the StudentData table to provide the aforementioned queries with the StudentID) doesn't allow me to do this because the field I want to filter by exists in the sub-report and not the main report (and you can't set the filter properties for a sub-report).
Any ideas?
Ok, I've got this to work now. I realized that as I was calculating the semester GPAs that I had grouped the results together by ID at some point during the process. This allowed me to remove the part of the initial query that grabbed the ID number from the form. Since the last query in the process linked everything together by student ID, the individual records held all of the information I needed and everything fell into place after that.
I half expected something simple like this to be the answer to my problem, but I'm still disappointed that it took me this long to figure it out...
Anyway, thanks to anyone who might have been thinking of possible solutions for this problem.

Move data from field to field in MS Access

In MS Access I have a table like this:
TABLE USER
Id (int)
Status (text)
OldStatus (text)
I would like to create a MS Access Query which, when executed, moves the content of Status field to the top of OldStatus, and adds the current year. For example:
Before execution:
ID STATUS OLDSTATUS
1 Very good [2010] Excelent
[2009] Very bad
2 Excelent [2010] Bad
[2009] Good
After execution:
ID STATUS OLDSTATUS
1 [2011] Very good
[2010] Excelent
[2009] Very bad
2 [2011] Excelent
[2010] Bad
[2009] Good
How can I do that? THANK YOU!!
Didn't know the name of your table, so you'll have to substitute. The goal here is to maintain the old status while concatenating the current status. I used a space (" ") to put between, but you can use any character you want.
Update Status_Table
Set OLDSTATUS = OLDSTATUS & " " & STATUS
For what it is worth, there is a better way. Create a StatusHistory table:
StatusHistoryID
, StatusID
, Status
, Status_Date
You would have more flexibility here. Reports could be set for a date range or a particular year. You're table would be very hard to run a report on the status for 2010.