Conditional hiding of sub form controls in Ms Access

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer
Commented:
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 Officer

Commented:
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 Professional

Commented:
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

Retired IT Professional
Commented:
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
Mark EdwardsChief Technology Officer

Commented:
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."

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial