setting widths on a form in datasheet view

  • Thread starter Thread starter John S. Ford, MD
  • Start date Start date
J

John S. Ford, MD

I have a form with several subforms which present data in a datasheet view.
Is there a property that allows me to set the widths of the various fields
and lock them (in the same manner as the ColumnWidths property of a
ComboBox)?

I'm trying to make it so users can't adjust the widths on their own.

John
 
You can't lock them, but you can reset the widths after
loading the form. And if necessary, in every other form
event.
frm.fields(i).ColumnWidth

(david)
 
David,

Can you give me some sample code that will do this? I've tried

Private Sub Form_Open(Cancel As Integer)
Me.Fields(1).ColumnWidth = 500
Me.Fields(2).ColumnWidth = 500
End Sub

I get the error message "Method or Data Member not found". What am I doing
wrong?

John
 
Actual code in use:
Sub gsbBS_AutoFit(f As Form)
'2003/03/16 dlg from BK
Dim intField As Integer

For intField = 0 To f.Count - 1
If TypeOf f(intField) Is Label Then
Else
If f(intField).Name = "Summary" Or Left(f(intField).Name, 1) =
"_" Then
f(intField).ColumnWidth = 0
Else
f(intField).ColumnWidth = -2
End If
End If
Next

End Sub

If you look carefully, you will see that the example I
gave you previously was wrong..... should be

(david)
 
David,

I can't seem to get that to work either. I used:

Private Sub Form_Open(Cancel As Integer)
without success. Any idea what I'm doing wrong? I'm using Access 97. Does
that matter?

John
 
Our forms have labels as well as chkbox, textbox, combo box.
You should check the type or the controltype to make sure that
you aren't trying to change the width of a label control.

Also, our code is normally called from a parent form
Load/click/change event, not from the subform Open
event as you have shown.

(david)
 
How many fields do you have on the form?

Collections start at 0, so if you only have 2 fields you're trying to
control, you need

Private Sub Form_Open(Cancel As Integer)
Me(0).ColumnWidth = 500
Me(1).ColumnWidth = 500
End Sub
 
Here is a previous post of mine on this subject.

From: Stephen Lebans
([email protected])
Subject: Re: Freeze Column?
View: Complete Thread (3 articles)
Original Format
Newsgroups: microsoft.public.access.forms,
microsoft.public.access.formscoding,
Date: 2003-12-24 11:53:00 PST

For programmatic control for forms in Datasheet view my standard
response is:

1) Michael Kaplan has an excellent article on manipulating Datasheets
here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmart
01/html/sa01b1.asp

2) An API solution is here:
http://www.lebans.com/autocolumnwidth.htm
The AutoSizing project also contains a method to FREEZE the
ColumnWidths.


--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
David,

Do the references I've made in my code refer to CONTROLS? I thought they
referred to FIELDS in the underlying data source of the subform.

Also, does it matter if the code is for a subform rather than the parent
form?

John
 
Fields don't have a display width. Only the controls that display them do.

And yes, it definitely makes a difference if you're trying to control the
subform, not the parent form.

If you're trying to do this from a module associated with the parent form
(say, for example, in Form_Load of the parent form), you need to refer to
Me!SubformControlName.Form.Controls(1) where SubformControlName is the name
of the subform control on your parent form (which will be the name of the
subform itself by default).

See http://www.mvps.org/access/forms/frm0031.htm for details of how to refer
to subform controls.
 
we have code like
gsbAutoFit(me.sbfData.form)

So our code is FOR the subform. I don't know what you are seeing,
but sometimes if you call code from the wrong event the form won't
be loaded yet, so I just thought I would mention how we actually
do it in practice.

(david)
 
I have a form with several subforms which present data in a datasheet
view. Is there a property that allows me to set the widths of the
various fields and lock them (in the same manner as the ColumnWidths
property of a ComboBox)?

I'm trying to make it so users can't adjust the widths on their own.

You've got the answers to do this, but is it really so terrible to allow
your users some freedom - where's the harm?
 
I don't mind giving users freedom to alter the widths but I want them back
to specific widths when they're done and someone else has to use them.

John
 
So put code in the form's Load event to set the widths.

Each user should have his/her own copy of the front-end anyhow, so it
shouldn't really matter. If User A wants column 2 to be 2 inches wide, and
User B only wants it to be 1 inch wide, let them: their making a change in
their copy of the front-end won't affect anyone else.
 
Yeah, but...
You are talking about datasheet view of forms - each user should have their
own copy of the frontend on their computer, linked to the backend on the
server.

Having multiple users accessing the same frontend is asking for trouble.
 
Back
Top