473,883 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to dynamically resize a continuous Dialog form to fit / show all records

TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I have recently had a issue where I open a continuous dialog form, showing anywhere from 1 to X records, X usually being in the 2-5 range. I found it very annoying that Access2010 per default made the continues form take up the entire height of the screen, even when there is only a few records.

So to fix that issue I came up with a bit of code to make the window size roughly match the amount of records, with the ability to specify a max amount of records to show. If the amount of records exceed the max, I also use the code to modify the scrollbar settings, so that only if there are more then Max records the scrollbar is shown.

The code is shown below, I placed it in the Load event of the form:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.    'Variables
  3.       Dim lngCount As Long
  4.       Dim lngWindowHeight As Long
  5.       Dim lngOldWindowHeight As Long
  6.       Dim lngDeltaTop As Long
  7.       Dim lngMaxRecordsToShow As Long
  8.  
  9.       lngMaxRecordsToShow = 10
  10.  
  11.    'Find the amount of records in form
  12.       Dim rs As DAO.Recordset
  13.       Set rs = Me.RecordsetClone
  14.       If Not rs.EOF Then rs.MoveLast
  15.       lngCount = rs.RecordCount
  16.  
  17.    'Check whether there are more then Max amount of records
  18.       If lngCount > lngMaxRecordsToShow Then
  19.          lngCount = lngMaxRecordsToShow
  20.          'Enable vertical scrollbar
  21.             Me.ScrollBars = 2 'Vertical
  22.       Else
  23.          'Disable scrollbars
  24.          Me.ScrollBars = 0 'None
  25.       End If
  26.  
  27.    'Calculate new windowheight.
  28.    'If you do not have a header/footer, or they are not visible adjust accordingly
  29.       lngWindowHeight = Me.FormHeader.Height + _
  30.                   Me.Detail.Height * lngCount + _
  31.                   Me.FormFooter.Height + _
  32.                   400
  33.                   'The 567 is to account for title bar Height.
  34.                   'If you use thin border, adjust accordingly
  35.  
  36.    'The form will be "shortened" and we need to adjust the top property as well to keep it properly centered
  37.       lngOldWindowHeight = Me.WindowHeight
  38.       lngDeltaTop = (lngOldWindowHeight - lngWindowHeight) / 2
  39.  
  40.    'Use the move function to move the form
  41.  
  42.       Me.Move Me.WindowLeft, Me.WindowTop + lngDeltaTop, , lngWindowHeight
  43.  
  44.    'Cleanup
  45.       Set rs = Nothing
  46. End Sub
I use:
AutoRezise= True
AutoCenter=True
with this code. Odd results may occur if you do not, but you can go test that yourself.
Oct 5 '12 #1
15 51337
twinnyfo
3,653 Recognized Expert Moderator Specialist
Smiley,

Quite an interesting solution. Have you found any bugs or quirks with this code, as of yet? My experience with resizing forms has been trial and error, and sometimes the forms will just be the wrong size, even though I set the size. Very creative solution, though!
Oct 5 '12 #2
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Not as of yet, as I just wrote the code for the first time today. I looked around online, but couldn't find any similar solution, so figured I should share my approach.

Problems I imagine might occur, is if you leave the MaxNrOfRecords very high, and thus the total height of the window overflows some maxHeight on the window.
Oct 5 '12 #3
NeoPa
32,584 Recognized Expert Moderator MVP
I did something similar a while back and it took me ages to realise that to resize a form you had to move it. Not very intuitive, but I got there eventually. I was convinced for ages that resizing simply didn't work.
Oct 22 '12 #4
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I had to laugh a bit at that (not you) cause I have been there myself. Thankfully Google and Bytes were there to help me :)
Oct 22 '12 #5
Hoopla3000
7 New Member
Cool idea Smiley. I've used this twice now with great success. In setting the window height, I added to the lngWindowHeight calc:

... + IIf(Me.Navigati onButtons = True, 250, 0) + ...

