How do I set size of colums in a table subform datasheet view in MS Access
Asked Answered
C

11

6

I have a subform bugging me. The mainform contains buttons etc. Everytime the user close/open the form, the columns width is reset to whatever the table likes. If i open the table directly, the size is as i want. If i change it in the subform, it is not saved. (See screendump)

I would like "Phase" to stay about 2 cm width. I can enter the subform and edit the "Width" but that is only applied to the other views.

crop

I hope you can help, Emil.

Cowherb answered 6/3, 2015 at 10:16 Comment(4)
Open the Main form in Design. Go to the SubForm. Click on the square at the top left of the SubForm and select 'Properties'. Right-Click the control 'Phase' and click 'Properties'.Click the 'Format' tab and select 'Width'. What do you see there? That should control the widht of control 'Phase' unless you have some overriding coding elsewhere.Prim
Indeed, columns in Datasheet view are all of the same width, regardless of the control width defined in Form view. None of the current answers works. THe only solution I have found uses VBA: https://mcmap.net/q/1775227/-set-column-width-in-datasheet-view-in-split-formReconvert
The easiest would be to to go into LAYOUT VIEW instead of DESIGN VIEW and just drag the size of the column to the desired widthHell
If you close with a button, you can use VBA DoCmd.Close acForm, "FormName", acSaveYes - This will store column widths. acSaveNo keeps column widths unsaved.Openhearth
H
6

I realize this post is almost 2 years old, but I ran into the same problem and came across this post.

I am running MS Access 2013 on Windows 7 Ultimate. I did not find the solutions offered here to work for me, so, I set out to find something that would work for me before I went to VBA code. (Incidentally, I appreciate the link offered by @Patrick_Honorez in his comment on the original post because that was going to be my fall-back solution.)

Anyway, here is what worked for me and I hope perhaps it will work for others as well:

  1. Open the parent form.
  2. In the subform, right-click the column header for the column for which you wish to adjust the width.
  3. Select the “Field Width” item from the context menu.
  4. In the “Column Width” dialog that appears in step 3, enter the desired column width in points, or, use the [Best Fit] button. Then click the [OK] button to close the dialog and return to the form.
  5. Right-click the parent form’s border to bring up the parent form’s context menu. Click the “Save” item in the context menu.
  6. Now close the parent form.
  7. The next time the form is loaded, the column widths should be as set it step 4 above--at least they are for my setup.
Hallucination answered 16/2, 2018 at 19:23 Comment(3)
You have to set it manually with the mouse, so to speak. Drag it wider and hit save. Restart and see if its saved. I use this method now, as it is the fastest :)Cowherb
Yes, that works too, but I would not say that you "have" to set it that way; it works that way, and the way described above.Hallucination
@Hallucination is there a way to get the subform to display in dataset rather than 'single form' view when in design view so I can click on the column header?Lannielanning
C
1

In Access 365, open main form, right-click sub-form datasheet columns that need width adjustment, use the Field Width to adjust, click on border of main form to select Layout view, and save changes.

Congest answered 26/3, 2020 at 14:48 Comment(0)
C
1

I see this post is quite old and OP must have figured someway to tackle the issue. I came across same issue today and found solution on this link. For anybody else having same issue, use following code (I modified the code a little because original code from the above mentioned post saves column width of only text boxes but my form has combo boxes too, column width of which was not getting saved) in close and open events of your subform and then open main form in Form View and then manually select desired widths either by mouse, by entering column width value or using best fit. Save the form and reopen to check results. That's it.

Private Sub Form_Close()
    Dim ctrl As Control

    For Each ctrl In Me.Controls
        If (ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox) Then
            SaveSetting "propertiesDBS", Me.Name, ctrl.Name, ctrl.ColumnWidth
        End If
    Next
End Sub


Private Sub Form_Open(Cancel As Integer)
Dim ctrl As Control
Dim frm As Form
Dim w As Long
    For Each ctrl In Me.Controls
        If (ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox) Then
            w = GetSetting("propertiesDBS", Me.Name, ctrl.Name, 0)
            If w <> 0 Then ctrl.ColumnWidth = w
        End If
    Next
End Sub
Cleptomania answered 29/4, 2020 at 11:23 Comment(0)
D
1
  1. Open subform in datasheet view (by double click on subform in the left pannel)
  2. Resize columns as you want by dragging or by right-click the column header for the column for which you wish to adjust the width and select the “Field Width” item from the context menu.
  3. Right-click the subform border to bring up the context menu. Click the “Save” item in the context menu.
Desecrate answered 29/10, 2020 at 22:5 Comment(0)
T
1

I know this is late to the party and most likely going to be the last comment anyone reads, but this can be done quite simply in MS Access 2016 - by someone like myself who has no more than 4 days experience in databasing overall and no experience with writing custom Macro's or VB Script (using only what is native to MS Access).

