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
Solved

VBA - Pause for 1 second then loop once

Posted on 2004-09-15
3
1,301 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

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

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

808 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