Sorting Fields In access by the time they were entered - sql

What I have here is a table with some text fields. I basically put in the name of some students into a table. I got their info from forms that teachers had sent me. When I put their names into the database, I just put the names in based on which form was at the top. Does access track the actual time that a field was put in in such a way that I could sort my text fields by that so that when I give a list of what I just did to someone else, they won't have to sort through the stack of papers to make sure all of the papers are there?
I should add that I need to track this for an individual field, not just for the record. For instance, let me take this one piece of paper I have. When I get it from an outside agency, I then put it into the database with the student's name and some info. I then need to send it to the teachers for them to sign and send back to me. I am on the second part so the record had already been created, but I want to find the date that I entered the Date_signed field basically.

In this example, you set the default value of the dtmEntered field to Now()
p.s. Same answer as HugoLemos but with a pic :)

You can use a Date/Time field with its default value = Now() to store the time each record is created, as already suggested. That approach works fine when only one user can be adding new records, which sounds like your situation.
If you wish to also store the time an existing record is changed, you can do that from a form's before update event.
This example assumes a text box named txtLast_change which is bound to a Date/Time field in the form's record source. The text box does not have to be visible to the user for this to work.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.txtLast_change = Now()
End Sub

Create a field with a date type and set default value to Now()

As you have discovered, there isn't any way after-the-fact to know when data was entered in to your table, as it's not something that you captured in the first place. As you mentioned in one of your comments, you can determine the order in which you entered new records based on the Id, but knowing when additional data was entered would require more tracking fields.
In the future, you may want to think about a table design along these lines:
Column Name Column Description
ID Record Id
STUDENT_ID Student Id Number
STUDENT_FIRST_NAME Student First Name
STUDENT_LAST_NAME Student Last Name
... Other student info ...
DATE_ENTERED Date/Time entered
DATE_SENT Date/Time sent to teacher
DATE_SIGNED Date/Time signed by teacher
UPDATED_DATE Date/Time record last updated
UPDATED_BY User that made the last update
If it's possible, you could always edit your table and add these datestamp columns. You'd have to allow for null values, as the previous entries wouldn't have a date/time value for some of them, but it would let you track future entries.

Related

SQL to set a date and constant number

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

RSA Archer - Calculated field based on Record Permissions field

I would like to have a complete copy of a Record Permission field.
For example - I have a field "OWNER" which is Record Permission type.
I want to create another field called "OWNER_COPY" which will always include the value which was selected in the OWNER field.
I thought of few ways to do so but none succeeded:
Crete a new Record Permission field (OWNER_COPY) but it has no option to be calculated (it doesn't have the option: "Set the value of this field using....")
Create calculated Text field (OWNER_COPY)- but if I'm writing [OWNER] in the formula it will provide the ID of the value and not its name.(e.g. if the owner was "Oliver", I will get his id - "123"" in the "OWNER_COPY" field).
Crete regular Text field (OWNER_COPY) and add a rule. but I couldn't find any kind of rule which can fit this case.
Any suggestions?? Thanks in advance :)
Archer can't copy value of RP to anther RP.
I used a custom object for this purpose. The limitation is that the field will be populated only when end user actually interact with a form. The good thing is that the field will be populated instantly.
As an alternative you can use a data feed as Tanveer described above, but in this case there will be a delay between the time when you save the record and population of the 2nd RP field.

Database manipulation

Let us say that we have an SQL database with a contacts table that has 5 fields; contactID, title, firstName, middleName, and lastName. On the front end we have a profile page with an update button.
Let us also say that we want to allow the user to update any given field without having to also enter data in the other fields (a last name change, for example.). Is there a 'simple' way to allow this?
My solution is to add a bit field to each property and add a series of condition statements to generate the UPDATE statement based on the bit field.
It is ugly and seems inefficient. Any advice?
The best way is to keep data retrieved from database in all fields and update all the fields. If user changes the value, it will be updated to new value. Otherwise it will stay the same old value.
Suppose that you retrieved all the values from database and on click of edit button, they are editable(textboxes) with old value already present in them. Then write a query like
update contacts set title =#title, firstName=#firstName, middleName=#middleName, lastName=#lastName where contactID=#ContactID

MS Access Delete query based on combobox

I have a table with a bunch of different fields. One is named period.
The period is not part of the raw data but I run a query when I import new data to the database that gives each record a period.
Now I need a delete query that will delete all the records that have the same period as what is selected in a combobox.
The values in the combobox come from a calendar table that contain all the possible values that could be in that period column at any time.
This is the basic query i thought would solve this issue but it tells me it is going to delete 0 rows every time I run it:
DELETE *
FROM PlanTemp
WHERE PlanTemp.period = Forms![Plan Form]!Combo163;
If you don't need the key field, just remove it.
Look at the "PROPERTIES" section and look at the column names.
Ether remove it there, or from your QUERY source.
You can also look at the Data section of the properties, and change your BOUND column, to Column 2... or whatever holds the data you want to use.

Dynamic query creation

I have a scenario wherein with the following details:
I have a form that contains fields like firstname,middle name,lastname,dob,pin,address for Client 1.
Now this form has to cater more than one client . The problem statement is - different clients may require different number of fields to be displayed on front end. For eg: a 2nd client would want - Country field instead of pin, would not require address on the form.
Now when i submit the form , currently i have a constant query which takes values of - firstname,middle name,lastname,dob,pin,address and inserts it into database for Client 1. I want to develop a query in a way that it is created at runtime and inserts only the values that come from the form into the database..
I hope my problem is clear. Can anyone help?????????????
You need to think about why you are doing this.
It will get hideously complex with just person form, add in more and it will balloon big style.
Dynamically building queries isn't particularly complicated, but it's a lot of code to do it.
Just think about each field you want to add to the query and it's type. What if a property on your person record was an image of them.
Do you have a configuration of the form, is the promary key on the record an auto inc, is it a compound key, do you use defaults, are some fields not null. How are you going to bubble back referential integrity exceptions...
Do the all singing all dancing version and basically you reinvent something like the Access IDE....
Personally I'd have a Person object with a set of Person Properties, they would have name, a value and a boolean to say whether they'd been changed.
Once you have teh list of chnaged properties and beacseu you are in the Person object you know the table is persons, it's keyed by an autoinc bigint, gender is mandatory and defaults to Male...
You have a fighting chance.
Your query should use parameters
So it would be say Insert Persons(FirstName, LastName, PIN) Values(#FirstName,#LastName,#PIN)
Then you'd nip through your changed fields and add parameters with same name, type and value.
As I said you can really go to town with this one, may be it's time for a night in though.
This should mean that some fields in your table like address and pin can be empty, in that case you can do without a dynamic query. Just collect all the inputs from your form and insert them into your table. Those form fields that were left empty due to different user needs will consequently have their corresponding field in your table empty. So just list all the needed fields in your table and all the possible input from your form in your insertion query.