Solved

show form before quitting

Posted on 2013-01-16
8
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

726 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