Space is for everybody. It's not just for a few people in science or math, or for a select group of astronauts. That's our new frontier out there, and it's everybody's business to know about space.
Hi Richard. I've watched the seminar all the way though and my database is much more secure now! Quick Question for you regarding unlocking fields. Like in your code I have none of the fields lock in my form and subform if the user is an admin or manager. If the user is in group 3 (a regular employee I have only certain fields unlock for them. However, thinking through it I would like even those fields to be locked for these users once the "record complete" combo box is clicked as "complete". What would the best way to go about this? Right now my code is identical to your from this video.
Adam Schwanz
@Reply 5 years ago
You can just use an if statement for that. Just say something if user is in group 3 and record complete combo = complete then lock everything else if user is in group 3 and record compete combo <> complete, then lock just a few.
Adam Schwanz
@Reply 5 years ago
Use your own field names but
If IsUserInGroup(3) and Combo = "Complete" Then
'Lock Fields Code
ElseIf IsUserInGroup(3) and Combo <> "Compelte" Then
'Lock Few Fields Code
End If
Adam Schwanz
@Reply 5 years ago
Minus the spelling error there, Complete not Compelte, my fingers are just hitting what they want today LOL.
Joseph O'MalleyOP
@Reply 5 years ago
I have updated my code but the last if statement looking at group 3 just seems to disregard my second condition and not lock based on whether the combo box is marked complete, any ideas where I'm going wrong?
Dim ctl As control
If UserUserInGroup(1) OR Is UserInGroup(2) Then
'nothing
Else
For Each ctl In Me
If ctl.ControlType = acTextbox Or ctl.ControlType = acComboBox Then
ctl.Locked = True
ctl.BackColor = RGB(239,242,247) 'grey
End If
Next
For Each ctl In Forms!MainFormName.SubFormName.Form!
If ctl.ControlType = acTextbox Or ctl.ControlType = acComboBox Then
ctl.Locked = True
ctl.BackColor = RGB(239,242,247) 'grey
End If
Next
End If
If IsUserInGroup(3) And Forms!MainFormName.SubFormName.Form!CompleteStatus <> "complete" Then
'only lock certain fields from main form and subform inside the main form
Control1.Locked = False
Forms!MainFormName.SubFormName.Form!Control2.Locked = False
End If
End Sub
Joseph O'MalleyOP
@Reply 5 years ago
Ohh Actually thinking about it more this is form-level locking and the condition I added to say if a certain field with a record is marked as "complete" would be record-level locking which this probably wouldn't do, as any of my 305 records could be marked as complete or not complete. Would Anyone know how to accomplish this?
Juan C Rivera
@Reply 5 years ago
Hi all, I used the tech help video showing a progress bar on the % of the form completed (extended cut). then I used a checkbox (hidden) if true lock (allow edits no) the form. very simple Richard walks you through every step with the bar. If you don't have extended cut maybe Richard can allow it once so you guys can see what your missing :)
V/r
Juan
Adam Schwanz
@Reply 5 years ago
You want Forms!MainFormName!SubFormName.Form!Control
Adam Schwanz
@Reply 5 years ago
What do you mean record level locking? Record locking is something very different - https://599cd.com/blog/display-article.asp?ID=1659
That user level locking is what you want to do if you just want to stop people from editing any records that are marked "complete" with the form. If you have users that are going into tables directly that can circumvent this, I'd advise to get them out and onto the form.
Joseph O'MalleyOP
@Reply 5 years ago
Hi All I hate to be a bother but does anyone know what still might be wrong with my code? My fields in the subform are still not locking if the record is marked as complete and now I'm getting an error saying "return without Go-Sub". If I remove the "And Forms!Service.ServiceSubform.Form!Status <> "Complete" part of the If IsUserInGroup(3) statement I don't get that error but that is the past bit of functionality I am trying to tie into my db.
Joseph O'MalleyOP
@Reply 5 years ago
Private Sub Form_Current()
Dim ctl As Control
If IsUserInGroup(1) Or IsUserInGroup(2) Then
'do nothing; don't lock fields for db committe and managers
Else
For Each ctl In Me
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.Locked = True
End If
Next
For Each ctl In Forms!Service.ServiceSubform.Form!
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
ctl.Locked = True
End If
Next
End If
'testers: unlocking testing fields only if the record is not marked as complete
If IsUserInGroup(3) And Forms!Service.ServiceSubform.Form!Status <> "Complete" Then
'from parent form field unlock - nothing right now
'from subform field unlock
Forms!Service.ServiceSubform.Form!OnOffTrack.Locked = False
End If
End Sub
Adam Schwanz
@Reply 5 years ago
Did you try the fix I told you earlier a few posts ago?
You want Forms!MainFormName!SubFormName.Form!Control
Change Forms!Service.ServiceSubform.Form!Status
To Forms!Service!ServiceSubform.Form!Status
Adam Schwanz
@Reply 5 years ago
Does For Each ctl In Forms!Service.ServiceSubform.Form! work for you?
I would thing that would need to be
For Each ctl In Forms!Service!ServiceSubForm
Adam Schwanz
@Reply 5 years ago
Actually, just lock the subform much simpler. Don't need to do a loop for each control
Just do ServiceSubForm.Locked = True
Joseph O'MalleyOP
@Reply 5 years ago
Hi Adam, that you so much for your help. I switched the reference method for the subform controls as you suggested. I think that helped in some ways towards a few of my issues but I was still having the whole subform showing as locked when the status combo box was "not equal to"/ "<>" the phase "complete". I ended up switching some of the driving logic by setting that combo box's default value to " not complete" so then in the vba code I have it as when IsUserInGroup(3) then a nested IF statement saying to unlock the specific fields if the combo box is = to "not complete". So when the record is marked "complete" , which can only be done by a manger, the record will be locked for group 3. It' working like a charm now!
Adam Schwanz
@Reply 5 years ago
Glad you figured it out
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.