Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21

    How to autosize fields

    I am working on a glossary of terms and am trying to create a report that will contain a list looking something like this:
    Code:
    term, subject
        This is a long description for the term
        See also: term1, term2
    I know how to set the font format to italics, but am having difficulty with line 1 because the fields are of fixed length. I want the length to be automatically determined according to the length of the actual content of the database field so that there is no gap between the text and comma and the subject field. I would also like to add a comma or possibly brackets around the subject text e.g.:


    Code:
    term (subject)
        This is a long description for the term
        See also: term1, term2
    but can't find how to do this. Its been a while now since I used MS Access for anything an it has changed significantly. I did find properties called Can Grow and Can Shrink and both are set to yes, but both fields still appear of fixed length.

    In the meantime I am working on trying to figure out how to make the 'See also' line appear only when the field in question is not empty. If anyone can help me with the above it would be appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    autofit col. width:

    txtBox.ColumnWidth = -2

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    In the meantime I am working on trying to figure out how to make the 'See also' line appear only when the field in question is not empty. If anyone can help me with the above it would be appreciated.
    You could try code in the On Format event of the relevant section to set the visible property of your textbox, dependent on the value of another control.

    Alternatively, you use Conditional Formatting of a textbox to set the font colour to white but of course this won't work if printed on coloured paper
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21
    Quote Originally Posted by Bob Fitz View Post
    You could try code in the On Format event of the relevant section to set the visible property of your textbox, dependent on the value of another control.

    Alternatively, you use Conditional Formatting of a textbox to set the font colour to white but of course this won't work if printed on coloured paper
    Bob, thanks for that. I did try the following in code (the Sub being generated automatically after selecting 'Build Event' in the Details header in Design view):

    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
        If Me.Alt.Value = "" Then
            Me.Also.Visible = False
            Me.Lab_Also.Visible = False
        Else
            Me.Also.Visible = True
            Me.Lab_Also.Visible = True
        End If
    End Sub
    Unfortunately it is getting totally ignored and both label and field still appear in all listed records. Still trying to figure it out. The project lives on a OnerDrive share so not sure whether its a code execution permissions (trust) issue perhaps?

  5. #5
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21
    Quote Originally Posted by ranman256 View Post
    autofit col. width:

    txtBox.ColumnWidth = -2
    Thanks. Will give that a try.

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps you need to test for a null value rather than a zero length string. Perhaps:
    If Nz(Me.Alt,0)=0 Then Or perhaps even If Len(Me.Alt)=0 Then

    The project lives on a OnerDrive share so not sure whether its a code execution permissions (trust) issue perhaps?
    I'm not sure what you mean by this exactly but I don't you should have multiple users using a db on OneDrive (if that's what you are doing). I believe I've read that it is a recipe for corruption.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  8. #8
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21
    Quote Originally Posted by ranman256 View Post
    autofit col. width:

    txtBox.ColumnWidth = -2
    I am wondering whether that applies to Excel? Apparently a value of -2 for field width is invalid in Access.

  9. #9
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21
    Quote Originally Posted by Bob Fitz View Post
    Perhaps you need to test for a null value rather than a zero length string. Perhaps:
    If Nz(Me.Alt,0)=0 Then Or perhaps even If Len(Me.Alt)=0 Then

    I'm not sure what you mean by this exactly but I don't you should have multiple users using a db on OneDrive (if that's what you are doing). I believe I've read that it is a recipe for corruption.
    No, its not intended for multiple users. Our organisation seems to have most of its data on OneDrive and my user 'Documents' folder is also on a OneDrive share. I don't know whether that has any bearing on the problem, but I do recall something about wherever you run the DB from needs to be a trusted location? Could be mixing it up with something else or ancient versions, but just thought to mention is as a possible factor.

  10. #10
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21
    OK, here's a simple example:

    Table fields:

    1. auto-index
    2. Term
    3. Subject
    4. Description

    Sample data:

    NAS, Networks, A network attached storage device
    RAN, Telecoms, Radio Access Network
    VM, Software, Virtual Machine

    I am looking to get something like:

    Code:
    NAS (Networks)
        A network attached storage device
    
    RAN (Telecoms)
        Radio Access Network
    VM (Software)
        Virtual Machine
    The descriptions will actually have much more detail, but this is the general idea.

  11. #11
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Kasperczak View Post
    I am wondering whether that applies to Excel? Apparently a value of -2 for field width is invalid in Access.
    I seem to remember using it it the past but that was on textbox on a form shown in DataSheet view.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think you're overcomplicating things. Have just one textbox on line one and set its Control Source property to =[Term] & " (" & [Subject] & ")"

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the -2 refers to columnwidth for datasheets

    Table fields:

    1. auto-index
    2. Term
    3. Subject
    4. Description

    Sample data:

    NAS, Networks, A network attached storage device
    so what applies to what?
    Term=NAS
    Subject=Networks
    Description=A network attached storage device

    so are you displaying as 3 fields in controls set out just so, or do you want to build these three fields into 1 field which says

    Code:
    NAS, (Networks)
        A network attached storage device
    The other thing we need to know is if this is being displayed on a single form, a continuous form or a datasheet and if it is 3 fields which field it is you want to widen/adjust. The Term field so the subject is closer? or the description field to ensure it displays all the data? or what?

  14. #14
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I want the length to be automatically determined according to the length of the actual content of the database field so that there is no gap between the text and comma and the subject field. I would also like to add a comma or possibly brackets around the subject text e.g.:


    I think replacing the two textboxes for Term and Subject with one using a concatenation of the two fields and the brackets would be what the OP wants.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  15. #15
    Kasperczak is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    21
    I did a little experimenting with above function like so:

    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
        Debug.Print (Me.Alt.Value)
        If Me.Alt.Value = "" Then
            Debug.Print ("Blank")
            Me.Also.Visible = False
            Me.Lab_Also.Visible = False
        Else
            Debug.Print ("NOT BLank")        
            Me.Also.Visible = True
            Me.Lab_Also.Visible = True
        End If
    End Sub
    It debug.print'ed the value of Me.Alt.Value, but what then happened is a bit weird. It printed 'Null' for some values and the actual value for others as expected but always printed "NOT Blank" for every iteration.

    I changed:

    If Me.Alt.Value = ""

    To:

    If Me.Alt.Value = Null

    but got the same thing. What gives?
    If the value is Null then should it not have printed 'Blank' for the empty Null values?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 10-27-2022, 07:32 PM
  2. Replies: 3
    Last Post: 12-02-2017, 02:04 PM
  3. Replies: 3
    Last Post: 04-24-2016, 07:24 AM
  4. Autosize a column's width and height?
    By Isla in forum Reports
    Replies: 1
    Last Post: 04-05-2016, 01:58 PM
  5. Replies: 12
    Last Post: 05-07-2012, 12:41 PM

Tags for this Thread

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