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!

enabled is not working

Status
Not open for further replies.

splats

Technical User
Jan 2, 2003
131
I have a list box in a subform that when selected, should enable or disable some of the other fields on the form. However, with the code as below, it does not work at all. Any suggestions would be greatly appreciated.
(Access version 2002-2003)

Thank you

Private Sub ListTypes_AfterUpdate()

If Me.ListType.Value = "FCBC Type" Then
Me.FCBCPeriod.Enabled = True
Me.FCBCType2ID.Enabled = True
Me.PRRT.Enabled = False
Me.PTypeID.Enabled = False

Else
If Me.ListType.Value = "PASB Type" Then
Me.FCBCPeriod.Enabled = False
Me.FCBCType2ID.Enabled = False
Me.PRRT.Enabled = True
Me.PTypeID.Enabled = True

Else
If Me.ListType.Value = "" Then
Me.FCBCPeriod.Enabled = False
Me.FCBCType2ID.Enabled = False
Me.PRRT.Enabled = False
Me.PTypeID.Enabled = False
End If

End Sub
 
I have also tried but still no luck....

Private Sub ListTypes_AfterUpdate()

If [sfrm-ReferralDatatest]![ListTypes].Value = "FCBC Type" Then
'[subformname]![control].Enabled = False

[sfrm-ReferralDatatest]![FCBCPeriod].Enabled = True
[sfrm-ReferralDatatest]![FCBCType2ID].Enabled = True
[sfrm-ReferralDatatest]![PRRT].Enabled = False
[sfrm-ReferralDatatest]![PTypeID].Enabled = False

Else
If [sfrm-ReferralDatatest]![ListTypes].Value = "PASB Type" Then
[sfrm-ReferralDatatest]![FCBCPeriod].Enabled = False
[sfrm-ReferralDatatest]![FCBCType2ID].Enabled = False
[sfrm-ReferralDatatest]![PRRT].Enabled = True
[sfrm-ReferralDatatest]![PTypeID].Enabled = True

Else
If [sfrm-ReferralDatatest]![ListTypes].Value = "" Then
[sfrm-ReferralDatatest]![FCBCPeriod].Enabled = False
[sfrm-ReferralDatatest]![FCBCType2ID].Enabled = False
[sfrm-ReferralDatatest]![PRRT].Enabled = False
[sfrm-ReferralDatatest]![PTypeID].Enabled = False
End If

End Sub
 
Private Sub ListTypes_AfterUpdate()
If Me.ListType[!]s[/!].Value = "FCBC Type" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello PH

Thank you for your input. I have already tried that as well but is still not working. Is it possible that I need a reference that will get it running?

Thanks

Tina
 
is still not working
What happens ? Any error message ? Unexpected behaviour ? Computer crash ? ... ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya tinat . . .

[ol][li]With your latest post your saying the listbox is on the mainform and the fields you want to control are on the subform. Is this correct?[/li]
[li]Are you sure your [blue]selecting the right column[/blue] in the listbox (column index starts at zero and includes any hidden columns in the [blue]Column Widths[/blue] property)?[/li][/ol]
As a first shot at this replace the code with the following (you may have to play with [blue]Column([purple]?[/purple])[/blue]):
Code:
[blue]   Dim sfrm As Form, En As Boolean
   
   Set sfrm = sfrm - [ReferralDatatest].Form

   If Trim(sfrm!ListTypes.Column([purple][b]1[/b][/purple]) & "") = "FCBC Type" Then
   sfrm!FCBCPeriod.Enabled = True
      En = True
   End If

   sfrm!FCBCPeriod.Enabled = En
   sfrm!FCBCType2ID.Enabled = En
   sfrm!PRRT.Enabled = Not En
   sfrm!PTypeID.Enabled = Not En
   
   Set sfrm = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Woops! . . .

Need to correct the code to:
Code:
[blue]   Dim sfrm As Form, En As Boolean
   
   Set sfrm = sfrm - [ReferralDatatest].Form

   If Trim(sfrm!ListTypes.Column([purple][b]1[/b][/purple]) & "") = "FCBC Type" Then
      En = True
   End If

   sfrm!FCBCPeriod.Enabled = En
   sfrm!FCBCType2ID.Enabled = En
   sfrm!PRRT.Enabled = Not En
   sfrm!PTypeID.Enabled = Not En
   
   Set sfrm = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hello PHV and theAceman1

Thank you for your suggestions. All of the fields are located on the subform, [sfrm-ReferralDatatest]. The listbox, Listtypes, determines whether the related fields are enabled or not in the code. However, when the code is executed, there is no error and none of the fields are not enabled at all. I would like the enabled property to work dependent on the choice of the ListTypes value list. The Listtypes values are not based upon a lookup table or query but are located within the properties of the unbound ListTypes field. TheAceman1, I have tried your suggestion but have changed the name of the subform in your code as below. Once again, there are no errors, or disabling of the fields with your code as well.

Dim sfrm As Form, En As Boolean
'sfrm -ReferralDatatest
Set sfrm = [sfrm-ReferralDatatest].Form

If Trim(sfrm!ListTypes.Column(1) & "") = "FCBC Type" Then
En = True
End If

[sfrm-ReferralDatatest]![FCBCPeriod].Enabled = En
[sfrm-ReferralDatatest]![FCBCType2ID].Enabled = En
[sfrm-ReferralDatatest]![PRRT].Enabled = Not En
[sfrm-ReferralDatatest]![PTypeID].Enabled = Not En

Set sfrm = Nothing

Any other suggestions would be greatly appreciated.

Thank you
 
tinat said:
[blue]All of the fields are located on the subform . . .[/blue]
Try this:
Code:
[blue]   Dim En As Boolean

   If Trim(Me!ListTypes & "") = "FCBC Type" Then
      En = True
   End If

   Me![FCBCPeriod].Enabled = En
   Me![FCBCType2ID].Enabled = En
   Me![PRRT].Enabled = Not En
   Me![PTypeID].Enabled = Not En[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks for your help TheAceMan1 but unfortunately still no success. There continues to be no errors and no sign that any of the codes are working at all. Very frustrating as I am certain that the field names are correct. Spent too many hours trying to fix this quirk. Don't know what else to do to get it to work. Seems so simple an idea for the code. Any one else out there have any ideas on this one?

Thank you

Tina
 
Hello Folks

Just an update as I finally found the source of my troubles. The list box was not committing the value to the table and therefore the code was not executing. I changed the list box to a combo box and voila. It works!!!

What a bugger this one was, I hope that this solution can help someone else out before they spend oodles of time on it like I did!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top