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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turning Locked Controls Grey if they have been verified

Status
Not open for further replies.

vix666

IS-IT--Management
Jul 17, 2003
63
AU
I have this code below which locks the controls on a form if either of 2 check boxes are ticked. When it locks the controls i also want their background colour to go grey.
The code below kind of works, it locks all the controls if the check box is ticked on that form, but it makes all the form records grey instead of just the ones which are locked.

Private Sub Form_Current()
On Error Resume Next
Dim ctls As Controls
Dim ctlCur As Control
Dim fEnabled As Boolean
Dim i As Integer

fEnabled = (Me![Verify Release] Or Me![Op Verify Release])

Set ctls = Me.Controls

For i = 1 To ctls.Count
Set ctlCur = ctls(i)

ctlCur.Locked = fEnabled
ctlCur.BackColor = "12632256"
ctlCur.ForeColor = "4473924"

Next i

Command56.Enabled = True
Command57.Enabled = True
Command95.Enabled = True

End Sub

Any ideas how i can just make the locked ones turn grey?I posted this message before and only had 1 reply, which wasnt relevant as I am using Access 97, so any other help would be great

Thanks in advance

Vicky
 
It sounds like you want the event to happen based on the value of the record. In that case, use the on current event which fires each time there's a new record loaded.
 
try this:

<snip>
For i = 1 To ctls.Count
Set ctlCur = ctls(i)
ctlCur.Locked = fEnabled
if not(fEnabled) then
ctlCur.BackColor = &quot;12632256&quot;
ctlCur.ForeColor = &quot;4473924&quot;
end if
Next i
<snip>


Maq [americanflag]
<insert witty signature here>
 
For i = 1 To ctls.Count
Set ctlCur = ctls(i)
ctlCur.Locked = fEnabled
if not(fEnabled) then
ctlCur.BackColor = &quot;12632256&quot;
ctlCur.ForeColor = &quot;4473924&quot;
end if
Next i

when i use this code it locks and greys out my check boxes instead of the other controls on the form, its close but i need the other controls to be grey and locked and the check boxes to be normal.

Thanks for the help, any other ideas?
 
well the code you posted is looking at every control on the form. How many controls do you want locked? If it's not that many then you can just lock those instead of looping through all the controls.

If it's too many then perhaps all you need is to check the control type first and just lock the text boxes.

I can't remember the code to check the control type off the top of my head. I know I've done it before somewhere. I'll look through my databases and post back.

Maq [americanflag]
<insert witty signature here>
 
For i = 1 To ctls.Count
Set ctlCur = ctls(i)
If ctlCur.ControlType = acTextBox Then
ctlCur.Locked = fEnabled
if not(fEnabled) then
ctlCur.BackColor = &quot;12632256&quot;
ctlCur.ForeColor = &quot;4473924&quot;
end if
end if
Next i

I don't know what types of controls you have on your form, so you may also need to check for comboboxes, listboxes, etc.

Or, another idea which I have used in the past is to set the tag property of each control that you want locked/unlocked and then just check the tag instead of the control type.

This would also eliminate the need for you re-enable the command buttons at the bottom of your code.

Maq [americanflag]
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top