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

Enable set of fields after selecting a particular item in combo box. 1

Status
Not open for further replies.

roaml

Technical User
Feb 19, 2002
264
US
Hello,

How can I get a set of fields to enable once a certain item is selected in a combo box?

For example, I have a combo box called “Activity” and an item listed in the combo list called “Verification”. I also have four other fields (“Verification Info”) associated with the item “Verification” (Verifier Name, Number, Company and VerDate). I would like to show the Verification Info section disabled until a user selects the item in “Activity” called Verification. When the item Verification appears in the combo box, the four fields in Verification Info will become enabled.

How can I do this?
 
Initally you need to set the "Enabled" Property of the said four fields to "False", either at On_Current, After_Insert, On_Open Event or whereever deemed appropriate to your context like say for example at BtnSave_Click event.

Second you will have to put the following code in Activity_AfterUpdate() Event

Code:
Private Sub Activity_AfterUpdate()
   If Not IsNull(Me.Activity)=True and Len(Trim(Me.Activity))>0 Then
      me.Verifier_Name.Enabled = True
      me.Number.Enabled = True
      me.Company.Enabled = True
      me.VerDate.Enabled = True
   Else
      me.Verifier_Name.Enabled = False
      me.Number.Enabled = False
      me.Company.Enabled = False
      me.VerDate.Enabled = False
      msgbox "Please Select an Activity", VbCritical,"User Alert"
      me.Activity.SetFocus
      Exit Sub
   End If
End Sub

Hope this helps...
Regards,
 
Sample code..
Code:
Private Sub ComboBox1_AfterUpdate()
	Select Case Me.ComboBox1.Value

	Case = "Some Value"
		'Do Something here

	Case = "Another Value"
		'Do Something else

	End Select
End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
To check for Activity = "Verification", you will have to code it like this...

Code:
Private Sub Activity_AfterUpdate()
   If Not IsNull(Me.Activity)=True and Len(Trim(Me.Activity))>0 And Me.Activity = "Verification" Then
      me.Verifier_Name.Enabled = True
      me.Number.Enabled = True
      me.Company.Enabled = True
      me.VerDate.Enabled = True
   Else
      me.Verifier_Name.Enabled = False
      me.Number.Enabled = False
      me.Company.Enabled = False
      me.VerDate.Enabled = False
   End If
End Sub

Regards,
 
Sorry HandsOnAccess..
Didn't refresh the page..


________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
Hello HandsOnAccess,

I am trying to implement the code and suggestion you provided. So far it is partially working. The problem I am having is with the isolation part. The four fields are enabled if a user selects any item from the “Activity” combo box. I would like the four fields enabled if the item “Verification” is selected only and if a user selects any other item in the combo box, the four fields remain disabled.

Almost there. :-D Thanks a bunch!

Here is the code I am using.

<BEGIN CODE>
Private Sub Form_Open(Cancel As Integer)

Me!Verifier_Name.Enabled = False
Me!Number.Enabled = False
Me!Company.Enabled = False
Me!VerDate.Enabled = False
End Sub

Private Sub Activity_AfterUpdate()

If Not IsNull(Me.Activity) = True And Len(Trim(Me.Activity)) > 0 Then
Me.Verifier_Name.Enabled = True
Me.Number.Enabled = True
Me.Company.Enabled = True
Me.VerDate.Enabled = True
Else
Me.Verifier_Name.Enabled = False
Me.Number.Enabled = False
Me.Company.Enabled = False
Me.VerDate.Enabled = False

MsgBox "Please Select an Activity", vbCritical, "User Alert"
Me.Activity.SetFocus
Exit Sub
End If

End Sub
<END CODE>
 
Modify the Private Sub Activity_AfterUpdate()
Use the code provided below

Code:
Private Sub Activity_AfterUpdate()
   If Not IsNull(Me.Activity)=True and Len(Trim(Me.Activity))>0 And Me.Activity = "Verification" Then
      me.Verifier_Name.Enabled = True
      me.Number.Enabled = True
      me.Company.Enabled = True
      me.VerDate.Enabled = True
   Else
      me.Verifier_Name.Enabled = False
      me.Number.Enabled = False
      me.Company.Enabled = False
      me.VerDate.Enabled = False
   End If
End Sub

Rest seems to be ok...

Regards,
 
YOU ARE THE BEST!!!!!!!!!!!!!!

It works great. Thank you sooo much.

Happy, happy. [thumbsup2]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top