Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wrapping code into another SUB? HOW? (Access2003)

    Can you, please, tell me how to operate this code?

    I have code written on Click of the button.

    Now I have to use this code below to set up running of my Update code in certain time.

    _______________________________

    Sub timer_set()

    Dim PauseTime, Start, Finish, TotalTime
    Dim TT As Date
    Dim TT2 As Date
    Dim varMSG As Variant
    Dim then_start As Date




    TT = Now()


    then_start = InputBox("Enter Start Time in MM/DD/YYYY ##:## AM/PM Format")
    'then_start = "12/8/2008 7:05 am"
    Start = timer ' Set start time.

    Do While Now < then_start
    DoEvents ' Yield to other processes.
    Loop
    Finish = timer ' Set end time.



    TotalTime = Finish - Start ' Calculate total time.



    TT2 = Now()
    varMSG = MsgBox("Started: " & TT & " Completed: " & TT2, vbInformation)
    _____________________________________________



    Where am I suppose to insert this code for it to work?


    My Update code is :
    ___________________________
    Private Sub My_Update_Code_Click()

    DoCmd.SetWarnings False


    DoCmd.OpenQuery "1-A"
    DoCmd.OpenQuery "1-X"

    MsgBox "Report data was refreshed successfully, you can run the Reports now!"


    End Sub
    _________________________________

    Thanks so much! Good weekend!

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Wrapping code into another SUB? HOW? (Access2003)

    I dont understand what you are trying to do, but the variable you use for current time (timer) is not right,it should beTime not timer.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrapping code into another SUB? HOW? (Access2003)

    I use to run this code:
    ___________________________
    Private Sub My_Update_Code_Click()

    DoCmd.SetWarnings False


    DoCmd.OpenQuery "1-A"
    DoCmd.OpenQuery "1-X"

    MsgBox "Report data was refreshed successfully, you can run the Reports now!"


    End Sub
    _________________________________


    Now I was told to run it with timer.

    I need to insert timer code into Update code.

    I just don't see where to call the sub from. Thanks

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Wrapping code into another SUB? HOW? (Access2003)

    you said "
    Now I was told to run it with timer."

    What do you mean by this?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wrapping code into another SUB? HOW? (Access2003)

    There's no point in calling timer_set from your code. You could do something like this:

    Private Sub My_Update_Code_Click()
    Dim t As Single
    ' Set start time
    t = Timer
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "1-A"
    DoCmd.OpenQuery "1-X"
    ' Subtract start time from end time to get running time
    t = Timer - t
    MsgBox "Report data was refreshed successfully in " & Format(t, "0.0") & " seconds, you can run the Reports now!"
    End Sub

Posting Permissions

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