Link to home
Start Free TrialLog in
Avatar of leeroypitre
leeroypitre

asked on

.ColumnWidth not changing in datasheet

Most of the time either one of theses seems to work.  however, at some point something happens in the form where after execution of either of these statements, the column is still set to "1410"

Me.subform_RBWS_TA_TEAM_DATASHEET.Form(vSplitItem(0)).ColumnWidth = 0

Me.subform_RBWS_TA_TEAM_DATASHEET.Form(vSplitItem(0)).Properties("ColumnWidth") = 0
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Have you tried:

Me.subform_RBWS_TA_TEAM_DATASHEET.Form.controls(vSplitItem(0)).ColumnWidth = 0
Avatar of leeroypitre
leeroypitre

ASKER

BTW using MS Access 2013

.controls, that did not work either.   No error, just width seems unchanged.  The reason this is coming up, I confirmed that the .ColumnHidden stops working sometimes when the .ColumnWIdth is modified programmatically. And it does not seem to have to be the same column.  Therefore, when .ColumnHidden = true stops working, I was trying a workaround with .ColumnWidth.

What I narrowed down is if I do not modify .ColumnWidth with vba (even = 0) .ColumnHidden seems to be more reliable.

I'm not seeing anything online about reported bugs or conflicts with these two properties?
Whenever you change the ColumnWidth on a hidden datasheet column, Access assumes you want the column to be seen, so it automatically "unhides" the column.  Make sure you "rehide" any columns you want hidden when changing column widths.
To eliminate the issues with trying to manage subform handling syntax, try running the subform as a regular form outside of the parent form and get your column width sizing to work as desired, if you can.
If not, create a datasheet form and run your own experiments with manipulating column widths and hidden columns.  There's plenty of help available with the right google search.
Whats the reason for hiding the columns?

It might just be simpler  (Coding wise) to create another subform (without the un-needed columns)
...and just swap the subforms programmatically.
Something like this on a button on the main form will toggle the subforms:

If [YourOriginalsubformName].SourceObject="YourOriginalsubformName" Then
    [YourOriginalsubformName].SourceObject="YourAlteredsubformName"
Else
    [YourOriginalsubformName].SourceObject="YourOriginalsubformName" 
End if

Open in new window



JeffCoachman
the reason for hiding is user preference. Our system is a highly automated dynamic application.  Different planning or mechanical projects manage projects differently. Multi forms is not feasible, since there would be a huge number of possibilities.  Although, all of these comments give me additional ideas to rethink our approach.
For Dynamic Behavior you could switch to Continuous form and place the Controls on the fly while assigning the ControlSource.
You might want to take a look at this article and the accompanying database to see what I did for a similar situation, where different users wanted to see the same data differently.

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.