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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable and Diable Areas on a Form depending on choice 2

Status
Not open for further replies.

mpsDA

IS-IT--Management
Jul 27, 2005
43
GB
I've seen this example within Microsoft access HELP!. I want to Create a option on my form for example YES or NO. If the User selects YES, the area is greyed out. If the user Selects NO, the area is enabled for the user to use or enter data.

How can this be done please.
 
with event handlers and enabled function...

--------------------
Procrastinate Now!
 
You need to use the After_Update Event on the Control containing the "Yes/No". Example below based on a combo box for Appointment Required:

Private Sub cboApptReq_AfterUpdate()

Select Case cboApptReq.Value
Case Is = "No"
txtAppointmentDate.Enabled = False
txtAppointmentTimeFrom.Enabled = False
txtAppointmentTimeTo.Enabled = False

Case Is = "Yes"
txtAppointmentDate.Enabled = True
txtAppointmentTimeFrom.Enabled = True
txtAppointmentTimeTo.Enabled = True
End Select

End Sub

Hope this helps.

Mark...

[Worm]

 
How are ya mpsDA . . . . .

Here's an example using a Checkbox:
[ol][li]In the [blue]Tag[/blue] property of the [blue]controls of interest[/blue], add a question mark ([blue]?[/blue]). You can group select and make one entry for all.[/li]
[li]Set the following [blue]properties[/blue] for the checkbox:
[ol a][li]Default Value [purple]False[/purple][/li]
[li]Triple State [purple]No[/purple][/li][/ol][/li]
[li]In the [blue]code module[/blue] of the form, copy/paste the following routine:
Code:
[blue]Public Sub EnableHandler()
   Dim ctl As Control
   
   For Each ctl In Me.Controls
      If ctl.Tag = "[purple][b]?[/b][/purple]" Then
         ctl.Enabled = Me![purple][b]YourCheckboxName[/b][/purple]
      End If
   Next

End Sub[/blue]
[/li]
[li]Next, in the [blue]AfterUpdate[/blue] event of the checkbox and [blue]OnCurrent[/blue] event of the form, copy/paste the following line:
Code:
[blue]   Call EnableHandler[/blue]
[/li][/ol]
[purple]Thats it! ........[/purple]

Calvin.gif
See Ya! . . . . . .
 
I have done the one from edsuk, it allows me to choose my option. i.e when i select pass toggle button the open form button is disbled. When i select Fail the open form is enabled. But once i switch between records the option stays the same for each record. eg the open form button stays the same for all. Can you help?????????
 
Place the code in the Current event procedure too.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Need more help!!
Tryed that place that code in the event procedure afterupdate and beforeupdate

still no change.
 
Put the same code in the 'Current' event of the Form itself.

Mark...
 
Do you enter the code in the Before update and after update events??
 
mpsDA

You place the same code in two places (or you can use a sub procedure and call it from two places). The places you place the code are: Form_Current() and ComboBox_AfterUpdate(), see an example below which uses a sub procedure.

Private Sub SetOther()

If Me.cboHowRecd = "Other" Then
Me.txtHowOther.Enabled = True
Me.txtHowOther.SetFocus
Else
Me.txtHowOther.Enabled = False
Me.txtHowOther = Null
End If

End Sub

Private Sub Form_Current()

Call SetOther

End Sub


Private Sub cboHowRecd_AfterUpdate()

Call SetOther

End Sub

As you can see the code is placed on the After Event of the combo box so should the value change the procedure will be called. It is also placed on the Form_Current event so that should the user move to a different record the procedure gets called and sets the text box accordingly.

Regards Mark...

[worm]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top