How to pause the unload of my form
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to pause the unload of my form

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    4

    How to pause the unload of my form

    Hi,

    I'm new at this so bear with me..

    I have the code below that moves my files, then at the end of my move I want to display a lable that shows sucess...I have that and it works fine...BUT....the label changes and I send the form unload (because I want to close the form) it happens so fast my users won't be able to see the result.

    How can I can delay the closing of the form for a few seconds?

    Code:
    Private Sub Form_Load()
    '
        Form1.Refresh
        Form1.Show
        Form1.AutoRedraw = True
        Form1.Visible = True
        Form1.Image1.Visible = True
        Form1.Label1.Caption = "Starting Copy of open MDB Files"
        Form1.Command1.Visible = False
    
    
        'Label1.Caption = "Starting Copy of MDB Files from WSIPR2"
       
       Dim fso As New FileSystemObject
        Form1.Refresh
        Form1.Show
        Form1.AutoRedraw = True
        Form1.Visible = True
        Form1.Image1.Visible = True
        Form1.Label1.Caption = "Starting Copy of open MDB Files"
        Form1.Command1.Visible = False
     
    '     fso.CopyFile "\\WSIPR2\GSAP\WSITES\TES.mdb", "\\GSDCSHR01\gsap\WSITes\TES.mdb"
    '     fso.CopyFile "\\WSIPR2\GSAP\WSITES\WSIDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\WSITes\WSIDATA\ultidata.mdb"
    ''
    '     fso.CopyFile "\\WSIPR2\GSAP\TES_Remote\ASTTES\TES.mdb", "\\GSDCSHR01\gsap\TES_Remote\ASTTES\TES.mdb"
    '     fso.CopyFile "\\WSIPR2\GSAP\TES_Remote\ASTTES\ASTDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\TES_Remote\ASTTES\ASTDATA\Ultidata.mdb"
    '
    '     fso.CopyFile "\\WSIPR2\GSAP\TES_REMOTE\AGUTES\TES.mdb", "\\GSDCSHR01\gsap\TES_Remote\AGUTES\TES.mdb"
    '     fso.CopyFile "\\WSIPR2\GSAP\TES_REMOTE\AGUTES\AGUDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\TES_Remote\AGUTES\AGUDATA\Ultidata.mdb"
    '
    '     fso.CopyFile "\\WSIPR2\GSAP\TES_REMOTE\ITITES\TES.mdb", "\\GSDCSHR01\gsap\TES_Remote\ITITES\TES.mdb"
          fso.CopyFile "\\WSIPR2\GSAP\TES_REMOTE\ITITES\ITIDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\TES_Remote\ITITES\ITIDATA\Ultidata.mdb"
          
        Label1.Caption = "Starting Compact & Repair of MDB Files on GSDCSHR01"
        
    '     If Dir("\\GSDCSHR01\gsap\WSITes\TES2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\WSITes\TES2.mdb"
    '        DBEngine.CompactDatabase "\\GSDCSHR01\gsap\WSITes\TES.mdb", "\\GSDCSHR01\gsap\WSITes\TES2.mdb"
    '
    '     If Dir("\\GSDCSHR01\gsap\WSITes\WSIDATA\ultidata2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\WSITes\WSIDATA\ultidata2.mdb"
    '        DBEngine.CompactDatabase "\\GSDCSHR01\gsap\WSITes\WSIDATA\ultidata.mdb", "\\GSDCSHR01\gsap\WSITes\WSIDATA\ultidata2.mdb"
    '
    '     If Dir("\\GSDCSHR01\gsap\TES_Remote\ASTTES\TES2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\TES_Remote\ASTTES\TES2.mdb"
    '        DBEngine.CompactDatabase "\\GSDCSHR01\gsap\TES_Remote\ASTTES\TES.mdb", "\\GSDCSHR01\gsap\TES_Remote\ASTTES\TES2.mdb"
    '
    '     If Dir("\\GSDCSHR01\gsap\TES_Remote\ASTTES\ASTDATA\Ultidata2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\TES_Remote\ASTTES\ASTDATA\Ultidata2.mdb"
    '        DBEngine.CompactDatabase "\\GSDCSHR01\gsap\TES_Remote\ASTTES\ASTDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\TES_Remote\ASTTES\ASTDATA\Ultidata2.mdb"
    '
    '     If Dir("\\GSDCSHR01\gsap\TES_Remote\AGUTES\TES2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\TES_Remote\AGUTES\TES2.mdb"
    '         DBEngine.CompactDatabase "\\GSDCSHR01\gsap\TES_Remote\AGUTES\TES.mdb", "\\GSDCSHR01\gsap\TES_Remote\AGUTES\TES2.mdb"
    '
    '     If Dir("\\GSDCSHR01\gsap\TES_Remote\AGUTES\AGUDATA\Ultidata2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\TES_Remote\AGUTES\AGUDATA\Ultidata2.mdb"
    '        DBEngine.CompactDatabase "\\GSDCSHR01\gsap\TES_Remote\AGUTES\AGUDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\TES_Remote\AGUTES\AGUDATA\Ultidata2.mdb"
    '
    '     If Dir("\\GSDCSHR01\gsap\TES_Remote\ITITES\TES2.mdb") <> "" Then Kill _
    '        "\\GSDCSHR01\gsap\TES_Remote\ITITES\TES2.mdb"
    '        DBEngine.CompactDatabase "\\GSDCSHR01\gsap\TES_Remote\ITITES\TES.mdb", "\\GSDCSHR01\gsap\TES_Remote\ITITES\TES2.mdb"
    '
          If Dir("\\GSDCSHR01\gsap\TES_Remote\ITITES\ITIDATA\Ultidata2.mdb") <> "" Then Kill _
             "\\GSDCSHR01\gsap\TES_Remote\ITITES\ITIDATA\Ultidata2.mdb"
             DBEngine.CompactDatabase "\\GSDCSHR01\gsap\TES_Remote\ITITES\ITIDATA\Ultidata.mdb", "\\GSDCSHR01\gsap\TES_Remote\ITITES\ITIDATA\Ultidata2.mdb"
    
      Label2.Caption = "Finished Compact and Repair of MDB File"
       Unload Form1

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: How to pause the unload of my form

    This should be faster:

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    ' Set Reference to Microsoft Jet Runtim Object (JRO)
    '  BROWSE if not found: \program files\common files\system\ado\msjro.dll
      CompactAndRepair (db$)
    End Sub
    
    Also, I'd run the C&R BEFORE any other code.  In a splash screen would be best...
    
    
    Sub CompactAndRepair(db$)
      Dim jro As jro.JetEngine, xn$
      Set jro = New jro.JetEngine
      Screen.MousePointer = vbHourglass
      xn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\"
      jro.CompactDatabase xn & db, xn & db & "-2"
      If Len(Dir(App.Path & "\" & db & "-2")) > 0 Then
        Kill App.Path & "\" & db
        Do While Len(Dir(App.Path & "\" & db)) > 0
          DoEvents               ' wait for delete
        Loop
        Name App.Path & "\" & db & "-2" As App.Path & "\" & db
        Do While Len(Dir(App.Path & "\" & db)) = 0
        DoEvents        ' wait for copy to complete
        Loop
    End If
    Screen.MousePointer = vbDefault
    End Sub
    Last edited by dglienna; November 1st, 2012 at 05:43 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2005
    Posts
    1,074

    Re: How to pause the unload of my form

    Move all your code to Form_Paint event and give it a try

    ...but remove all your Refresh, Redraw,etc. they will not be neccesary
    Last edited by jggtz; November 1st, 2012 at 06:49 PM.
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center