?
Solved

VBA - Pause for 1 second then loop once

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

864 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