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!

Need help greying out a Text field based on Value list selection

Status
Not open for further replies.

Swiftraven

Technical User
Oct 29, 2001
28
US
Hi,
I have looked through prior posts and haven't been able to find out exactly how to do this since I am a total newb at access.
My problem is, I have a Value list called ProblemType that contains 3 items, Hardware, Software and Component. I also have two text boxes called Software Program and Sw Test Number that are the next two fields to be entered.
What I need is when the person chooses Software in the drop down menu on the form, I want them to be able to type in the infomation in the two text boxes, if they choose either Hardware or Component, I want the text boxes greyed out so that the default ("Does Not Apply") text appears and they can not change it.
Tab_IncidentRecord is the name of the table that the form is updating.
I tried an On Change Event:

Private Sub ProblemType_Change()
If [Tab_IncidentRecord]![ProblemType] = "Software" Then
[Tab_IncidentRecord]![SWProgram].Enabled = False
[Tab_IncidentRecord]![SWTestNum].Enabled = False
Else
[Tab_IncidentRecord]![SWProgram].Enabled = True
[Tab_IncidentRecord]![SWTestNum].Enabled = True
End If
End Sub

that I saw from another post but this didnt work.

Any help is GREATLY appreciated.
Sorry for the newbie question

Thanks
Jason
 
The code looks promising - maybe it is just the event that it is the problem. Have you tried the on exit or on lost focus or even the form's Before Update events?
 
You have the right idea with the code, the only problem is that you are trying to reference table fields. Instead you should be referencing the fields on your form. Replace all references to [Tab_IncidentRecord] with me! (current form) Maq B-)
<insert witty signature here>
 
Thanks alot, you guys are great.

I changed the code to Me! and put a variation of it in the On Activate for the form itself and for my Update Form button to set them to disabled by default and put the If..Then..Else statement in the Before Update on ProblemType to check for Software.

Works like a charm.

Thanks again for the help :)
I am sure I will be back soon with more newb questions.
Jason
 
Darn, I spoke too soon. Told you I would be back soon :(

It is working how I want it to most of the time. Problem is a user can break it if they select software, fill in the two fields, then change it back to hardware. This just disables the fields with the now useless program and test data within. I tried to make it return to the default value (&quot;NA&quot;) by using the DefaultValue property, but it doesnt do anything but cause me to have a #Name? in the two fields when I click my clear record button and leaves the bad data in when they are disabled.

Here is the code that I tried. I have never seen/used Visual Basic or tried coding events before today, so if this is totally off the wall wrong, forgive me :)

The ProblemType field is what I am keying off of as to whether to activate the 2 fields or not.

If Me![ProblemType] = &quot;Software&quot; Then
Me![SWProgram].Enabled = True
Me![SWTestNum].Enabled = True
Else
Me![SWProgram].DefaultValue = &quot;NA&quot;
Me![SWTestNum].DefaultValue = &quot;NA&quot;
Me![SWProgram].Enabled = False
Me![SWTestNum].Enabled = False
End If

My default value in my table is NA which I set in the properties, I need to figure out how to make it replace the bad data in the fields back to the default value after the user changes the ProblemType from software to anything else.

Thanks again
Jason
 
The default value is just something that fills in when nothing else is typed into the box. Since your user has typed data into the box the default value is not applicable. (No pun intended)

You want to set the value of the text box to &quot;NA&quot;, not the default value.

If Me![ProblemType] = &quot;Software&quot; Then
Me![SWProgram].Enabled = True
Me![SWTestNum].Enabled = True
Else
Me![SWProgram] = &quot;NA&quot;
Me![SWTestNum] = &quot;NA&quot;
Me![SWProgram].Enabled = False
Me![SWTestNum].Enabled = False
End If

Maq B-)
<insert witty signature here>
 
Thanks again Marquis, you've been a huge help. :-D

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top