Results 1 to 8 of 8
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    why use timer for copyfile?

    i have a FE updater that several you helped me with several months back and it worked most of the time but i have been researching these methods and rewriting to meet more of my needs. my question is the start timer and loop, what is its purpose? i just this afternoon ran my first successful test with my version, but for simplicity i had left this start and loop commented out but the updater still downloaded the new version just fine. whats its purpose, download speed maybe? would i be safe leaving it out or is there something i'm not thinking of for its reason to be there?

    Code:
    If Me.txtversion <> Me.lblversion.Caption Then
    'copy Access file
    CreateObject("Scripting.FileSystemObject").CopyFile _
        "C:\users\myname\documents\testnew\test1.accdb","C:\", True
    'allow enough time for file to completely copy before opening
    Dim Start As Double
    Start = Timer
    While Timer < Start + 3
        DoEvents
    Wend
    'load new version - SysCmd function gets the Access executable file path
    'Shell function requires literal quote marks in the target filename string argument, hence the quadrupled quote marks
    Shell SysCmd(acSysCmdAccessDir) & "MSAccess.exe " & """" & CurrentProject.FullName & """", vbNormalFocus
    'close current file
    DoCmd.Quit
    Else
        DoCmd.BrowseTo acBrowseToForm, "form1"
    End If


  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    The 5th line states it is a Kludge attempt to prepare for the document to be completely copied before continuing.

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    ok, sorry i hadn't read the original version of the code i posted in a few days and didn't notice that. so it sounds like i definitely need it and maybe increase it.

  4. #4
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Its interesting to see use of timer and the filesystemobject. You may also be able to compare the filesize of the destination file to the original. and wait till that completes. While using the timer to make sure it hasnt been longer than a your threshold.

    I tried to test the code below, but SSD and sweet technology make them just spit out Start then Done in the immediate. Maybe it will do for you.

    Code:
    Public Sub CopyTillDone(ByVal strSource As String, ByVal strDestination As String, Optional Timeout As Integer = 60)
    Dim dblStart As Double: dblStart = Timer
        Debug.Print "Start"
        Set fso = CreateObject("Scripting.FileSystemObject")
        fso.CopyFile strSource, strDestination, True
        
        Do While GetFileSize(strSource) <> GetFileSize(strDestination)
            DoEvents
            Debug.Print "Waiting"
            If Timer > Start + intTimerLimit Then Exit Do
        Loop
        Debug.Print "Done"
        Set fso = Nothing
    End Sub
    Function GetFileSize(ByVal strFileName As String)
      Set fso = CreateObject("Scripting.FileSystemObject")
      
      If fso.FileExists(strFileName) Then
        Set file = fso.GetFile(strFileName)
        GetFileSize = file.Size
      Else
        GetFileSize = -1
      End If
      Set fso = Nothing
      Set file = Nothing
    End Function

  5. #5
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    Holly smoke batman i hadn't thought of that or seen it used but that's a great ideal that will help with slow download speeds. i was actually worried about the timer for that reason, i built a small tracking DB last week and put it on a few desktops this week, short version is that every 10 minutes it takes 200 numbers from a linked table on the network and does a sum, then records the milliseconds and time of day it took. its been amazing the difference in time from one 10 minute period to the next. I'll get started tomorrow reading up on what you've wrote and getting it integrated. Thanks

  6. #6
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Yeah just thought of it lols. It was the alternative to invoking a ftp shell and sending a file to replicate the completion.

  7. #7
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    Again thanks, here is what i ended up with, taking what i had already rewrote from the original and adding the file comparison ideal.

    Code:
    Option Compare Database
    Option Explicit
    Public strSource As String
    Public strDestination As String
    Public strSourcesize As Variant
    Public strDestinationsize As Variant
    Public fs As Variant
    Public linkver As Integer
    Public ver As Integer
    Public strname As String
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Public Sub versioncheck()
        
    On Error GoTo ErrorHandler:
        DoCmd.Hourglass True
        DoCmd.Echo True, "thinking..."
        linkver = DLookup("version", "defaultlinkt")
        ver = DLookup("version", "defaultt")
        'MsgBox "started"
        If linkver <> ver Then
            Set fs = CreateObject("Scripting.FileSystemObject")
                'get source from linked table
            strSource = DLookup("felocation", "defaultlinkt")
            'set destination as current location
            strDestination = CurrentProject.Path & "\"
                'copy source to dest
            fs.CopyFile strSource, strDestination, True
                'source file size
            strSourcesize = GetFileSize(strSource)
                'destination file size
            strDestinationsize = GetFileSize(strDestination)
            strname = CurrentProject.Name
            DoCmd.Echo True, "Start loop..."
            Do While (strSourcesize) <> (strDestinationsize)
                Dim Start As Double
                Start = Timer
                Sleep 1000
                If Timer < Start + 3 Then Exit Do
            Loop
            Set fs = Nothing
            Shell SysCmd(acSysCmdAccessDir) & "MSAccess.exe " & """" & CurrentProject.FullName & """", vbNormalFocus
            'close current file
            DoCmd.Quit
            
        End If
         
        Exit Sub
    ErrorHandler:
        Call LogError(Err.Number, Err.Description, "newversion_versionchecker()")
    End Sub
    Function GetFileSize(ByVal strFileName As String)
    Dim fso As Variant
    Dim File As Variant
    On Error GoTo ErrorHandler:
      Set fso = CreateObject("Scripting.FileSystemObject")
      
      If fso.FileExists(strFileName) Then
        Set File = fso.GetFile(strFileName)
        GetFileSize = File.Size
      Else
        GetFileSize = -1
      End If
      Set fso = Nothing
      Set File = Nothing
        Exit Function
    ErrorHandler:
        Call LogError(Err.Number, Err.Description, "newversion_GetFileSize()")
      
    End Function
    feel free to pick it apart. so far it appears to be working.

  8. #8
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Glad it works for you =). I will have to remember this solution.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. In Use Timer
    By dccjr in forum Programming
    Replies: 7
    Last Post: 09-18-2013, 12:40 PM
  2. Timer on IIf Statements?
    By athyeh in forum Programming
    Replies: 4
    Last Post: 07-29-2013, 09:54 PM
  3. Debugger and Timer
    By DepricatedZero in forum Programming
    Replies: 2
    Last Post: 05-29-2013, 01:15 PM
  4. countdown Timer
    By yigitki in forum Programming
    Replies: 16
    Last Post: 11-11-2011, 11:24 AM
  5. Timer object
    By joki in forum Programming
    Replies: 7
    Last Post: 03-17-2011, 08:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums