Conditional hiding of sub form controls in Ms Access

I want to hide two controls in a sub form based on the condition selected from the parent form , I have tried all what I can , nothing is working out my code is on sub form before update event:

If (Me.Parent!txtProductCH <> [Purchase Order]) Then
Me.CboProduct.Visible = False
ElseIf (Me.Parent!txtProductCH = [Purchase Order]) Then
Me.CboProduct.Visible = True
ElseIf (Me.Parent!txtProductCH <> [Purchase Order]) Then
Me.CboPrices.Visible = False
ElseIf (Me.Parent!txtProductCH = [Purchase Order]) Then
Me.CboPrices.Visible = True
End If

Open in new window



Where do go wrong here?

Regards

Chris
LVL 3
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
With so many ElseIf i think i am lost but ...i will give it  a try
Dim showVisible as boolean
showVisible =(Me.Parent!txtProductCH = [Purchase Order])
Me.CboProduct.Visible = showVisible 
Me.CboPrices.Visible =   showVisible 

Open in new window

Mark EdwardsChief Technology OfficerCommented:
First, is your subform a datasheet or a continuous form.  The two are handled in completely different ways.

Also, be aware that there is only 1 true control on a datasheet or continuous form, and that is the row that is selected.
All the other rows have "screen repeats" of the condition of the controls for the selected row.  Only "Conditional Formatting" can change things like back color, forecolor, bold, and underline, etc on each row.  You can't hide a control on one row and make it visible on another row.  It's all rows or no rows.  It all depends on what condition you set on the selected row.

Datasheets are harder to play "tricks" with than continuous forms.

So, what does thou useth?
Hamed NasrRetired IT ProfessionalCommented:
Try:

If (Me.Parent!txtProductCH <> [Purchase Order]) Then
	Me.CboProduct.Visible = False
	Me.CboPrices.Visible = False
Else
	Me.CboProduct.Visible = True
	Me.CboPrices.Visible = True
End If

Open in new window

Hamed NasrRetired IT ProfessionalCommented:
Or:
If (Me.Parent!txtProductCH = [Purchase Order]) Then
      Me.CboProduct.Visible = True
      Me.CboPrices.Visible = True
Else
      Me.CboProduct.Visible = False
      Me.CboPrices.Visible = False
End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark EdwardsChief Technology OfficerCommented:
I am assuming that you want to change the visibility of your controls on a subform that is a datasheet or a continuous form.
The code that has been given so far should be put into your subform's Form_Current() event if you want it to fire when you select a record.
The controls' visibility will be set for the conditions on the record that is selected and only for the conditions in that record.  No data in any other records matter - they won't be considered.

So if the code If (Me.Parent!txtProductCH = [Purchase Order])  is equal to True, then Me.CboProduct.Visible = True will be the case for the control CboProduct for ALL records in the subform.  
If (Me.Parent!txtProductCH = [Purchase Order])  is equal to False, then Me.CboProduct.Visible = False will be the case for the control CboProduct for ALL records in the subform.

Chris, I've got a feeling from the responses I'm seeing that a lot of folks don't really know what you are trying to do.  Please explain a little more in detail.  "Draw us a picture."
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.