Runtime error #7 - out of memory

I've developed a Visual Basic 6.0 program that displays some data (gathered from a Access database throw ODBC). This program works fine in my computer, under Windows 2000 but in eveery other computer with Windows 9x shows a runtime error #7 "Out of memory".
Please help!!
thanks a lot

p.s. even in my own computer with windows 98 and the very same software installed gets the #7 error.
Who is Participating?
bosleyConnect With a Mentor Commented:
Hi krahd, we have just gone through the exact same problem on our project.  I had a form with a grid and 2 tab controls.  The main tab control had 8 tabs and about 50-60 controls on it.  We found we had to break this form up. When this form was loaded our Win 95 systems took over a 25% resource hit (looking at the resource monitor).  what we did was to break up each of the tabs to a sub-form that is loaded on the click of a button from the main form (fMainForm).  So instead of 8 tabs we have 8 buttons. From the user's point of view they either have to click on the tab they want (old version) or a button (new version).  This reduced the resource hit from 25% to about 5%.  Your case may be a lot more of a savings because you have more controls than we did.

Just a suggestion.


Increase the virtual memnory size and make sure that you have installed the latest service pack i.e. SP5

Good Luck...
Ajay Chadha ... :-)
Do you create any large arrays, strings or collections in your program?  

Use error handling code to check what it is doing when it runs out of memory.  

Don't hold huge amounts of data in memory.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Are you getting back loads of data?
Your machine should basically have the same amount of memory as hard disk+RAM.
When running in Win2K, try using the performance monitor to make sure you haven't got a memory leak somewhere.
Check Process->Private Bytes->Your running app.
Usually when I get this error, it's because of an infinite loop or infinite recursion problem.  Does it happen at design time as well?  If so, bung in a couple of break points or click ctrl-break and see what's happening...
krahdAuthor Commented:
Thank you all for your comments.
What I have is a form named fMainForm with a lot of controls in it.
I have 400+ textboxes and 200+comboboxes, divided in 11 "pages" using frames and a TabStrip (by toggling the visible propertie of the frames).
I have also, 6 forms that access some other data using dataGrids.
The program checks the database and fills the controls fMainForm up.
Then the user is allowed to make some changes, but when he tries to save them he gets the #7 error.
The amount if data involved is not really big, just what is needed to fill the controls up.
Every procedure I used is far smaller than 64kb, but the "text size" of fMainForm is 437 kb (300 just due controls declarations).
I do not have infinite loops, and the biggest collection I have has less than 60 objects.
Anyway, what I cannot explain is: why do I get the error udner windows 9x & ME but it does NOT appear under Windows 2000?

Thanks a lot again.
You might be running out of system resources, with that many controls on a form.  I *think* in Win95 there's still a limit, it was just increased.

Are you using control arrays for the multiple text boxes and combo boxes?
krahdAuthor Commented:
Hi again.
I'm using control arrays for both text and combo boxes.
I use one array for each type of control for each page. Id est I have 22 arrays (11 per type).

I forgot to mention that there are a lot of labels too, one per control (describing the info contained) Arranged in one array per page, too.

Thanks again.

P.S. Could it be a bug in ADO software?
I'd be checking system resources, then.  Run sysinfo and have a look...
Theres a good knowledge base article about this: Q229756

I quote:
"Although you can have up to 254 control names in a form ... In some cases, you will experience out-of-memory error. ".

It also explains a few ways to get around it (i.e. UserControls, control arrays).
Best way is to try and cut down the size of your forms though.....
krahdAuthor Commented:
Hi again.
First af all I would like to give thanks to all who took the time to answer. Thans :)

Bosley: As far as I remember the subform (a la Access) feature isn't present in Visual Basic...
but if it is, could you please tell me how to do it? :)

(I've made a prototype where another form was loaded by frmMain (but not a subform) but it was rejected...)

Thanks again,


You create a forms (nothing special about the forms I just call them "sub forms") that contains the controls from your tabs. Next, you replace your tab control with, for example, buttons.  Each button corresponding to one tab on the tab control you removed. In the click event of the buttons on the main form you will open the corresponding form containing the controls previously on your tab:

private sub button1_click()
end sub

You can also use " vbModal" if you want the user to complete that form and close it (I assume this would trigger a save) before continuing with other processing on your main form.

I would suggest that each "sub form" corresponds to one table of data to make the inserts and updates, etc a lot more straight forward.

Hope this helps.

Using that many controls is sure to cause your problem. I suggest using a static number of text boxes, and having them visible no matter what tab is chosen... then change the appearance of them to reflect the chosen tab.
Force-accepted by
CS Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.