Graying out fields

Mayanja_N

New member
Local time
Tomorrow, 01:45
Joined
Oct 6, 2011
Messages
5
Am using access 2007 to develop a database. I need to gray out fields in the same form and in different forms depending on the registration form

First, on the registration form, i have a field 'age', if age is less than 5 years, i have to gray out fields like 'occupation', 'martial status' and 'telephone'

Secondly, on the registration form, i have a field 'sex', if i select male, the fields on form HIV encounter : pregnant, gestation and ANC should be grayed out when i start filling that form.

thanx for any help
 
To grey out a field you can set it's Enabled property to False.

You could do this in the On Change event with some code like;
Code:
If Me.Age < 5 Then 
     Me.Occupation.Enabled = False
     Me.MaritalStatus.Enabled = False
Else
     Me.Occupation.Enabled = True
     Me.MaritalStatus.Enabled = True
End If

You would also need similar code in the Form's On Current Event.
 
Thanks John, it worked for the text box 'age', but i also have a combo box Prior ART which has values 'Yes, No and unknown'. When either No or Unknown is selected, the next fields are supposed to be grayed i.e PMTCT and PEP which are also combo boxes with the same 3 options.
This is the error am getting and the first line is highlighted.

Private Sub combo_priorart_Change()
If Me.priorART = "No" Then

Me.PEP.Enabled = False
Me.PMTCT.Enabled = False
Else
Me.PEP.Enabled = True
Me.PMTCT.Enabled = True

End If
End Sub
 
You could try a select case statement

Code:
Private Sub combo_priorart_AfterUpdate()
Select case me.priorArt
Case "No"
Me.PEP.enabled=False
Me.PMTCT.Enabled=False

Case "Yes"
Me.PEP.Enabled=True
Me.PMTCT.Enabled=TRUE

Case "Unknown"
Me.PEP.enabled=False
Me.PMTCT.Enabled=False

End Select

End Sub
 
@harrison, i used yo code and i was not successful.
it says 'compile error : method or data member not found'

Private Sub combo_priorart_AfterUpdate()
Select Case Me.priorART
Case "No"
Me.PEP.Enabled = False
Me.PMTCT.Enabled = False

Case "Yes"
Me.PEP.Enabled = True
Me.PMTCT.Enabled = True

Case "Unknown"
Me.PEP.Enabled = False
Me.PMTCT.Enabled = False

End Select

End Sub
i wrote the code at the After update event ~ code builder. it still highlights the first line in yellow and the 4th line on Enabled
 
The code should work as long as all the items are on the same form.
 
Try;
Code:
Private Sub combo_priorart_Change()
If Me.priorART[B][COLOR="Red"].Text[/COLOR][/B] = "No" Then

Me.PEP.Enabled = False
Me.PMTCT.Enabled = False
Else
Me.PEP.Enabled = True
Me.PMTCT.Enabled = True

End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom