hiding a field based on chosen value in combo box

icemonster

Registered User.
Local time
Today, 09:06
Joined
Jan 30, 2010
Messages
502
ok.

i can make this work, but somehow, i can only do one choice. i have 4 choices, lets say A,B,C,D, if i choose B, i want field B to be visible, and also if i choose C, or even D.

yet somehow, i can only make it work for one. can anyone help me? here is the code.

Private Sub Status_AfterUpdate()
If Me.[Client Status] = "On Hold" Then
Me.Hold_Termination_Date.Visible = True
Else
Me.Hold_Termination_Date.Visible = False

End If

End Sub


any help will be greatly appreaciated.

also, is it possible to hide more than one field?
 
You would need a listbox to do this with it's MULTI-SELECT property set to SIMPLE or EXTENDED.

Then you could do this:

Code:
Dim varItm As Variant
 
For Each varItm In Me.ListBoxNameHere.ItemsSelected
   Me.Controls(Me.ListBoxNameHere.ItemData(varItm).Value).Visible = True
Next varItm

That is "air code" (untested) but it should work if the control name is the same as the field name and your listbox has the field names listed and is the bound column.
 
There are a variety of approaches.

If using the If-Then, you should be able to use the Or to get the right results ....

Code:
If Me.cmbBox.Column(x) = "A" Or Me.cmbBox.Column(x) = "B" ... Then
   Me.txtBox.Visible = True
Else
   Me.txtBox.Visible = False
End If


Or if usinga numbering system a Select Case ....

Code:
Select Case Me.cmbBox.Column(x)
Case 1    
   Me.txtBox1.Visible = True
   Me.txtBox2.Visible = False
   Me.txtBox3.Visible = False
Case 2 To 4
   Me.txtBox1.Visible = False
   Me.txtBox2.Visible = True
   Me.txtBox3.Visible = True
Case Else
   Me.txtBox1.Visible = False
   Me.txtBox2.Visible = False
   Me.txtBox3.Visible = True
End Select

Depends on how fancy you want to get. If a one-off, then any approach will work - if extensive, some iterating or self-referring piece of code might serve better ....

Hope that helps,

-dK
 
ok.

it worked, one more thing, what if i want to hide more than 1 field? like let say field C and D? how do i write it in code?

sorry if i posted two threads, my computer hanged, thought it didnt go through :(
 
no worries got it figured out. :D thanks. does anyone know who to have a date range on a subform?
 

Users who are viewing this thread

Back
Top Bottom