Change a form control's llow edits property to No if it is Not Nul

  • Thread starter Thread starter Chris v.
  • Start date Start date
C

Chris v.

I'm using Access 2007 and have an "Input" form with sub forms. The Main
form's Allow Edits property is set to yes, while the controls on the main
form are locked so the user can ONLY look-up clients. The sub forms is where
the data entry happens. However, if the sub form already has data, that data
shouldn't be modifiable. Yet, if any of the sub-form's fields are null, I
want the user to be able to enter the appropriate data. So me questions are:
1) How can I do this? and 2) Is this a bad design?
 
Why not lock the control if it has data? In the Current event of the form
being used as a subform, try something like:

Private Sub Form_Current()

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
Select Case ctlCurr.ControlType
Case acTextBox, acListBox, acComboBox
ctlCurr.Locked = (Len(ctlCurr.Value & vbNullString) > 0)
End Select
Next ctlCurr

End Sub
 
It worked like a charm. Thank you. Can you recommend how/where I can learn
VBA online or which book to start with, or both? Your code was most helpful.
:)
 
Back
Top