By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

How to hide field/s depending upon the value in other fields of same form in Access

P: 23
Hello everybody
Actually I am a beginner with MS Access and want to make my own data base for my patients (as I am Surgeon by profession). I explain you my new query...
Suppose we have two bound combo boxes, "PositiveGPE_Finding" and "Lymphnode_Gp" respectively, in same form named "History". "PositiveGPE_Finding" combo box have value list with Multiple Selection enabled and Values; Pallor, Jaundice, Cyanosis, Lymph Nodes. Combo box "Lymphnode_Gp" has its own values. Is it possible that "Lymphnode_Gp" combo box is only enabled when 'Lmph Node' value is checked in "PositiveGPE_Finding" combo box.....
I have tried using 'ItemData' and 'Selected' properties of combo box but could not succeed....

I tried this code in the AfterUpdate()event of cbo PositiveGPE_Findings but it didn't work as well...

Expand|Select|Wrap|Line Numbers
  1. Private Sub PositiveGPE_Findings_AfterUpdate()
  2.   Dim varItem As Variant
  3.   Dim ctl As Control
  4.  
  5.   Set ctl = Me![PositiveGPE_Findings]
  6.  
  7.   If ctl.ItemsSelected.Count = 0 Then Exit Sub
  8.  
  9.   For Each varItem In ctl.ItemsSelected
  10.     Me![Lymphnode_GP].Enabled = (ctl.ItemData(varItem) = "Lymph Node")
  11.   Next
  12. End Sub
Can you help me with this....???
May 2 '11 #1
Share this Question
Share on Google+
2 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
The ItemsSelected and varItem are for listboxes, not comboboxes.

You can test for nothing selected like so:
Expand|Select|Wrap|Line Numbers
  1. If Isnull(Me![PositiveGPE_Findings]) then Exit Sub
And use the .Value for checking whether to enable the control:
Expand|Select|Wrap|Line Numbers
  1. Me![Lymphnode_GP].Enabled = (Me![PositiveGPE_Findings].Value="Lymph Node")
A last thing to note is that .Value is the default property of textboxes and comboboxes, so if you simply write Me![PositiveGPE_Findings] it will be equivalent to Me![PositiveGPE_Findings].Value
May 2 '11 #2

P: 23
I tried this code as
Private Sub PositiveGPE_Findings_AfterUpdate()
If IsNull(Me![PositiveGPE_Findings]) Then Exit Sub
Me![Lymphnode_Gp].Enabled = (Me![PositiveGPE_Findings].Value = "Lymph Node")
End Sub
but it gives Run-time error '13' Type mismatch
...............
what to do....?
May 2 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.