• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

Unload form/Close all recordsets

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
Celia
Asked:
Celia
1 Solution
 
Ryan ChongCommented:
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
 
CeliaAuthor Commented:
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
 
vim_asteyaCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Ryan ChongCommented:
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
 
RLTimblinCommented:
You must close all recordsets and disconnect from the datasource before closing a form or exiting a program.
0
 
CeliaAuthor Commented:
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
 
Ryan ChongCommented:
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
 
CeliaAuthor Commented:
PIII-600HMZ,64MB MEMORY,VB6,MS ACCESS 2000,Network Access.Nope.

What should I do now?
0
 
Ryan ChongCommented:
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
 
CeliaAuthor Commented:
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
 
Ryan ChongCommented:
Hi Celia,

Finally, please post your code! Make it easier to help you.
0
 
CeliaAuthor Commented:
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
 
glass_cookieCommented:
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
 
modderCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now