Lock a field

Bentleybelle

Registered User.
Local time
Today, 03:22
Joined
Feb 22, 2004
Messages
53
I've looked through the forum but haven't found quite what I want. I am a novice but realise this is going to be a relatively simple one ....

I use an invoice form for my own business with client details and a sub form with invoice lines. The client is selected via a combo box. I realise the danger that I could inadvertently alter the client, so would like to lock the client field when I move on to the next invoice or close the record, I don't want to lock the invoice lines. Can't get the code quite right and not sure whether this should be AfterUpdate or OnExit?

Any help much appreciated.
 
Hello:

In Access, you cannot lock a field, but you can lock the control that the field is bound to such as a text box or combo box. You can place the below code in the OnCurrent event of your form and this will lock a combo box when a current record is displayed or when moving to a new record.
'
Private Sub Form_Current()
cboField1.Enabled = False
End Sub
'
When your on your desired record, you must then have a way of enabling your combo box again if desired, such as a command button. Below a command button name cmdEdit re-enables the combo box control.
'
Private Sub cmdEdit_Click()
cboField1.Enabled = True
End Sub
'
Good luck with this!
Regards
Mark
 
according to my understanding of your database i think what u need to do is dont set a control source for the combo box this will not allow it to edit the information
 
I would put it on the forms current event. This code is fired when you move to a different record, so should do what you want.

Me.comboboxname.enabled = false
Me.comboboxname.locked = true

Then I suggest a button somewhere that will unlock the field.

Dave

PS: If you lock the main form - Me.AllowEdits = False, you wont be able to change the subform details.
 

Users who are viewing this thread

Back
Top Bottom