in case the form has the navigation buttons enabled.
Apr 10 '13 #6
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Nice touch Hoopla, thank you very much for reporting it back. I shall try to have a look at it soon, and then update the original post.
Apr 14 '13 #7
NeoPa
32,584 Recognized Expert Moderator MVP
Hoopla3000:
In setting the window height, I added to the lngWindowHeight calc:
Where's that "Like" button when you need it? Good idea :-)
Apr 14 '13 #8
Hoopla3000
7 New Member
I just noticed today that this doesn't work in Access 2013 as well as it does in 2010. It may be that the window height is returned differently in 2013 with the flat metro styling. Does anyone know a quick fix?

The attached image shows how the sizing differs between two versions of Access but the same application.

I just realized and should note that the Access 2013 image was taken from Windows Server 2012, which may be an additional factor.

Attached Images
File Type: png Access_2010_vs_2013_sizing.png (27.9 KB, 7499 views)
Jun 5 '14 #9
Seth Schrock
2,965 Recognized Expert Specialist
This is a great help. I'm always fighting with the height of my continuous forms. Everytime I go into design view and back to form view, I have to fix the height of the window. Thanks Smiley.
Jun 7 '14 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4756
by: Dalan | last post by:
I designed a dialog box with a combo to select individual vendors from a form and its related data for print ouput. Though the dialog box seems to work okay, I apparently do not have the filtering code behind the OnOpen Event Procedure of the report structured correctly. Anyone's assistance will be appreciated, although I would like to stay on the same track. Here is what I have done: 1. Created a new vendor query (qryVendorRpt) with...
2
15197
by: Noah Coad [C# MCP] | last post by:
I'm creating a program the must show the time (a clock) in a user control and the text must fill the user control. How do I make text dynamically resize to fill a label/panel/usercontrol? Thanks!! -Noah Coad Microsoft MVP & MCP (.NET/C#)
1
2441
by: andrew | last post by:
Hi there, I'm having a problem with a modeless form in my app. I have a main form in my app and a socket that waits on data from a server (I use BeginReceive/EndReceive for that) and when I receive certain data from the server I want to create a new modeless form to show some of that data. But after receiving the data from the socket the modeless dialog does not appear (it seems to be receiving no windows message to update itself,...
3
2991
by: Guadala Harry | last post by:
Here's the functionality I'm after: I need for a page to display a photo. When users click on other links within the page, the photo changes. I'd like to swap out the photo without doing a Postback of the entire page. I initially implemented this with an aspx page that contains an IFame which displays only the picture (gif). The behavior was what I wanted, but the problem is that the IFrame does not resize with the photo......
7
4640
by: Peter | last post by:
I have a primary form named frmMain. During some extended data pulls I launch another Dialog Form named frmUpdating. How do I keep the frmUpdating centered on the frmMain if a user moves the frmMain form? -Peter
14
3783
by: Simon Abolnar | last post by:
I would like to know how to open child form from dialog form. Thanks for help! Simon
1
2846
by: Teelions | last post by:
I know that this can be done for iframes but am wondering if it can be also done for layers. I have 2 pages: an asp content page that has a html (toc.html) include placed within it. The content of toc.html is a menu list placed inside a layer called "navcontainer". The content of the asp page is inside a layer named "wrapper". And the include file, toc.html, is inside a layer named "toc" inside "wrapper". So within the asp page,...
1
6103
by: JDeats | last post by:
I have a simple WinForm with a WinForms splitter down the middle. I would like to make it so when the user clicks on a button inside the left portion of the screen (the panel to the splitters left) that portion of the form is reduced in size by about 90% (I want to shrink this area of the of the form). The splitter doesn't appear to have any methods for programmatic resizing, I tried changing it's width settings and the splitter moved...
0
1748
by: ashishyadav2007 | last post by:
In Setup project for .net I have added a dialog(form) between Start and End dialog(form), but i need to show that dialog(form) only if a registry search condition is successful. If registry search condition fails I dont want to show that dialog(form) during installation process. How can I do that -- i mean how can i apply launch condition to a dialog(form) in the setup project?
1
3851
by: rythmic | last post by:
Hi! I have developed a system where I use Dojos dijit dialog to show certain information. It works perfectly for all major browsers except for firefox ( where I've tested v3.6 and 4 BETA) The first time I try to get a dijit dialog it all works as expected and all is well and I close it. The second time I try to open another dialog I get an error message and nothing happens. If I open the first dialog it is still working. The error...
0
9934
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10840
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7120
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5795
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4608
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4214
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.