Lock a record in a form once all it's fields are completed. (1 Viewer)

usmanghani_2654

New member
Local time
Today, 11:20
Joined
May 8, 2012
Messages
8
Hi there,
My appologies for this long description of my questions. Helps will be highly appreciated.

Well, i have a database form (Key Issue-Form) with table (Key Issue-Table) contaning all the data of form at backend.

Now this form is actually used to issue keys and is used by about 40+ security staff members (everyone with different level of computer skills - mostly really less skills), all these staff members have their network names which they use to log-in to windows/work computers.

I am trying to make the most easiest and user-friendly database form, so that the staff members can just type in the details of a person and key with really minimum effort.


For this reason,
I have the first field Date Out with default value equals to today's date which works perfectly.

2nd field is name of the person to which they are issuing key - which definitely they have to type in with their whatever skills.

3rd field is the company/department name from which that person is, who is getting the key, its a drop-down list with most of the contractors/company who work for us.

4th is the contact number, which they have to type in.
5th field is again a drop-down field with all buildings (about 26 buildings), for which we hold the keys of.

6th field is a drop-down list of all the keys (about 1000 keys) from all buildings and it depends on the value of the fifth field. It's like a filter. If i select a building from fifth field, the sixth field will show the keys for only that specific building.

7th field is Time out. i have set its default value to 'Now()' which grabs the present time. but i have suggested the staff members to always press F5 before issuing a key and entering details, which updates the present time.

8th field is for the name of the staff member issuing key. They have to write their name. I am thinking to change this field to drop-down with staff's names in so it will be more easy for them to type.
Q: BUT if I could change it to something like this that it will automatically grab the staff member's network details, like his network log-in name and which he cannot change it at all. Because, otherwise they can write anyone else's name to cheat even though if i will make it a drop-down list, they can select someone else's name. I changed the control source of this field to CurrentUser which was not that good because if i issue a key with my name in this field and after that someone else accesses this file then in all previous records the field 8 grabs the current user who is accessing the file now, and not my name. Help on this please.

9th field is for date in when the key came back, it could be next day or any. so that's why I didn't set it on 'Today's date'. Staff are advised to type in.

10th field is for time in, which, again they will type in.
Q: OR if I could do something like this that when someone enters the Date In (9th field), then this field automatically grab the present time.

11th field is again the staff member's name who will be receiving back the key. I can make it a drop-down field with all staff member's names.
Q: BUT if i could do it same as field 8th, that the person who will receive the key he will obviously type in the Date In and Time In, so once these two values are typed in by this user, i want the 11th field to automatically grab current user's windows log-in name which he should not be able to change at all.

12th field is a drop-down list expressing the status of the key, with values like OK, Missing, Damaged, Awaiting.
Q: Now here i want that once the staff member received the key, typed in the Date In and Time In and the field 11th grabbed his user details automatically and after that the staff member selects 'OK' by himself from the drop-down list then the whole record should LOCK so no one can change or delete it, because once the key is back and all details are in the record, we obviously don't want it to be changed or deleted mistakenly.

beside this all, i never learnt MS Access from a course, whatever i have done so far is by my self and obviously internet/forums and having some tips from a book which doesn't cover these above questions.

Use the field numbers as a reference to express your answer please.

Helps will be highly appreciated.

Bless you all.
Usman
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:20
Joined
Feb 19, 2002
Messages
43,266
Date and time work better if they're in the same field rather than separate. Rather than setting time as a default which populates as soon as someone starts typing, enter the value in the Form's BeforeUpdate event.
Me.TimeOut = Now()
You can also log TimeIN the same way if the current date/time is ok. Otherwise, the user can type whatever he wants.

An easy way to get the logged in user is with an environment variable. Again - don't populate this until the Form's BeforeUpdate event.

Me.UpdatedBy = Environ("UserName")
 

usmanghani_2654

New member
Local time
Today, 11:20
Joined
May 8, 2012
Messages
8
Pat Hartman - You are a hero.

i have tried your suggested vb scripts and they work perfectly.
now i still left with one Question that after all fields are filled in once, then i want the whole record to be locked so no one can make changes not even by mistake or intentionally.

Along with this one strange thing i noticed. Whenever i open my database file, it always mentions that
"Security Warning - Certain content in this database has been disabled."
with an option button. when i go to this option button it gives me choices to enable content or protect me from ..... i read the fact behind it and it says, that i have to place my file in a trusted location which i have done and now No message comes up.

by the way, in 3rd field's AfterUpdate event i have mentioned
Me.2ndfield.locked=True
which works perfectly and locks 2nd field as soon as i move away from 3rd field after updating. so even if i try to change or delete the 2nd field....i cant...because its locked...which is fine

BUT
the problem is...if i close this database and open it again, then the locked field (2nd) appears to be unlocked and i am able to make changes in it...

now this is where im stuck....:confused:

many thanks for the help...




Date and time work better if they're in the same field rather than separate. Rather than setting time as a default which populates as soon as someone starts typing, enter the value in the Form's BeforeUpdate event.
Me.TimeOut = Now()
You can also log TimeIN the same way if the current date/time is ok. Otherwise, the user can type whatever he wants.

An easy way to get the logged in user is with an environment variable. Again - don't populate this until the Form's BeforeUpdate event.

Me.UpdatedBy = Environ("UserName")
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:20
Joined
Feb 19, 2002
Messages
43,266
Thank you for the birthday wishes:)

Rather than locking the field immediately, wait until the record has been saved. The user should be allowed to correct any error he finds before the record is saved. In the Form's AfterUpdate event:
Code:
Me.AllowEdits = False

In the Form's Current event:
Code:
If Me.NewRecord = True Then
    Me.AllowEdits = True
Else
    Me.AllowEdits = False
End If
 

Users who are viewing this thread

Top Bottom