Results 1 to 11 of 11
  1. #1
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77

    Wishing to draw a box around a cluster of fields

    I have a form where a caseworker may enter information about a given case.
    In order for the form to look better to the eye and better support the underlying logic, I wish to draw some squares around the fields.
    Currently, my form looks somewhat like this:
    Click image for larger version. 

Name:	fromhere.png 
Views:	30 
Size:	24.2 KB 
ID:	39912

    I would like a square around a number of fields, like this (made in Paint):
    Click image for larger version. 

Name:	tohere.png 
Views:	30 
Size:	29.5 KB 
ID:	39913

    How to?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    One of the controls available on the ribbon should be a rectangle.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    grab the RECTANGLE off the toolbar and stretch it around your boxes.
    (next to checkbox)

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Also, once you have drawn your rectangle you will need to Right Click on the Rectangle and set the Position to be "Send Behind"

  5. #5
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    Thank you. I see that I need to be in design view for this to happen. I had been working in layout view.

  6. #6
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    Well, having tried it out I wonder if there is a more efficient and controlled way? I wish to make sure the rectangle clings tights to the textboxes already present. As it is, I have to draw the rectangle "by hand", leaving the design open for havd-made errors. Is there a way to instruct Access to draw the rectangle exactly around a given amount of boxes? Like, boxes highlighted should have a rectangle drawn around them?

    I a looking for something similar to the simple function in excel where it is possible to highlight a number of fields and then adjust the format to have lines drawn along the outer lines of the rectangle thus highlighted.

  7. #7
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Sort answer no, you only would need to do this once in design view though?
    Not repeatedly every time you used the form.

    It's pretty easy to use the left or right align right click menus to line things up.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    in vba - probably the form open event, something like

    me.rect.top=nameoftopleftcontrol.top-60 (your customer label)
    me.rect.left=nameoftopleftcontrol.left-60
    me.rect.width=nameofbottomrightcontrol.left+nameof bottomrightcontrol.width+60 (your email textbox)
    me.rect.height=nameofbottomrightcontrol.top+nameof bottomrightcontrol.height+60

    the 60 is to allow a 1mm boundary around the controls, adjust to suit

    this assumes that no controls have left values <the top left control and the left+width>than the bottom right control

  9. #9
    Join Date
    Apr 2017
    Posts
    1,673
    For every control in form, you can set the position of leftmost top corner of control (button, combobox. textbox, label, rectangle, line, etc.) and i'ts width and height as numeric values.
    You also can align selected controls to left, to right, to top, or to bottom.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    Put this code in a module, it will create your box for you

    Code:
    Function DrawBox()
    Dim ctl As Control
    Dim bLeft As Integer
    Dim bTop As Integer
    Dim bHeight As Integer
    Dim bWidth As Integer
    Const Margin = 60
    
    
        With Screen.ActiveForm
            bLeft = .Width
            bTop = .Section(acDetail).Height
            bHeight = 0
            bWidth = 0
            For Each ctl In .Controls
                
                If ctl.InSelection Then
                  
                    If ctl.Left < bLeft Then bLeft = ctl.Left
                    If ctl.Top < bTop Then bTop = ctl.Top
                    If ctl.Left + ctl.Width > bWidth Then bWidth = ctl.Left + ctl.Width
                    If ctl.Top + ctl.Height > bHeight Then bHeight = ctl.Top + ctl.Height
                    
                End If
                
            Next ctl
           
            Set ctl = Application.CreateControl(.Name, acRectangle, acDetail, , , bLeft - Margin, bTop - Margin, bWidth - bLeft + Margin * 2, bHeight - bTop + Margin * 2)
            with ctl
                'set any properties you want here
            end with
        End With
        
    End Function
    Then add an autokey macro to run it (perhaps ctrl+B? so macro is called ^B)

    in your form design view, highlight the controls you want a box round and hit ctrl-B

    Note the above has no error handling and assumes the controls are in the detail section - at least that is where the box control will be created, feel free to modify as you require. The name is autocreated in the same way when you create a a control

  11. #11
    Nanuaraq is offline Advanced Beginner
    Windows 7 32bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    77
    It seems I stumbled upon another solution: In layout view, I can change the format of grid lines in a single cell. I may also highlight a number of cells and change the format for all of them at the same time. This way, I can tell the form to draw a line where I want it. It is less user-friendly than Excel but otherwise works the same way. Problem solved.

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

Similar Threads

  1. Replies: 6
    Last Post: 03-16-2019, 08:53 AM
  2. Replies: 9
    Last Post: 06-15-2017, 03:00 PM
  3. How to draw a vertical line on a sub form
    By hassan.tajdar in forum Forms
    Replies: 4
    Last Post: 05-09-2017, 08:47 PM
  4. Replies: 39
    Last Post: 03-15-2017, 07:34 PM
  5. Can I draw Binary Tree in Forms or excel?
    By selvakumar.arc in forum Access
    Replies: 1
    Last Post: 05-30-2013, 11:04 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