How to Change Column Property with VBA

 Change Column width on datasheet with VBA

If you have a column name “Exam1” you can change the column width by coding on VBA.

The more number of width is the bigger column length. We use a ColumnWidth after a field name. Put a code below the On Load Event of datasheet form or subform.

on load

Private Sub Form_Load()

Me.Exam1.ColumnWidth = 1000

Me.Exam2.ColumnWidth = 2000

End Sub

Comparison of two columns set the column width to 1000 and 2000

change column width

Hide a Column on datasheet with VBA

We use the ColumnHidden property after the fieldname on the On Load Event of form. For instance, We want to hide a field name “Exam1” on subform or any form when open the form. We use the code “Me.Exam1.ColumnHidden = True” as shown below including the result after form is loaded. The Exam 1 will not display on the Datasheet form.

hide columnhide result

Change a Column Name on datasheet with VBA

You have a field name “Exam1” with a label name “Exam1_label” on the form. When form is loaded the column name will show as “Exam1” for Exam1 field. If you want to change the column name or caption name to “Test #1” then use the code below on the On Load Event of form. After form is loaded, a column name will display as “Test #1” for Exam1 field.

Private Sub Form_Load()

Me.Exam1_Label.Caption = “Test #1”

End Sub

change name
Besides, its impact gets to be perceptible much viagra from canada sooner. Having poor nutrition, being obese or overweight, and inadequate performing exercise is all that is associated with most of these drugs is that they are contra indicated for many people as a flaccid penis will levitra no prescription gain a few pounds. The effect of this erectile dysfunction drug lasts for six hours after the intake of the purchase viagra online cute-n-tiny.com drug. Patients should decrease fluid intake before bedtime, viagra soft 50mg moderate the consumption of alcohol and caffeine-containing products, and follow timed voiding schedules.

Change a Column Name linked to a field in another table with VBA

The previous example is a hard coding to change a label name from Exam1 to “Test #1.”

If you want to change the column name or caption name to “Test #1” or something else that entered in another table, then you can use the Dlookup function to get the name from that table. The example below is assigning the Exam1 column name = “Test#1 (50)” on the Exam1 Title field with a max score 50 from the tblClass table where ClassID = ClassCode on the subform or current form.

Me.Exam1_Label.Caption = DLookup(“E1Title”, “tblClass”, “[ClassID] = ” & Me.ClassCode)

class info

After form is loaded, a column name will display as “Test #1 (50)” for the Exam1 field.

change caption link

Change a Column Order on datasheet with VBA

You also can change the order of column on your subform or datasheet form by using the ColumnOrder after a field name as “Me.Exam1.ColumnOrder = 1”. After form is loaded, a column order of field name Exam1 will be placed at front of all columns shown below.

Private Sub Form_Load()

Me.Exam1.ColumnOrder = 1

Me.Exam2.ColumnWidth = 2000

End Sub

column order

Related posts