I have a subform which is bringing in linked data from another table, when writting the vba code for locking up all the fields & unlocking based on GroupID can I set all of that in the parent form or do I have to go into to the subform and write the code in there as well for the corresponding fields?
Adam Schwanz
@Reply 5 years ago
Just lock the entire subform at once on the main form. Don't need to go in and lock them individually.
So let's say you wanted to LOCK or UNLOCK the ContactF (which is a subform on CustomerF) depending on the status of the IsActive field, you would say this in the OnCurrent event:
Private Sub Form_Current()
If IsActive Then
ContactF.Locked = False
Else
ContactF.Locked = True
End If
End Sub
It's that easy. Don't forget the same code in the AfterUpdate event for the IsActive field itself.
Joseph O'MalleyOP
@Reply 5 years ago
Thank you so much for the reply. would be okay with locking the whole subform at first but how would I go about unlocking specific fields within the subform based on GroupID? I apologize if I am missing something.
Thank you so much for your help I really appreciate it. I'm getting an error and I was wondering if you can help he figure out were I'm going wrong
Private Sub Form_Current()
DIM ctl As Control
If ISUserInGroup(1) Then
Else
For Each ctl In Me
If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox Then
ctl.Locked = True
End If
Next
For Each clt in Forms!MainForm.MySubform.Form!
If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox Then
ctl.Locked = True
End If
Next
End If
If IsUserInGroup(2) Then
FieldName.Locked = False
Forms!MainForm.MySubform!FieldName.Locked = False
End If
End Sub
Adam Schwanz
@Reply 5 years ago
Few things, maybe just my preference, but I like to just say 'do nothing if it's no code, easier to read.
If ISUserInGroup(1) Then
'do nothing
Else
For Each ctl In Me
This part has a spelling error, clt instead of ctl
For Each clt in Forms!MainForm.MySubform.Form!
These arent actually "FieldName" right? They're your real field names. Like ContactName.Locked = False etc, or do you have a field called fieldname?
If IsUserInGroup(2) Then
FieldName.Locked = False
Forms!MainForm.MySubform!FieldName.Locked = False
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.