Toggle button to show/hide column in subfrom

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
 
G

Guest

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.
 
D

Douglas J. Steele

Ah, yes, that makes a difference.

Me.subfrmChrgBackLog.Form!jobnumlong.ColumnHidden = _
Not Me.subfrmChrgBackLog.Form!jobnumlong.ColumnHidden
 
G

Guest

Thanks! That did the trick and it works great now. Thanks again for your time.

Have a great day!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top