while inserting data it throws error 'database is locked by the admin on machine --'
The first question is, are YOU the admin on the named machine?
If not, then the message might be literally true. Talk to the admin.
If YOU are the admin and that named machine is the same machine you are on, then the problem might be that you are attempting to add data to a recordset underneath a form bound to the same recordset. You are therefore blocking yourself. More precisely, the two recordsets, one of which is implied by its connection through the form, block each other.
The solution is usually to save the record bound to the form before attempting to update the recordset through code. Or don't use a bound form to do this. (Though admittedly using an unbound form is harder for a novice 'cause of all the recordset tricks you have to play on yourself.)
is it necessary to set focus every time
Focus is automatic for mouse/tab operations, so you must be doing something with VBA underneath the form. Whatever you are doing, you are attempting to reset something not in focus at the time you are tweaking it. But normally, you do NOT have to have the focus on a specific field. It just has to be somewhere legal. You can randomly access controls if you wish.
Because sometimes the data is inserted .
Likely that it has to do with exactly where in the recordset buffer the new record (being insert) and old record (visible through the form) are located. If they are in the same buffer, you find that the old record, being the center of attention of a write-enabled form, is open and therefore locked. The new record cannot go into the same buffer. But if, by luck, the new record and the old record would be in different buffers, you can get away with it. Which tells me that you don't have table-level locking on, 'cause if you did, you would NEVER be able to add a new record. You MIGHT have record-level locking on, which is really buffer-level locking. (Bill Gates lied when he called it record-level locking.)