Results 1 to 6 of 6

Thread: Time delay

  1. #1
    Join Date
    Aug 2004
    Posts
    4

    Unanswered: Time delay

    Is there any way to hold the execution of a portion of your procedure for a few seconds? What my procedure does is to insert a new record into an Access table and then refresh the data grid. Unfortunately, the data grid is not refreshing because I noticed that it starts refreshing even before the record is added to the Access table. I was hoping to insert a line in my procedure asking it to wait for a few seconds before refreshing the data grid.

    Below is an example of my procedure:
    Dim dbs As ADODB.Connection
    Set dbs = New ADODB.Connection
    dbs.ConnectionString = "Provider=MSDASQL.1;Data Source=ABC"
    dbs.Open
    dbs.Execute "INSERT INTO Temp_Table (Temp_Field) VALUES (1);"
    dbs.Close
    Set dbs = Nothing
    queryAccess = "Select * from Temp_Table"
    If DataEnviron.rsBrw_Access.State = 1 Then
    DataEnviron.rsBrw_Access.Close
    End If
    DataEnviron.Commands("Brw_Access").CommandText = queryAccess
    DataEnviron.Commands("Brw_Access").Execute
    Set dtg_Access.DataSource = DataEnviron
    dtg_Access.DataMember = "Brw_Access"
    dtg_Access.Refresh

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I haven't tried this, but would it work if you posted the refresh instead of calling it directly? That might induce just the right amount of delay, without actually wasting any time.

    -PatP

  3. #3
    Join Date
    Aug 2004
    Posts
    4
    I'm sorry but what do you mean by posting the refresh?

  4. #4
    Join Date
    Apr 2004
    Location
    Arizona
    Posts
    75

    TRy This

    Dim Delay as Integer
    Dim CurrentTime as Integer
    Dim StartTime as Integer

    StartTime = Timer
    Delay = StartTime + 10 'Number of second you want to pause
    CurrentTime = StartTime

    While CurrentTime <= Delay
    CurrentTime = Timer
    WEnd

  5. #5
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    Declare your connection object at the module level using the WithEvents command like this:

    Private WithEvents dbs As ADODB.Connection

    Now your connection object has an Event called ExecuteComplete

    Put the refresh code in that event. In this manner the refresh will happen exactly when the execute has completed.
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  6. #6
    Join Date
    Aug 2004
    Posts
    16
    Sub Delay(pdblSeconds As Double)
    On Error Resume Next
    Const OneSecond As Double = 1# / (1440# * 60#)
    Dim dblWaitUntil As Date
    dblWaitUntil = Now + OneSecond * pdblSeconds
    Do Until Now > dblWaitUntil
    Sleep 100
    DoEvents
    Loop
    End Sub

    Then type:
    delay (5) where ever you need to delay, It will then delay for 5 seconds before it continues.

Posting Permissions

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