Results 1 to 14 of 14
  1. #1
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7

    Autowidth for columns in subForm

    I have developed an Access app, which has different navigational tabs which open up different forms. e.g. Tab A has Form A inside it and Form A has SubForm A1 inside it. For some reason, the following code is not working on any of the fields
    Me.YourFieldName.ColumnWidth = -2



    Can anyone please suggest me some workaround so that all the fields in the subforms will have auto width adjustable to fit in the text.
    Thank you!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is this a Navigation Form? I don't like and don't use Navigation Form. However, if that code is in the subform module and subform is Datasheet view, seems it should still work even if the subform is on a Navigation Form. But since I won't use NF I am not so familiar with their nuances.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Columns cant have negative value.
    You could try fld.columnwidth = 20 and do it for each field upon tab_click.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Ranman, using a negative value should cause the control to resize to least width that will still allow full display of data. Review http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7
    Yes..This subform A1 is inside a Form A in Tab A and setting the column width to -2 does set it to minimum width possible. Not sure why this is not working.

  6. #6
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7
    I want to use the new code in OnClick event of the Navigation tab..so that everytime, the user clicks on the tab name, all the columns in the corresponding subforms will have proper width

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Asking again - is this a Navigation Form?

    Or is this a normal form with a Tab control? I just tested click event of page of Tab control and it does nothing. No idea why Tab control even has events, none seem to work.

    Is the code behind the subform or main form?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7
    Quote Originally Posted by June7 View Post
    Asking again - is this a Navigation Form?

    Or is this a normal form with a Tab control? I just tested click event of page of Tab control and it does nothing. No idea why Tab control even has events, none seem to work.

    Is the code behind the subform or main form?

    Sorry.. its a Navigation form

    to clarify more:


    Got one Navigation Form NavFormA


    NavFormA has different NavigationButtons. Button1 has FormB as its 'Navigation target name' i.e. it loads FormB when Button1 is clicked upon.


    FormB has a subform subfrmC in it and subfrmC has datasheet in it.


    I want to the columns of subfrmC to automatically adjust their widths whenever button1 is clicked.


    NavFormA -> Button1 -> FormB -> subfrmC

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7
    Quote Originally Posted by June7 View Post
    So for me..it becomes:

    Forms!NavFormA.Form!FormB.Form!subfrmC.Forms.txtCl ient.ColumnWidth = -2???

    Its not working

    I also tried:
    Forms!NavFormA.Form!Form_FormB.Form!subfrmC.Forms.txtClient.ColumnWidth = -2
    where Form_FormB is the name of the class object for FormB


  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So the code is behind the main form?

    If you want to provide db for analysis, follow instructions at bottom of my post.

    Perhaps code in the subform Load event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7
    Here is my current code behind the subfrm

    Private Sub Form_Current()


    Dim ctrl As Control
    For Each ctrl In Me.Controls
    If ctrl.ControlType = acTextBox Then ctrl.ColumnWidth = -2
    Next


    End Sub


    Private Sub Form_Load()


    Me.txtClient.ColumnWidth = -2
    Me.txtSDP.ColumnWidth = -2
    Me.txtCategory.ColumnWidth = -2
    Me.txtEmployee.ColumnWidth = -2
    Me.txtTitle.ColumnWidth = -2
    Me.txtManager.ColumnWidth = -2
    Me.txtRollup.ColumnWidth = -2
    Me.txtAllocation.ColumnWidth = -2
    Me.txtOffice.ColumnWidth = -2


    End Sub

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Current event should do the trick as well as Load, I would think, at least it does with a normal form.

    However, as noted, I am not that familiar with Navigation Form and would have to work with to analyse issue. I don't have any db using Navigation Form and do not want to build.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    rockstar283 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    7
    Quote Originally Posted by June7 View Post
    Current event should do the trick as well as Load, I would think, at least it does with a normal form.

    However, as noted, I am not that familiar with Navigation Form and would have to work with to analyse issue. I don't have any db using Navigation Form and do not want to build.
    Thanks for all the help man..I really appreciate it..I will keep digging more..anyone else has any thoughts on this issue?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 18
    Last Post: 02-14-2014, 05:06 PM
  2. Subform with dynamic number of columns
    By modbass in forum Programming
    Replies: 1
    Last Post: 12-15-2011, 03:39 AM
  3. Replies: 1
    Last Post: 11-29-2011, 07:43 AM
  4. Replies: 8
    Last Post: 09-05-2011, 11:16 PM
  5. Visible property in subform columns
    By MDB in forum Forms
    Replies: 3
    Last Post: 09-03-2011, 06:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums