Controlling Edits

E

E.Q.

I have a subform in datasheet view. I'd like to lock the text box named
chrMeasureName for existing records but allow users to enter it in new
records.
I've tried this code

Private Sub Form_Current()
If Me.NewRecord Then
Me.chrMeasureName.Enabled = True
Me.chrMeasureName.Locked = False
Else: Me.chrMeasureName.Enabled = False
Me.chrMeasureName.Locked = True
End If
End sub
This works until chrMeasureName (a text box) is selected in the new record
row and one of the records above is clicked. This generates an error for
trying to disable a control that has focus.
Is it possible to limit edits the way I want. I'm wondering if I can solve
this through error handling or if there's another approach. I thought one
solution would be to have two different forms, one to allow new entries and
another to enter measure descriptions, but I'm hoping there's a more elegant
solution.
Thanks
EQC
 
S

Stefan Hoffmann

hi,

This works until chrMeasureName (a text box) is selected in the new record
row and one of the records above is clicked. This generates an error for
trying to disable a control that has focus.
You can use the ActiveControl property of the form to determine which
control is focused.
Is it possible to limit edits the way I want. I'm wondering if I can solve
this through error handling or if there's another approach.

If Me.ActiveControl = chrMeasureName Then
otherControl.SetFocus
End If
chrMeasureName.Enabled = False

And use the error handling method as fallback.


mfG
--> stefan <--
 
E

E.Q.

Thanks, this was the last piece needed to generating a front end that
contains the features the users said they wanted. Your help is greatly
appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top