Dale Fye
asked on
Hide columns in a subform that is using a query as the SourceObject
I'm using a dynamic query to identify records with write conflicts (different Modified_DT values) between Access and Azure tables (there will eventually be over 20 of these tables that require synchronization). Because of the number of tables which must be synched, I would prefer not to create separate subforms as this would be extremely time consuming.
Instead, I have a dynamic query which provides me with the records I want to view, including all of the columns in the two tables. Instead of a datasheet form, I'm using the query as the SourceObject for this subform, as shown in this image:
But I would like to hide the PD_ID, Well_ID, and DateRecorded columns. I know I could do this with a datasheet subform, but I don't want to create a separate datasheet for each of the 20+ tables.
So what I need to know is whether I can hide these columns and if so, how?
FormName: frm_Synch_Data
subformName: sub_Write_Conflict_Records
Instead, I have a dynamic query which provides me with the records I want to view, including all of the columns in the two tables. Instead of a datasheet form, I'm using the query as the SourceObject for this subform, as shown in this image:
But I would like to hide the PD_ID, Well_ID, and DateRecorded columns. I know I could do this with a datasheet subform, but I don't want to create a separate datasheet for each of the 20+ tables.
So what I need to know is whether I can hide these columns and if so, how?
FormName: frm_Synch_Data
subformName: sub_Write_Conflict_Records
For any column - assuming Datasheet View .... that you want to hide, give the Name of that control something like txtSomeColumeName.
Then in VBA code ... say in the Load or Open event or OnCurrent even ....
Me.txtSomeColumeName.ColumnHidden = True ' Or False
You must refer to the Control Name ... and to avoid issues .... make sure it's different than the Control Source ... ie prefix it with txt or cbo ...
Then in VBA code ... say in the Load or Open event or OnCurrent even ....
Me.txtSomeColumeName.ColumnHidden = True ' Or False
You must refer to the Control Name ... and to avoid issues .... make sure it's different than the Control Source ... ie prefix it with txt or cbo ...
Dale ... it's YOU lol ... completely missed that
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
More info on how to do this:
Manually create the "ColumnHidden" property on your querydef columns by first manually hiding, then unhiding the columns. This will create the ColumnHidden property on the querydef field.
(I tried creating it with VBA, which you can do, but results were better with manual creation.)
Use VBA to set the ColumnHidden property of a column to true or false
set the subform source object to the query.
See the attached example. Set the properties in the form load event. I have not tested what changing the querydef columns/SQL does to the ColumnHidden property.
HideSubformQueryColumns_Dale.accdb
Manually create the "ColumnHidden" property on your querydef columns by first manually hiding, then unhiding the columns. This will create the ColumnHidden property on the querydef field.
(I tried creating it with VBA, which you can do, but results were better with manual creation.)
Use VBA to set the ColumnHidden property of a column to true or false
set the subform source object to the query.
See the attached example. Set the properties in the form load event. I have not tested what changing the querydef columns/SQL does to the ColumnHidden property.
HideSubformQueryColumns_Dale.accdb
ASKER
Got an easier answer from another source:
forms("frm_Splash").sub_Wr ite_Confli ct_Records .Form("PD_ ID ").ColumnWidth = 0
I can use this without having to create the property in the querydef, for each of the the columns I want to hide.
forms("frm_Splash").sub_Wr
I can use this without having to create the property in the querydef, for each of the the columns I want to hide.
@Dale: Your code seems to indicate that you are talking about a datasheet form sourceobject, not a query.
I tried following your logic to apply it to a querydef sourceobject, but couldn't get it to work. What's your code format?
Does this work for a query sourceobject, or do your names just make it look like a form, but are really a query? If it's a query, then nice trick. Wish I'd thought of it....
I tried following your logic to apply it to a querydef sourceobject, but couldn't get it to work. What's your code format?
Does this work for a query sourceobject, or do your names just make it look like a form, but are really a query? If it's a query, then nice trick. Wish I'd thought of it....
Dale, how about just moving the columns you don't want to see all the way to the right or just removing them from the query if you don't need them?
If I misunderstood your question give some info