473,441 Members | 3,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

How to prevent subform closure on main form window resize

TheSmileyCoder
2,322 Expert Mod 2GB
I have noticed that when I resize the window of my main form, that any subforms that "fall" out of the visible area get closed.

Now Access automatically reopens them if I expand the window again, but I would still prefer to keep them "active" and in memory.

Do anyone know a way in which to prevent access from closing them?

And on the same note, if there is a way to detect this kind of closure, compared to closure that happens when the main form closes.
Apr 5 '11 #1
14 2660
hype261
207 100+
Smiley,

I have never seen this behavior myself, but I have run into tons of problems with user resizing the screen. Here are a few of the solutions I have come up with.

1). I wish Access would allow you to set the min/max height and width of a Form, much like C# does, you can mimic this though by hooking into the Forms Resize event and preventing them from reducing the size beyond a certain point. This has a side effect that the screen flashes and doesn't look all that great, but is doable.

2). My prefered method is to dynamically resize the subforms/list boxes at run time to fit the size of the form. This works well if your subforms are in a good location. Again you hook into the Forms Resize event. I have even taken it so far as if they resize to a point that the subform won't appear I set the subform to be invisible. I believe this could work in your situation, set the subform to invisible and move it to the top left.
Apr 5 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Hi Hype, and thank you for your reply.

Yes, I do agree with 1. However, Im curious as to how you prevent the users from decreasing beyond a certain point, could you elaborate on your method?
Apr 5 '11 #3
hype261
207 100+
All it takes is 2 lines of code. I am at home right now so I don't have any of my Access code so it might have misspelling, but it should give you an idea of what to do.

Expand|Select|Wrap|Line Numbers
  1.  
  2. const minHeight as Integer = 10000 'Or whatever your min height is for your form
  3.  
  4. if(me.windowHeight < minHeight) Then
  5. Docmd.MoveSize ,,,minHeight
  6. End if
  7.  
Me.WindowHeight is a read only property so you cannot change modify that directly which is why you have to use the MoveSize command. You are going to want to place this in your Form ReSize Event.
Apr 5 '11 #4
Rabbit
12,516 Expert Mod 8TB
Shouldn't the close or unload event of the form trigger even if it's being used in a subform?
Apr 5 '11 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Ah yes, using the Docmd.MoveSize. I had tried using the WindowHeight, but as you say, I found it to be read only.

@ Rabbit:
The close event of the subform does trigger, however it my problem comes from not wanting the subform to close. There are times where I would like to reference the subform, even if it is not part of the visible area (And thus access has closed it).
Apr 5 '11 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Well I tried your suggestion, using the DoCmd.MoveSize, and while it prevents the user from KEEPING the form too small, it still allows him momentarily to resize the form to just the blue windows bar, which causes the subform to close. DAM!
Apr 5 '11 #7
Rabbit
12,516 Expert Mod 8TB
If it closes, then the unload event should trigger first correct? You cancel the unload event and that will prevent the form from closing.
Apr 5 '11 #8
Rabbit
12,516 Expert Mod 8TB
Of course, you would then need a way close that subform. Perhaps a close button on the main form paired with a global variable will do the trick.
Apr 5 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
You cannot cancel the unloading of a subform. While the event does fire, setting the Cancel=true seems to have no effect at all.
Apr 5 '11 #10
Rabbit
12,516 Expert Mod 8TB
What about a DoCmd.Maximize that reruns if click restore?
Apr 5 '11 #11
Rabbit
12,516 Expert Mod 8TB
Also, a form can be opened as a dialog, this prevents the user from resizing the form.
Apr 6 '11 #12
TheSmileyCoder
2,322 Expert Mod 2GB
Hi rabbit and thank you for all your replies, and tips.

The whole problem started when I wanted to write some code to allow dynamic form resizing (resizing the window makes the form resize as well as the controls). So placing it in a dialog would defeat the purpose.

On even further examinitation, I've found that the subform closing happens when the detail area of the main form is no longer visible (I.e the height of the main forms window gets so small to only allow space for the header and footer.

I remember having had this issue before, in a search form, where I put all the search fields in the forms header, then search results would be displayed in the detail area. I added an button with a Docmd.MoveSize which basicly shrunk the form, to only show the header area, in which there was also buttons to navigate the search results, in the main form. One of the issues I had there was that the subform displaying the search results would also unload.
Apr 6 '11 #13
Rabbit
12,516 Expert Mod 8TB
Well, the only thing I can think of now is to create a 1 pixel wide copy of the subform and put it in the top left corner of the header. I don't know the repercussions of that though.
Apr 6 '11 #14
TheSmileyCoder
2,322 Expert Mod 2GB
I could try playing with moving it to the header, however im not sure If I can catch the correct time to move it to the header.

One of the issues is that the form looses its "state" so to speak. Through other controls, I manipulate the Recordsource of the form, and when its closed (by the resize) and opened again (by the resize) it can no longer remember its recordsource. Alternativily, I will just have to try and deal with this problem instead.
Apr 11 '11 #15

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

Similar topics

0
by: Ellen Manning | last post by:
I've got an A2K form with a subform based on a query. This query has a checkbox and an amount field and returns records if checkbox is checked. I Dsum the amount field and display on the main...
0
by: Colin | last post by:
In access 2000 I need to filter records in a Subform by pushing a button on a command button located on the Main form. The Main form is blank. Its only purpose is to contain the subform which is...
1
by: New2Access | last post by:
Hi, I have a form thats used to enter records into a table. The table and form have fields for Name, week, project, and hours. To assist users, I wish to add a subform that will show them how...
18
by: Darryl Kerkeslager | last post by:
I don't do much with subforms - in fact I've deliberately avoided them - but .... I have a tab control that will contain several subforms, each bound to a separate table, and each table/subform...
2
by: Deano | last post by:
Thanks for the replies to my previous post. So while I'm on a roll here's another plea for help. I simply need the code for a button on the main form that will create a new record in the...
1
by: NBruch | last post by:
Ok let me explain what im trying to do: i need a combo box which needs to be linked to a listbox (or combo box doesnt matter which really) then the listbox should bring up the record in a...
1
by: luv4nrt | last post by:
Hello all, I have a membership dB in which I have a form that updates data in 4 tables. One of the tables is bounded to a subform within the Main membership form. I am trying to link all four...
3
by: virtualgreek | last post by:
Dear all, I have a scenario that is driving me nuts. (MS Access 2003) I have a form/subform (Continuous form) where it gets its data from tables Order and Order_Details. In the footer...
1
by: Elainie | last post by:
I have a main form and in it I have a datasheet subform filtered on surname, I would like the users to select a name in their list on the subform then the data moves up into the main form... Is...
4
by: Savita23 | last post by:
Hi, I have a subform in datasheet layout embedded in the main form.I want to invoke a procedure on the double click of each record in the subform.Is there a away by which I can fire the double...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.