Results 1 to 9 of 9
  1. #1
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239

    Move form controls according to subform resize

    Hi,

    I have a continous subform with code that automatically resizes subform according to number of records in It. Under subform I have many controls that need to be moved too, based on subform size.

    When subform's size is bigger, control must move down exactly same - or move up If subform isn't at It's minimum "design view" size.

    I don't know how to start coding, since code for auto-resizing subform is called from module in Form_Load and subform control After_Update event !


    Please take a look at this attached sample (really just a sample), you'll better understand. Open form TblName, there you will see comboboxes for entering surnames. Select another item from combobox and another combobox will show - that's subform and It's resizing. Under subform there are two fields - "Street" and "City". These 2 texboxes should move simultaneously with subform size (up or down).


    Any help much appreciated !!
    Attached Files Attached Files

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    you need to change the top property of the controls below the subform. Something like

    mycontrol.top=mysubform.top+mysubform.height+60

    alternatively if within your subform resizing code you know how much it is resized by then

    mycontrol.top=mycontrol.top+resizedamount

  3. #3
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    mycontrol.top=mysubform.top+mysubform.height+60
    I tried this but can't get It to work, nothing happens:

    Code:
    Forms![TblName]![Street].Top = Forms![TblName]![TblJoin].Form.Top + Forms![TblName]![TblJoin].Form.Height + 60
    mycontrol.top=mycontrol.top+resizedamount
    This works, but I can't fix issues with It. Desired output is that control under subform would always be with same space as all other controls (like first two fields in sample - "ID" and "Name"). Look at this attached sample, and start selecting items from combobox, you'll see what happens and you'll figure out what I want. I have set position of control under subform in way that you can see all problems.


    Thanks for response Ajax !
    Attached Files Attached Files

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    with respect - it is for you to figure out. I'm happy to provide suggestions but do not have the time to work out solutions. My job is to develop database solutions and 'vba magic' which I get paid for - I provide help on a volunteer basis

  5. #5
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    No problem, I understand, this is a forum and everyone is here on volunteer basis, no hard feelings. Maybe somebody else will provide me an answer or give some idea how to solve this issue

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    I've provided the correct solution - you just haven't followed it

    I said

    mycontrol.top=mysubform.top+mysubform.height+60

    you've used

    Forms![TblName]![Street].Top = Forms![TblName]![TblJoin].Form.Top + Forms![TblName]![TblJoin].Form.Height + 60

    So assuming this code is in your form (I would expect it to be), you don't need 'Forms![TblName]!'

    and for some reason you are trying to access the subform form details, not the subform control.

    So assuming your subform control is called 'tblJoin' then replace Forms![TblName]![TblJoin].Form. with tblJoin

  7. #7
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    hi again,

    code is not in form, but It's called from separate module. I need code to execute on load event, and when form is allready opened but new records is added in subform (so code is called form Load_event and after_update event). That's why I did It like this. You can check sample to see what Is calling from where.

  8. #8
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    so incorporate the code into the code you are using for changing the size of the subform control since this is triggered by the vents you want - also investigate the use of screen.activeform as a means of identifying the form and controls

  9. #9
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Got It

    Code:
    Forms![TblName]![Street].Top = Forms![TblName]![TblJoin].Top + Forms![TblName]![TblJoin].Form.InsideHeight + 100
    It was InsideHeight that caused me headaches. In my code for autoresizing subform is changed insideheight and not .Height, so that needed to be included in code for moving controls too !

    Now everything works nicely. I'm closing this thread.

    thanks for help Ajax !

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

Similar Threads

  1. Replies: 4
    Last Post: 08-26-2015, 08:47 AM
  2. Replies: 3
    Last Post: 12-03-2014, 01:40 PM
  3. Resize InsideHeight of Subform from Main Form
    By Bjg1986 in forum Programming
    Replies: 1
    Last Post: 04-12-2013, 03:26 PM
  4. Move Focus From Subform To Main Form
    By burrina in forum Forms
    Replies: 2
    Last Post: 11-18-2012, 03:09 AM
  5. Controlling subform resize
    By Deutz in forum Forms
    Replies: 2
    Last Post: 10-13-2011, 07:35 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