Grey out text fields

rscott1989

Registered User.
Local time
Today, 17:17
Joined
Oct 24, 2013
Messages
21
I am fairly new to Access, trying to become a little more educated. I am trying to use a check box to either grey out certain text field(s). For example If the box is checked true then certain fields would become available to input data. If the box is not checked it stays grayed out.

I am not very experienced in using VBA, so any help offered is greatly appreciated!
 
I think your looking to enable/disable fields using code. I'll use myChk, myCtl1, myCtl2, myCtl3 in this example. You could do this with afterupdate event of your checkbox but that won't run when you open the form. It's the myChkTest procedure below that does the work but we need it to be called when the form opens and when we change the checkbox.

In the form's OnOpen event. (could be in OnCurrent or OnLoad)
Private Sub Form_OnOpen()
Call myChkTest
End Sub

Stay in the module and go below the last End Sub. On a new line, type the following (End Sub will appear once you type the first line)

Private Sub myChkTest()
If myChk = True Then
myCtl1.Enabled = True
myCtl2.Enabled = False
myCtl3.Enabled = True
Else
myCtl1.Enabled = False
myCtl2.Enabled = True
myCtl3.Enabled = False
End If
End Sub

In the AfterUpdate event of myChk
Private Sub myChk_AfterUpdate()
Call myChkTest
End Sub

Hope that helps get you started.
 
I do not seem to be doing this right. I tried the way you told me (THANK YOU btw) and now i get an error. Something wrong with the code. I am attaching a screenshot of what i want to do.

when a box is checked, all the data in the corresponding field will be available to edit. If a box is left unchecked then no data can be edited.
 

Attachments

Use the CLICK event for the check box in order to enable/disable the a certain control.
I saw in your screenshot that you use a single check box in order to enable/disable a single control.
So:
Code:
Private Sub CheckBoxName_Click
  Me.ControlName.Enable = Me.CheckBoxName
End Sub
You wrote:
I tried the way you told me (THANK YOU btw) and now i get an error.
This is NOT a useful information for us.
You must tell us what the message say.
 
OKay i figured out how to grey the fields out using the check box......

This is the code i used in the on click event,



Private Sub Check658_Click() ' M4

If Me.Check658.Value = True Then ' for check1 use your check box name
Me.DATE_M4.Enabled = True ' for text1 use your textbox name
Me.M4__SCORE.Enabled = True
Me.M4__GO___NO_GO.Enabled = True
Me.Combo535.Enabled = True

Else
Me.DATE_M4.Enabled = False ' for text1 use your textbox name
Me.M4__SCORE.Enabled = False
Me.M4__GO___NO_GO.Enabled = False
Me.Combo535.Enabled = False
End If
End Sub




Now What if when the form starts i want it to automatically be unchecked (Grayed out) I changed the default value to unchecked, but the fields are not grayed out right away. Any suggestions fir this?

Thanks so much for your help!!
 
You could try the following code in the forms On Open event:
Code:
Me.Check658 = False
Me.DATE_M4.Enabled = False
Me.M4__SCORE.Enabled = False
Me.M4__GO___NO_GO.Enabled = False
Me.Combo535.Enabled = False
 
Even if your code work, it is not OK.
Try this:
Code:
Private Sub Check658_Click() ' M4
           Me.DATE_M4.Enabled = Check658
           Me.M4__SCORE.Enabled = Check658
           Me.M4__GO___NO_GO.Enabled = Check658
           Me.Combo535.Enabled = Check658
        End Sub
The same result with half of code => Easier and faster to programming and a lot easier to maintain.

One more thing:
Give to each control a suggestive name.
Answer me/yourself, but quickly: What Check658 do ? What Combo535 store/show ?

Good luck !
 
Mihail,

Thank you! That is a much easier way! Now I am running into another problem. It all works fine, but the values are being defaulted to something weird. I am attaching a screenshot

I want all the fields to start out blank

Thank you!!
 

Attachments

Note please that is a difference between controls and fields.
The controls are "windows" that allow you to see the values from fields in a certain record.
So, if you have an bounded control, this control will show the value from the field.
The control will not be blank while the field is not empty (or null) for that record.
 

Users who are viewing this thread

Back
Top Bottom