Making Check Box and Label Enabled/Disabled

nate_03

Registered User.
Local time
Yesterday, 22:56
Joined
Jun 2, 2003
Messages
22
Is it possible through simple VB code to have a label and respective check box enabled or disabled when a specific string pops up in a text box.

I have a text box that contains computer models. When viewing the records I would like the check box and label to be grayed out unless KTX is in the computer models text box.

Any advice would be great!

Thanks,

Nate
 
Nate,

You can use the OnCurrent event of the form to:

Code:
If Me.YourTextBox = "KTX" Then
   Me.YourCheckBox.Enabled = True
Else
   Me.YourCheckBox.Enabled = False
End If

Wayne
 
Thanks Wayne:

I think I understand but my code does not seem to work.

Am I just inserting the code anywhere in the VB program?

Here is a look at what I have

code----------------------------------------------------------------------------

Form OnCurrent

If Form_DesktopAdd / Modify / Delete.Make / Model = "KTX" Then
Form_DesktopAdd / Modify / Delete.Check28.Enabled = True
Else
Form_Desktop Add / Modify / Delete.Check28.Enabled = False
End If

code----------------------------------------------------------------------------

I am getting a Compile error: Expected: Expression

Thanks again.
 
his code goes into the ON Current event for the form. Go to the Form Properties in Design View, Select the EVENT tab, and enter "Event Procedure" in the row marked "on Current". Then click on the Ellipses (...)at the end of the row and the code window will open at the right place.

If the fields you are referencing are on the current open form, you don't need to specify the full form name. Use the ME keyword instead as Wayne suggested. ( e.g: Me.Check28)

Your code is failing at the first hurdle because your field names are incorrectly entered. If you have spaces in your field names, they must be enclosed in square brackets. Personally, I wouldn't use forward or back slashes in field names either, to avoid confusion with file paths or switches.
 
Private Sub Detail_Click()

If Me.Make_Model = "KTX" Then
Me.Check28.Enabled = True
Else
Me.Check28.Enabled = False
End If

End Sub

This still does not seem to work? :confused:

Thank you for the advice, but it still does not seem to work. The check box does not disable at all.

Nate
 
Sorry Wayne, even though the zipped file is 504 bytes I can't attach it to the posting. It says it's too big! I will try again this afternoon.

Thanks
 
You are not entering this code in the OnCurrent event. You have it in the Detail Click event. Have you tried moving the code to the OnCurrent event first?
 

Users who are viewing this thread

Back
Top Bottom