How do I create a record lock?

wind20mph

MS Access User Since 1996
Local time
Today, 17:07
Joined
Mar 5, 2013
Messages
50
I have a terrible skill in this but I am doing my best to find ways. But I am running out of time in the development stage. I have the following form and table:

Tables:
Eqpt
EqptHistory

Forms:
frmEqpt
frmHistory

frmEqpt is the Mother form and frmHistory is the subform connected thru eqptID. Now what I want to do is count the records in the frmHistory and Locked the fields for editing. If it is new records, the fields will automatically unlock.

How do I do that because I can't find a way to count the fields with records and lock them.

Thanks in Advance.
 
You could open the sub form in design mode and set the Locked property of each control to Yes and the Enabled property of each control to No. Then put some code in the form's On Current event to reverse these settings if it is a new record. Something like:
Code:
Private Sub Form_Current()
  If Me.NewRecord Then
    Me.FirstCtrl.Enabled = True
    Me.FirstCtrl.Locked = False
    Me.SecondCtrl.Enabled = True
    Me.SecondCtrl.Locked = False
  Else
    Me.FirstCtrl.Enabled = False
    Me.FirstCtrl.Locked = True
    Me.SecondCtrl.Enabled = False
    Me.SecondCtrl.Locked = True
End Sub
You would probably want some code it the form's Before UpDate event, which can be cancelled, as well to check with the user that the record is to be saved because once it has been saved edits will not be possible.
 
Thank you. I have made that one. But everything is locked. What I mean is, first the routine should count the number of records, and only those records will be locked for editing and not the entire Recordset. I am Using Access 2010 by the way.
 
Thank you. I have made that one. But everything is locked. What I mean is, first the routine should count the number of records, and only those records will be locked for editing and not the entire Recordset. I am Using Access 2010 by the way.
The code I suggested should unlock the controls if the focus moves to a new record. Is that not happening.
 
The code I suggested should unlock the controls if the focus moves to a new record. Is that not happening.
The code unlocks the fields when new record was clicked and when moved via navigation button, so even if there were records, it unlocks itself. or something is wrong with my code.
Code:
Private Sub Form_Current
  If Me.NewRecord Then
     Me![empno].Enabled = True
     Me![empname].Enambled = True
     Me![mbasic].Enabled = True
     Me![mallow].Enabled = True
  Else
     Me![empno].Enabled = False
     Me![empname].Enambled = False
     Me![mbasic].Enabled = False
     Me![mallow].Enabled = False
End Sub

Just this simple line... I have been so stupid to detect what is wrong. Until this moment.
 
I'm at wits end... the code did not work. so I decided to change the view. I placed the original fields into locked = yes enabled = no visible = false and created an unbound fields. So I don't have to worry about locking and unlocking since the data will not save unless clicked the saved button or unlock fields button.
 
Can you post a copy of the db in A2003 mdb format.
 
wind

you do not need record locks initially.

I would concentrate on getting a working database going first, without worrying about such details

eg - counting records has nothing to do with record locks.
 
wind

you do not need record locks initially.

I would concentrate on getting a working database going first, without worrying about such details

eg - counting records has nothing to do with record locks.
thanks i take note of that. i have other purpose of record counting. when exporting intended records to excel. but not at the moment. just finishing my development the hr department is putting me under pressure of the payroll system and the employment history record. i am focusing on finishing the development within the month of march and then revise the necessary additions in time.
 

Users who are viewing this thread

Back
Top Bottom