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

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?
 
D

Douglas J. Steele

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
 
C

Chris v.

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.
:)
 

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