I have a form of multiple project sites where one of the fields is labelled "Project Start Date". I have another field in the form labelled "Projected Project Finish Date". Both fields are stored in a table labelled "General Project Info" (well, at least that's the source of the information for the form come from).
I could manually fill in the Proposed Project Finish Date by adding 10 days to the Project Start Date, but I would like to make it a calculated field, i.e once someone puts in the Project Start Date Access automatically calculates the Proposed Project Finished Date.
I am aware you can use a query to calculate this: New Query-->Include Project ID and Project Start Date fields, then make the third field--> Proposed Finish Date: DateAdd("d",10,[Project Start Date]). This produces a query result which has a column with all the sites, a column with the Project Start Date and a column with a date that is 10 days later. Perfect. But, how do I store those new results in my existed General Project Info table and have them appear in the form? I'm obviously a beginner and am missing something.
Thanks for any help in this matter.
Oh, I am using Access 2007.
You can use the After Update event for Project Start Date on your form to update the Project End Date control to Project Start Date + 10, but if the answer is always + 10, why store the date at all? Just use your query to show the end date.
Private Sub StartDate_AfterUpdate()
Me.EndDate = Me.StartDate + 10
End Sub
Or
SELECT StartDate, StartDate + 10 As EndDate FROM ATable
Edit
To add an After Update event, use the property sheet in form design view. Select [Event Procedure] and then click the three little dots. It will open up the code window and you can add code into the event. You will need to use the proper names for you controls, but if you type Me., intellisense will help you along with names of properties, methods and controls.
Related
So I am creating a database to track projects. In it I have several milestones. On the form each milestone has a label and a textbox next to it. The project manager will go in and type the date of that milestone.
What I need to do is based on the textbox that date is typed in it will save date and milestoneID to a table.
If you look at the Form and Table images attached:
You see on the form they enter the date next to milestone.
On the table you see the each date gets a schedule ID (autonumber), the projectID gets assigned to it (another table), and then the milestoneID(phaseID) followed by the StartDate. Ignore the end date. I need that schedPlanPhaseID to fill in based on which text box then entered a date in on the form.
I am still very new to SQL and access so sorry if I miss something obvious.
Form Image
Table Image
I'm creating an Access database to try to track average cost of inventory. I want to make it to where when a button is clicked on the form a column is added to the table that is named with the current date and the word Quantity and another column is added with the current date and the word Price. I can't just add columns named quantity and price because I am hoping to be able to use this over time. So I want to know on mm/dd/yyyy we bought x widgets for y dollars a piece. Then a week later I want to be able to hit the same button and add more lines with the new current date. Is this even possible? I'm using Microsoft Access 2016. I've tried the following with some variations based on what I've researched but nothing seems to work. AvgCost is the table name. Also I'm very very new at this.
Private Sub Record_Button_Click()
ALTER TABLE AvgCost ADD COLUMN Quantity_DATE()
End Sub
I keep getting an error message reading "Compile Error: Expected: ENd of Statement and it highlights AvgCost
Can't run an SQL action in VBA like that. Certainly won't create a field with a date in field name. Need to call a command and concatenate date value.
CurrentDb.Execute "ALTER TABLE AvgCost ADD COLUMN Quantity_" & Format(DATE(), "yyyymmdd") & " Number"
However, this really is poor design. Instead of implementing procedure that routinely changes database structure, should be adding records.
I am trying to create two fields in Microsoft Word. One that has a "created Date" (that I can manually enter) and the second that calculates the difference in days from created date to today's current day. It is to allow me to see how long an item has been worked on as I am using trying to build a schedule in word.
I am assuming a Macro needs to be created but I can't find any clear examples anywhere.
Thanks for your help
I have a tbl_ProjectList that includes the project's Name and End Date.
A qry_cboProject queries this table to only display projects in a combobox on Subform A where the End Date is after the selected date on Subform B, both on Mainform C.
On Subform A, a macro copies (INSERT INTO SQL) projects from Subform B's previous months into the new months. However, if an out-of-date project gets copied over to a new month, the combobox field would be empty for that record, even though the Key exists on the back-end.
I've tried playing with the combobox's properties on Subform A by changing the Bound Column, Column Count, Column Widths, and Limit To List, but am only able to get the out-of-date project to display by its Key, rather than its Name.
The front-end reasoning for this macro is that employees do not have to repetitively select the same projects for each month, and employees already working on out-of-date projects may still need to put in some hours to close out the project.
Does anyone have any suggestions? Thank you in advance!
The order in which fields show up in you combo box depends on how the control source is querying the information i.e. to get name and not the key to show up in a combobox using the a control source query like the following:
SELECT Key, Name FROM tbl_ProjectList
You would need to set the following attributes:
Column Count: 2
Column Width: 0"; 2"
Bound Column: 1
It sounds like you may need to requery the control source as well. This should cause all the information to update.
#Parfait - apologies for not describing my problem in more detail. There are multiple subforms on one main form to allow the user to select a date in one subform, which populates projects on a second subform and responsibilities on a third subform.
Jeffrey's suggestion made me realize that the underlying query to the combobox should be adjusted for projects that are carried over into new months, where a foreign key exists in the underlying tbl_ProjectUserEntry
Therefore, I added a WHERE criteria to the query, which uses a DLookUp function to see if the foreign key exists:
DLookUp("[DateID]","tbl_ProjectUserEntry","[DateID] =" & Forms.frm_UserEntry.tbDateID) IS NOT NULL
frm_UserEntry is the main form..
Again, apologies for my brief description to a complex problem.
Following on from this question, how would I go about writing the resulting date value to the field (DEADLINE (25 WD)) which is located in a form?
(The field is located in the form which is linked to a table.)
The real solution is to not store this "calculation", but use it when and where required. Calculations belong to Queries not in Tables. The reason why it is best to use in Queries than storing in tables using Form method is because, when the DateOpened is changed the Deadline is automatically updated. BUT this happens only if you are using the Form to edit the information. If you are editing the date directly in the table or using a Query to Update the record, the Deadline will not be consistent.
However, if you use a query like
SELECT
DateOpened,
addWorkDays(25, DateOpened) As Deadline
FROM
yourTable;
This will work based on the DateOpened, as when the Query is run. Even if it gets changed in the Query (while it is open), the Deadline will be updated accordingly. You loose this flexibility when you use a Form to store calculations back to the table.
That being said, as your need is to calculate this based on another field; I would suggest that you make use of the AfterUpdate event of the DateOpened control.
Private sub DateOpened_AfterUpdate()
If Len(Me.DateOpened & vbNullString) <> 0 Then
Me.DeadlineDate = addWorkDays(25, DateOpened)
Else
Me.DeadlineDate = ""
End If
End Sub
Since the control is bound to the table, there will be no need to run an update code. This will automatically have the deadline filled in.