On Change event

craigcain

Registered User.
Local time
Today, 08:28
Joined
Sep 26, 2007
Messages
15
Hi,

I am trying to add an event to a combo box that has two values (yes, no) so that when yes is selected other options appear. I have tested the code in all sorts of different ways but all I could manage was making the other options appear whether I selected yes or no.

Here is my code:

Code:
Private Sub Insurers_Informed_Change(Cancel As Integer)
If Insurers_Informed.AfterUpdate = Yes Then
    Me.Label97.Visible = True
    Me.txtInsureDate.Visible = True
    Me.Label99.Visible = True
    Me.txtInsureMethod.Visible = True
    Me.Label101.Visible = True
    Me.txtInsureWhom.Visible = True
Else
    Me.Label97.Visible = False
    Me.txtInsureDate.Visible = False
    Me.Label99.Visible = False
    Me.txtInsureMethod.Visible = False
    Me.Label101.Visible = False
    Me.txtInsureWhom.Visible = False
End If
End Sub

I realise that this probably isnt the most efficient way of writing the code. I need the three labels and textboxes to appear when yes is selected but then disappear again if the user selects no.

Any help would be much appreciated.
 
Hi,

I am trying to add an event to a combo box that has two values (yes, no) so that when yes is selected other options appear. I have tested the code in all sorts of different ways but all I could manage was making the other options appear whether I selected yes or no.

Here is my code:

Code:
Private Sub Insurers_Informed_Change(Cancel As Integer)
If Insurers_Informed.AfterUpdate = Yes Then
    Me.Label97.Visible = True
    Me.txtInsureDate.Visible = True
    Me.Label99.Visible = True
    Me.txtInsureMethod.Visible = True
    Me.Label101.Visible = True
    Me.txtInsureWhom.Visible = True
Else
    Me.Label97.Visible = False
    Me.txtInsureDate.Visible = False
    Me.Label99.Visible = False
    Me.txtInsureMethod.Visible = False
    Me.Label101.Visible = False
    Me.txtInsureWhom.Visible = False
End If
End Sub

I realise that this probably isnt the most efficient way of writing the code. I need the three labels and textboxes to appear when yes is selected but then disappear again if the user selects no.

Any help would be much appreciated.



you need a me.fresh in there to make this work otherwise it will run once
 
Seems to me Insurers_Informed is a control on your form. If so, the AfterUpdate property of it, is a text property, I think, not a Yes/No thingie.

Is Insurers_Informed the combo? Does it contain "Yes" or "No"?

If so, you might try
1 - use the AfterUpdate event in stead on the on Change
2 - try the following test
Code:
If Insurers_Informed = "Yes" Then
    Me.Label97.Visible = True
    Me.txtInsureDate.Visible = True
    Me.Label99.Visible = True
    Me.txtInsureMethod.Visible = True
    Me.Label101.Visible = True
    Me.txtInsureWhom.Visible = True
Else
    Me.Label97.Visible = False
    Me.txtInsureDate.Visible = False
    Me.Label99.Visible = False
    Me.txtInsureMethod.Visible = False
    Me.Label101.Visible = False
    Me.txtInsureWhom.Visible = False
End If
Or
Code:
    Dim fAnswer as Boolean

    fAnswer = (Insurers_Informed = "Yes") 
    Me.Label97.Visible = fAnswer
    Me.txtInsureDate.Visible = fAnswer
    Me.Label99.Visible = fAnswer
    Me.txtInsureMethod.Visible = fAnswer
    Me.Label101.Visible = fAnswer
    Me.txtInsureWhom.Visible = fAnswer
 
I had a bit of a play with the change event and it seems to be working fine now. I changed the afterupdate check to Insurers_Informed.value

Thanks for the replies

Code:
Private Sub Insurers_Informed_Change()
If Insurers_Informed.Value = "Yes" Then
    Me.Label104.Visible = False
    Me.txtNotInformed.Visible = False
    Me.Label97.Visible = True
    Me.txtInsureDate.Visible = True
    Me.Label99.Visible = True
    Me.txtInsureMethod.Visible = True
    Me.Label101.Visible = True
    Me.txtInsureWhom.Visible = True
Else
    Me.Label104.Visible = True
    Me.txtNotInformed.Visible = True
    Me.Label97.Visible = False
    Me.txtInsureDate.Visible = False
    Me.Label99.Visible = False
    Me.txtInsureMethod.Visible = False
    Me.Label101.Visible = False
    Me.txtInsureWhom.Visible = False
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom