Toggle button to show/hide column in subfrom

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having trouble with the correct syntax to refer to a control on a subform.

I created a toggle button on my main form (frmChrgBackLog) to show or hide a
column in my subform (subfrmChrgBackLog). The subform object name in the
main form is the same as the subform name. I tried multiple versions of code
to do this but neither of them have worked. The code will be in the main
form. Is this possible and if so what is wrong with my syntax? Thanks,

'Version 1
Me.subfrmChrgBackLog.Form!jobnumlong.Visible = _
Not Me.subfrmChrgBackLog.Form!jobnumlong.Visible

'Version 2
Me.subfrmChrgBackLog.Form.Controls("jobnumlong").Visible = _
Not Me.subfrmChrgBackLog.Form.Controls("jobnumlong").Visible

'Version 3
Forms!frmChrgBackLog!subfrmChrgBackLog.Form!jobnumlong.Visible = _
Not Forms!frmChrgBackLog!subfrmChrgBackLog.Form!jobnumlong.Visible
 
I double checked my names and the appear to be ok. My subform is in
datasheet view. Does that make a difference? Do I have to requery the
subform after hitting the toggle command button?

Is there an alternate way to accomplish the same result?

Thanks for your response. I appreciate your help.
 
Ah, yes, that makes a difference.

Me.subfrmChrgBackLog.Form!jobnumlong.ColumnHidden = _
Not Me.subfrmChrgBackLog.Form!jobnumlong.ColumnHidden
 
Thanks! That did the trick and it works great now. Thanks again for your time.

Have a great day!!
 
Back
Top