Add new record in subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Continuous Forms subform. I want the user to be able to add new
records to the subform, but for existing records I need to limit the editing
of the record to 2 fields. Is this possible?

Thanks
 
yes. in the subform's Current event, add the following code, as

Private Sub Form_Current()

Dim ctrl As Control

For Each ctrl In Me.Controls
Select Case ctrl.ControlType
Case acTextBox, acComboBox, acCheckBox
ctrl.Locked = Not Me.NewRecord
End Select
Next
If Me!ControlA.Locked Then Me!ControlA.Locked = False
If Me!ControlB.Locked Then Me!ControlB.Locked = False

End Sub

for ControlA and ControlB, substitute the names of the two controls you want
open at all times. the procedure looks at each control on the subform. if
the control is a textbox, a combo box, or a checkbox, then the code sets
Locked = True on existing records, and Locked = False on new records. then
the code checks the two "always open" controls, and unlocks them if
necessary.

hth
 
Thank you very much. It worked!
Marni

tina said:
yes. in the subform's Current event, add the following code, as

Private Sub Form_Current()

Dim ctrl As Control

For Each ctrl In Me.Controls
Select Case ctrl.ControlType
Case acTextBox, acComboBox, acCheckBox
ctrl.Locked = Not Me.NewRecord
End Select
Next
If Me!ControlA.Locked Then Me!ControlA.Locked = False
If Me!ControlB.Locked Then Me!ControlB.Locked = False

End Sub

for ControlA and ControlB, substitute the names of the two controls you want
open at all times. the procedure looks at each control on the subform. if
the control is a textbox, a combo box, or a checkbox, then the code sets
Locked = True on existing records, and Locked = False on new records. then
the code checks the two "always open" controls, and unlocks them if
necessary.

hth
 
Back
Top