Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA - Pause for 1 second then loop once

Posted on 2004-09-15
3
Medium Priority
?
1,311 Views
Last Modified: 2011-10-03
Part of my VBA (shown below) is triggered when you click on the button cmdSearch.  This triggers a search query on a database and returns the results.  The strange thing is that the results returned when clicked arn't all of the those that should, if you press search for a second time you then get the full list returned.  I think this may be a problem with the stored procedures which I'll sort out at a later date.  As a workaround , what I want is to put in a bit of extra code that when the cmdSearch button is clicked, it runs the main code below, then has a delay of a second and runs it again.  Any ideas how I would do this?


Private Sub cmdSearch_Click()

    pClearTheGrid

    Dim adosqltemp As New ADODB.Command
    adosqltemp.ActiveConnection = gAdosqlconn

    Dim myvar(0 To 5) As Variant

    Dim lngDept As Long
    lngDept = gActualDept
    myvar(2) = lngDept
    myvar(4) = "Code"
    If optClientName.Value = True Then
       myvar(4) = "Name"
    End If
    myvar(0) = ""
    myvar(1) = UCase(txtClient)
    myvar(3) = chkLinkedDept.Value
    myvar(5) = chkTSonly.Value
   
    chkTSonly = False
   
    adosqltemp.CommandType = adCmdStoredProc
    adosqltemp.CommandText = "usp_TSCliSearch"
   
    Dim rs2 As ADODB.Recordset
    Set rs2 = adosqltemp.Execute(, myvar)

    Dim irow As Integer
    irow = 0
 
    If rs2.BOF = True And rs2.EOF = True Then
      flxGridClientList.Row = 1
      flxGridClientList.Col = 0
      flxGridClientList.Text = txtClient.Value
      flxGridClientList.Col = 1
      flxGridClientList.Text = "*** No records match ***"
      flxGridClientList.ForeColor = vbRed
      Exit Sub
    End If
   
     flxGridClientList.Visible = False
     irow = 0
     While (Not rs2.EOF) And irow < 30
             
         irow = irow + 1
         flxGridClientList.Rows = irow + 1
         flxGridClientList.Row = irow
         flxGridClientList.Col = 0
         flxGridClientList.Text = rs2!ClientCode
         flxGridClientList.Col = 1
         flxGridClientList.Text = rs2!Title1 & " " & rs2!title2
         rs2.MoveNext
     
      Wend
      flxGridClientList.Visible = True

    Set rs2 = Nothing
   

End Sub
0
Comment
Question by:wobbled
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1000 total points
ID: 12062604
Copy  the bulk of the code to a module procedure, called, say MySearch
Put this code at the end of your cmd Search_click procedure.

Application.OnTime DateAdd("s", 1, Now()), "MySearch"
0
 
LVL 17

Author Comment

by:wobbled
ID: 12345911
Apologies for this, I thought I had left an answer, but was wrong.

The reply from GrahamSkan unfortuntly did not work as it then produced a number of errors where it said that it could not find the variables I set.  I believe this is probably due to the number of different forms and how the code has been spreadaround in different modules etc.

While GrahamSkan's reply did not provide the answer it did give me the id of using the Application.OnTime function so I will award him the points, which I eventually got there with

Many Thanks

W
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question