Solved

Unload form/Close all recordsets

Posted on 2001-07-09
14
417 Views
Last Modified: 2008-03-03
I have a password logon(A).
If password successful,mainform(B) will appeared.

>>Then I need to unload A.

There will be another query form(C) for user to enter the product name.
If it successful,Add form(D) will appeared.

>>Then I need to unload C.

In form D,there are 7 textboxes,1 listbox,6 combox boxes,2 option buttons,3 buttons,1 datetimepicker control, 1 maskeditedbox control, 2 datacombo.
User need to input data...error checking will be performed.If it is successful,mainform will be enabled true and form D will be unload.

>>I'm using enabled properties to active the active form.
>>How to unload a form fast?

Method 1(OTHER FORM):
Unload Me
'Exit from the whole system
End

Method 2(MAINFORM-(B)):
Private Sub exit_1_Click(Index As Integer)
Dim intCount As Integer

While Forms.Count > 1
'find first form besides "me" to unload
intCount = 0
While Forms(intCount).Caption = Me.Caption
intCount = intCount + 1
Wend

Unload Forms(intCount)
Wend
'last thing to do
Unload Me

End Sub

>>Problem
HOW COME IT TAKE ALMOST 10 to 15 seconds to unload form D?

Can anyone tell me the correct steps in manipulating one form after another?

Regarding recordset,is there any function to check and close all the opened recordset when form unload?
0
Comment
Question by:Celia
14 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi,

In form_unload()

add

Set formName = Nothing


To check whether a recordset is opened:

If rsAdo.State = 1 Then rsAdo.Close: Set rsAdo = Nothing

'Hope will help.
0
 
LVL 1

Author Comment

by:Celia
Comment Utility
hI RYANCYS,

i DID INCLUDE "SET FORMNAME = NOTHING" IN THE FORM_UNLOAD STATEMENT.iT STILL TAKE 15 MINS TO UNLOAD MY FORM(D).

PLS TAKE NOTE:My mainform(B) will also be in the foreground unless the user exits from the program.

Pls help me!
0
 
LVL 1

Expert Comment

by:vim_asteya
Comment Utility
Somewhat similar to rancys.......

U could add this line before the line which opens a recordset.
If recordset1.state<>0 then recordset1.close
r1.open..........

This will close all open recordsets and connections

Hope this helps
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi Celia,

Here are few questions:

1. Did you bound any controls with database in your mainform(B)?

2. What controls you use in mainform(B)?

3. MDI forms?

4. Do any process when Form_Unload()?

Thanks.
0
 

Expert Comment

by:RLTimblin
Comment Utility
You must close all recordsets and disconnect from the datasource before closing a form or exiting a program.
0
 
LVL 1

Author Comment

by:Celia
Comment Utility
1. Did you bound any controls with database in your mainform(B)?
>>I use API stuff for putting bitmaps in menus.

2. What controls you use in mainform(B)?
>>I'm using menu editor to create my 37 menu items.

3. MDI forms?
>>Single forms
4. Do any process when Form_Unload()?
>>nope.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi Celia,

How is your developing platform? Is it the pc is out of resources when you execute this program? because sometimes the application itself affected by overall pc performance.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:Celia
Comment Utility
PIII-600HMZ,64MB MEMORY,VB6,MS ACCESS 2000,Network Access.Nope.

What should I do now?
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi Celia,

so do you do any massive calculation or process in your program?

Try to add the DoEvents in your Form_Unload()

What code do you write in Form_Unload() for Form D?

So the mainform(B) unload prefectly? Thanks.
0
 
LVL 1

Author Comment

by:Celia
Comment Utility
Pls explain what do you meant by "DoEvents" in form_unload()
What code do you write in Form_Unload() for Form D?
>>unload me.

yap,mainform(B) unload prefectly.

+++My last resort.
When the form D is loading/unloading,is it possible to display a bar telling user that data is processing...pls wait....once form D has finished its tasks?What do you think?Need help in this.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi Celia,

Finally, please post your code! Make it easier to help you.
0
 
LVL 1

Author Comment

by:Celia
Comment Utility
There's too many lines of code.How to go about doing it?

Basically this form D has many controls as I mention before and it's using global variables/functions....This is a poor design for a beginner like me.....learning

When the form D is loading/unloading,is it possible to display a bar telling user that data is processing...pls
wait....once form D has finished its tasks?What do you think?Need help in this.

>>Do u have any example on that?I will increase points if there's a need.

Thanks!


0
 
LVL 8

Accepted Solution

by:
glass_cookie earned 150 total points
Comment Utility
Hi!


There are 2 alternatives.  1 - Let there be a delay before displaying messages. 2 - Display the bar immediately upon unloading/processing.

Alternative 1
This is the code for FormD:

Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 2000 'If process takes longer than 2000 msec, it will be executed.  You can change it to 1 if you want.
'All your processing codes...
'All your processing codes...
'All your processing codes...
'All your processing codes...

Timer1.Enabled = False
Unload FormBar
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Timer1.Enabled = True
Timer1.Interval = 2000 'If process takes longer than 2000 msec, it will be executed.  You can change it to 1 if you want.
End Sub

Private Sub Timer1_Timer()
FormBar.Show
Timer1.Enabled = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
'All your processing codes...
'All your processing codes...
'All your processing codes...
'All your processing codes...

Unload FormBar
Unload Me
End Sub



This is alternative 2:
Code for FormD: (Show the bar upon loading/unloading)

Private Sub Form_Load()
FormBar.Show
'All your processing codes...
'All your processing codes...
'All your processing codes...
'All your processing codes...

Unload FormBar
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
FormBar.Show
End Sub

Private Sub Form_Unload(Cancel As Integer)
Unload FormBar
Unload Me
End Sub

As for your 'bar', create a form called FormBar.
You could design it in any way you want.  You may want to make it a small form with a label in it with the caption : "Please wait while the program is processing it's tasks..."

That's it!

glass cookie : )

PS. Let me know if I did answer your question or not : )
0
 
LVL 3

Expert Comment

by:modder
Comment Utility
Celia

Please finalise this question, even if nobody gave you a satisfactory answer - in that case just let me know and I will be happy to refund your points to you.

If someone did give you a satisfactory answer, please accept the comment as the answer. If you are having problems doing that let me know.

Please do *not* ignore this request. To the other participants in the thread - if no response is forthcoming alert me and I will take action.

Regards

modder
Community Support Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now