Text box content won't display

RichO

Registered Yoozer
Local time
Yesterday, 20:01
Joined
Jan 14, 2004
Messages
1,036
Here's a strange one.....

We have only 4 computers in our office. Our DB backend is SQL server and due to constant corruption of the database from multiple users, each user/computer runs its own separate copy of the mdb file.

I have set up a small form in a separate database to allow me to quickly compact the DB and copy it to the 4 locations on the network instead of doing it manually. This process works fine...BUT....I have a text box on the form set up to display the copy progress and the contents of the text box do not properly display during the file copying. Even though the code to change the value of the textbox comes before the file copy command, the textbox will not display the until after the copying is finished. However, when I step debug the process it displays the information correctly before the file copy command executes.

Here is a sample of my code...
Code:
    Dim strPath1    As String
    Dim strpath2    As String
    
    strPath1 = "C:\FortuneSystem\Temp.mdb"
    strpath2 = "\\Scott\Fortune\"
        
    If Dir("C:\FortuneSystem\Fortune_System.ldb") <> vbNullString Then
        MsgBox "Cannot proceed!  Fortune database is open.", vbCritical
        Exit Sub
    End If
    
    [B]txtProgress = "Compacting Database"[/B]
    [COLOR="YellowGreen"]'compact master DB to a temporary DB file[/COLOR]
    DBEngine.CompactDatabase "C:\FortuneSystem\Fortune_System.mdb", strPath1
    [b]txtProgress = ""[/b]
    If chkTed Then
        If Dir(strpath2 & "Ted.ldb") <> vbNullString Then
            MsgBox "Ted cannot be copied.  Program is running.", vbCritical
        Else
            Screen.MousePointer = 11
            [b]txtProgress = "Ted Copying"[/b]
            Kill strpath2 & "Ted.mdb"
            FileCopy strPath1, strpath2 & "Ted.mdb"
            [b]txtProgress = ""[/b]
            Screen.MousePointer = 0
        End If
    End If
....etc...

Can anyone explain why this is happening and possibly a way around it?

Thanks
 
I believe this happens because by default Access only repaints the screen after event procedures are completed. In most cases the time frames are too small to notice.
You can force a repaint on a form using "Me.Repaint", but that means you'd need two lines of code everywhere you update your text box.
What I'd do is write a ShowProgress routine like...

Code:
Private Sub ShowProgress(text as string)
  Me.txtProgress = text
  Me.Repaint
End Sub
And then you can get the job with one line like...
Code:
  ...
  ShowProgress "Compacting Database"
  DBEngine.CompactDatabase "C:\FortuneSystem\Fortune_System.mdb", strPath1
  ShowProgress ""
  ...
 
Repaint did the trick. Thanks!
 

Users who are viewing this thread

Back
Top Bottom