?
Solved

VBA - Pause for 1 second then loop once

Posted on 2004-09-15
3
Medium Priority
?
1,308 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

800 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