J
Jim Franklin
Hi,
I have a form which opens as a datasheet. The form contains a number of
unbound controls which have their controlsource property set in the forms
Open event. (This is because the list of fields can potentially change every
time the form is opened.)
My problem is that I want to fix some of the column widths of the datasheet
so that any adjustments to widths made previously by a user are removed when
the form is opened. I do this by setting the control's .columnwidth property
in the form's Load event.
This has always worked for me (and indeed works for other forms in the same
app.) but for some reason here it has no effect.
The following is an example just for control txtbox1 to simplify things.
every time the form opens, txtbox1 retains the column width of when it was
last closed. Here is all my code for the form:
Private Sub Form_Load()
Me.txtbox1.ColumnWidth = 1000
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim fld As Field
For i = 1 To 100
Me.Controls("txtbox" & i).ColumnHidden = True
Next i
i = 1
For Each fld In Me.RecordsetClone.Fields
If fld.Name = "ProjectID" Or fld.Name = "ProjectDescription" Or
fld.Name = "OracleNumber" Or fld.Name = "PONumber" Then 'do nothing
Else
Me.Controls("lbl" & i).Caption = fld.Name
Me.Controls("txtbox" & i).ControlSource = fld.Name
Me.Controls("txtbox" & i).ColumnHidden = False
i = i + 1
End If
Next fld
End Sub
Note: I have also tried opening the form WITHOUT the Open event code, to see
if something in here is affecting it, but makes no difference.
If anyone has any ideas, I would be very grateful. Thank you!
Jim
I have a form which opens as a datasheet. The form contains a number of
unbound controls which have their controlsource property set in the forms
Open event. (This is because the list of fields can potentially change every
time the form is opened.)
My problem is that I want to fix some of the column widths of the datasheet
so that any adjustments to widths made previously by a user are removed when
the form is opened. I do this by setting the control's .columnwidth property
in the form's Load event.
This has always worked for me (and indeed works for other forms in the same
app.) but for some reason here it has no effect.
The following is an example just for control txtbox1 to simplify things.
every time the form opens, txtbox1 retains the column width of when it was
last closed. Here is all my code for the form:
Private Sub Form_Load()
Me.txtbox1.ColumnWidth = 1000
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim i As Integer
Dim fld As Field
For i = 1 To 100
Me.Controls("txtbox" & i).ColumnHidden = True
Next i
i = 1
For Each fld In Me.RecordsetClone.Fields
If fld.Name = "ProjectID" Or fld.Name = "ProjectDescription" Or
fld.Name = "OracleNumber" Or fld.Name = "PONumber" Then 'do nothing
Else
Me.Controls("lbl" & i).Caption = fld.Name
Me.Controls("txtbox" & i).ControlSource = fld.Name
Me.Controls("txtbox" & i).ColumnHidden = False
i = i + 1
End If
Next fld
End Sub
Note: I have also tried opening the form WITHOUT the Open event code, to see
if something in here is affecting it, but makes no difference.
If anyone has any ideas, I would be very grateful. Thank you!
Jim