Solved

show form before quitting

Posted on 2013-01-16
8
254 Views
Last Modified: 2013-01-19
hey guys,

i've got a frmSynchronise that i open as a hidden form when the DB opens. when i close the DB, i want to display the form and then synchronise the replicas. what this does is that when the user sees the open form, he / she knows that the DB is syncing and thus taking awhile to quit instead of thinking that the programme is lousy.

however, i can't get the form to become visible regardless what i try

Private Sub Form_Close()

Me.Visible = True
DoEvents 'in an attempt to make the form visible
Me.Repaint 'in an attempt to make the form visible
Call GeneralRefactoring.SynchroniseBEReplicas
Application.Quit
'Sleep 1000

End Sub

Open in new window


is it because i'm putting it in the form close event and thus it cannot display? but when i debug and step through, i indeed CAN make the form visible. could yall help me out please? thanks!!
0
Comment
Question by:developingprogrammer
  • 4
  • 3
8 Comments
 
LVL 40

Expert Comment

by:als315
ID: 38786008
If this form is invisible, why code is in Close event for this form? Try to make form visible on form, where you are closing DB.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38786428
I think that you are trying to make this happen too late - and you are giving Access conflicting instructions.

DoCmd.Quit tells Access to shut down.  As it does so, it closes all objects... so this is not a good time to tell it to open (or show) a form.

A workaround if you really need to see the form might be to open a separate database whose sole purpose is to display that form, synchronize the databases (you'd have to adjust the path of the replica since your synchronization code currently assumes that the current database is the replica) and shut itself down.  You could do that from the close event:

Private Sub Form_Close()

Application.FollowHyperlink "YourPath\YourDB.mdb"

End Sub

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38786498
Another (easier) solution might be to create a separate form to handle the synchronization.

Then in the close event:

Private Sub Form_Close()

DoCmd.OpenForm "YourSychronizationFormName", WindowMode := acDialog
Application.Quit
'Sleep 1000

End Sub

Open in new window


And place your synchronization code in "YourSychronizationFormName".

The acDialog window mode option halts code execution in the close event until YourSychronizationFormName closes - so the Application.Quit code won't run until the user closes YourSychronizationFormName, or the code in that form self-closes it.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:developingprogrammer
ID: 38792376
guys, thanks for your great responses.

ok i've done quit a bit of messing around and testing, and here's my line of code.

If Environ("Username") <> "inactive" Then
    DoCmd.OpenForm "frmSynchronise"
    DoEvents
    Call GeneralRefactoring.SynchroniseBEReplicas
    DoCmd.Quit
End If

Open in new window


everything works perfect when i'm closing my form and this code is triggered in the on close event of my main form. however when i hit the x on the top right of the screen to close the access application (not the form), my frmSynchronise does not load up until i can see the words on it. here are the pictures below. how can i get the form to load fully so the user can see the words on the form and know what's going on when they hit alt f4 or the top right x? thanks guys!!

p.s. oh yes guys and i can't use acdialog cause that would stall the code execution until user closes the form or does something. so acdialog is sadly ruled out = (((
when i close the whole application alt f4 or click x top right cornerwhen i close the form
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38792519
My gut feeling here is that you are trying to do the impossible.

You are trying to keep a form open while Access is actively trying to close all objects in the current database (this is what happens when you click the application's "x" button).

You can try the approach I suggested earlier of placing this form in a separate database designed to run the synchronization, or research methods for disabling the Application's "X" button (there are methods out there, but I personally would stick to the second database approach).
0
 

Author Closing Comment

by:developingprogrammer
ID: 38796389
niaks, doing a separate database is a bit too much for me to do so what i did was i just put in the captions of the form "Database syncing to network....." so even though the form is blank they will still see the title of the form and can gather something from there. thanks mbizup and als315!!!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38796433
That is a really good workaround!

If you can't be with the form you love, love the one you're with!
0
 

Author Comment

by:developingprogrammer
ID: 38796459
Hahahaha that's classic!! Going in my diary... = PP = ))
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

840 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