Solved

VBA - Pause for 1 second then loop once

Posted on 2004-09-15
3
1,296 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
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 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

A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
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 video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now