Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Condition unlock check box in subform 1

Status
Not open for further replies.

LittleNick

Technical User
Jun 26, 2009
55
US
Good Morning.
I have a situation where I am trying to do something like conditional formatting. In conditional formatting, I can color a record of a subform if a record has a date past due for example. In the situation I am facing is I have a subform with a couple of text boxes, a combo box and a check box (checkbox is Locked) and when the combo box display my userid on that record (which I will compare to the sign on userid), then the check box is unlocked allowing me to check or uncheck it while leaving those records that do not display my id to be locked.
Any suggestion on how I can implement this?
Appreciate your helps.
 
You could make use of the ENVIRON() environment variables and then set the enabled property of the controls you want to torment.

What do you have so far?

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
something like:
Code:
Private Sub cmdUserName_AfterUpdate()
  If DCOUNT("[UserName]", "Users", "[UserName] = '" & cmdUserName & "'") > 0 Then
    Forms!frmSubForm!checkbox.Locked = False
  Else
    MsgBox "Alert!  Unrecognized User Attempted Login!  Alert! Alert!",vbCritical,"Alert!"
  End If
End Sub

This is untested, but I think the idea should work.

--

"If to err is human, then I must be some kind of human!" -Me
 
Thanks acent and kjv for your reply.
I just tried kjv suggestion, it unlocked the checkbox of all records in the subform and not jusr the record that is assigned to my userid.
I may have been confusing in my previous explanation. Let me try to describe clearer.
I have a subform that shows as follow:

DATE TASK USERID DONE
08/05/09 Cleaning the desk johnd (chkbox)
08/05/09 Load Mary machine davidt (chkbox)
08/05/09 Run Back up johnd (chkbox)

Now, I am being johnd and signed on, then when I open the form with this subform displayed, I want to be able to check done when I am done cleaning the desk or ran back up, BUT, I can not check the task load Mary machine.
Thanks for any suggestions or helps.
 
Okay, so you have your Form set to Continuous Form View? If so, then you would at least have to select the specific record in code before running any commands. Also, you may be better off adding a lock/unlock field into your table/recordset, and basing the lock/unlock actions off of that. I'm not terribly sure you can just flat lock/unlock a specific control for a specific record, and not all records on a form, unless you have some way to narrow down your recordset before doing so..

Hopefully this makes some sense.. I'm a little stretched, time-wise, at the moment.

--

"If to err is human, then I must be some kind of human!" -Me
 
I don't think there's a way to do this...can you filter the subform for just the records that the particular user is allowed to change? Or is it necessary that the be able to view all records?
 
Thanks everyone for the reply.
Joelflorendo, you may be right, there may not be a way to do this directly.
What I did was I create a ddifferent recordsource that filter all records except the ones the current user is signed on then I display the records and set the checkbox.locked to false. It is not what I originally though of doing but it worked with the same intention.
Again thanks for all your helps.
 
Good to hear you found a solution...
Just in case anyone else might be considering doing this, I was thinking about it, and possibly came up with another way to make it work.

You could use conditional formatting to indicate to the users that certain records are allowed to be change (grey it out, etc.).

In order to prevent unwanted changes, you could base the form off of a disconnected recordset. Then when the user tries to make a change, check if it's ok for them to change. If not, give a message box or something and undo the changes on the form.

You'd also have to include the current user's username in the underlying recordset to base the conditional formatting off of it.
 

LittleNick,
Glad to hear you got it sorted out.

joelflorendo,
That sounds like a great idea, assuming it works that way. Conditional formatting in Access is something I've messed with very little if any at all.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top