Here's how I did it.

Scenario - Split Form (Form + Datasheet).

Extra Recommendations:

  1. It pays to be across all properties of every object type in your database, as a change in a field property can cause unpredictable erratic effects, which take ages to figure out why it happened and how to stop it from happening again, whilst delivering your desired outcome.

  2. Me.Requery in your VBA script after every necessary event and also in your main form (generally the 'After Update' event is used most), and be wary that too many Me.Requery's (in unnecessary events) can also be detrimental - so too much of a good thing can be a bad thing.

Bottom Line Up Front - Modify the format of your query that is to be exported/printed.

  1. In 'Design View' of the query you are concerned with, ensure that the fields are in the order you need them outputted in first as this is exactly how the macro will present them for export/print (example could be "Australia" then "Northern Territory" then "Town's In The Northern Half Of The State" then "Darwin" then "Suburbs In The Northern Half Of City").

  2. Switch to 'DataSheet View' in the same query and use the top left folded over triangle looking thingy to highlight the entire data set then right click that same triangle to present an options menu. Select 'Row Height' and type in "15" (default row height in Excel).

  3. Deselect the entire spreadsheet and this time select every column (left click the left most column, hold shift button, scroll over to the right to the far end of the data set and click the last column) and then right click one of the highlighted columns to present another menu. Select 'Field Width' and within that new pop-up menu select 'Best Fit' and then 'OK'.

  4. (Optional - not sure if this helps or hinders but I did it for my purpose) With the columns still selected right click one of the highlighted columns again and select 'Freeze Fields'.

  5. My scenario had buttons with macros configured to run filtered reports so I was able to check this by simply clicking any of those buttons and seeing the report formatting, which it held true to the work I had just done. I exported using another button with a macro that exports to Excel with 'Print Formatting' selected (my main form also had the datasheet view as the only thing that could be printed and was also set in 'Print' formatting.

The Excel spreadsheet opened with all row heights and column widths in a way that I could read every field/record with perfect ease and without extra modification.

This also worked for cascaded combo boxes, with the export only outputting the 'drilled down/filtered' datasheet records, in a format that required no further modifications.

Hope this helps someone, as its saved my hide! :)

Translative answered 9/4, 2021 at 10:14 Comment(1)
Further updates: Microsoft Excel default row height is actually 14.25 (my apologies) If your exported excel spreadsheet report opens with random column widths, I found if you go back into the respective query and double click in-between each column (automatic resize) this may also help.Translative
P
0

Open the Main form in Design. Go to the SubForm. Click on the square at the top left of the SubForm and select 'Properties'. Right-Click the control 'Phase' and click 'Properties'.Click the 'Format' tab and select 'Width'. What do you see there? That should control the widht of control 'Phase' unless you have some overriding coding elsewhere. Input the size you want and see what happens.

Prim answered 6/3, 2015 at 16:15 Comment(3)
Hi. I have already tried that. It says 2 cm. But it is about 4-5 cm. The problem is when i go into design view, it does not show the subform as a table, but as list of textboxes with captions... A total different view. But when i go back to view mode, it is a table, as when a table is opened directly.Cowherb
Your subform can be viewed as a datasheet or as a form. Perhaps you need to change the view. Try right-clicking on the subform.Prim
I tried that. Sometimes, it is just shown as a white box with the text in the upper left corner as "Table.Name" instead of showing the actual table. I remade the subform and was then able to set the width manually with the cursor, in layout view, and hence save it. That worked for now! :)Cowherb
H
0

Use continuous forms instead. It gives you complete control over how your subform displays.

Hazlitt answered 5/2, 2019 at 22:20 Comment(0)
P
0

If you open your subform directly, your property sheet menu should display automatically if the default view is "Datasheet." Click on "All" and change the "Auto Resize" property to "No." This should solve the issue and avoid the need for VBA.

This only works when you open the subform separately. So if you want the changes to be reflected within your main form, you'll have to close it and switch back and forth.

Pewee answered 21/10, 2019 at 21:47 Comment(0)
O
0

Super annoying by default. It seems to work as one would expect of you set the view mode to layout view. Drag column widths as needed and save. Go back to form view and it works. It's really dumb it doesn't work the same way in form view our design view.

Octant answered 18/2, 2020 at 21:45 Comment(0)
R
-1

Either open the Main Form in Layout View or directly open your Subform in Datasheet View. Right Click on the Field Header, select Field Width, and enter the desired width. Save. Bewm.

Reviel answered 11/5, 2016 at 19:32 Comment(0)
S
-1

My solution (Access 2016) was to create the main & subform, recreate the subform on its own using form wizard and set it up the way I want it, rename the original subform to something else, and finally rename the recreated subform to the original form name. Open the main form and the subform should be laid out the way you want it. You can then delete the original subform you renamed.

Seif answered 4/7, 2018 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.