473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to wait for Count > 0

13 New Member
I have an Access 2003 database linked to an MS SQL 2005 backend. We use the database as part of a process whereby we use Zone OCR to scan records off paper forms into an XML file, suck the data off the XML file into a table and then present the data in the MS ACCESS db for manipulation and correction before being pushed back into other SQL tables. The Scanning process runs on a seperate instance of SQL so the only way to fire it from a Form object is through a SQL job. Unfortunately this will not return a timely recordset, meaning I get a notice that the job started, but that happens immediately and I don't know when the job ends, because the job runs on a named instance of SQL. I have figured out a method of firing a job off in the main instance of SQL to insert a single record into a logging table when the job completes. What I would like to do is use a Do Until loop, or some other method to look at this logging table (UCT_Count) and when the Count of records in the table is greater than 0, then pop a message box in Access stating the job is complete. I Have the following code to fire off the Job
Expand|Select|Wrap|Line Numbers
  1.  
  2. Function DataTransfer()
  3.  
  4.     Dim cnn As ADODB.Connection
  5.     Dim cmd As ADODB.Command
  6.     Dim lngRecs As Long
  7.  
  8.     Set cnn = New ADODB.Connection
  9.     Set cmd = New ADODB.Command
  10.  
  11.     With cnn
  12.       .Provider = "SQLOLEDB"
  13.       .Properties("Data Source") = "ServerName"
  14.       .Properties("Initial Catalog") = "APEXDATA"
  15.       .Properties("User Id") = "XXXXuserName"
  16.       .Properties("Password") = "XXXXXXXXX"
  17.       .Open
  18.     End With
  19.  
  20.     Set cmd.ActiveConnection = cnn
  21.     cmd.CommandText = "dbo.ACC_util_UCT_DataTransfer"
  22.     cmd.CommandType = adCmdStoredProc
  23.  
  24.     cmd.Execute
  25.  
  26.     Set cmd = Nothing
  27.     cnn.Close
  28.     Set cnn = Nothing
  29.   End Function
  30.  
This will fire the stored proc which starts a job etc...that ends with a single record in the logging table. I am just not sure how to wrap this in a Do Until loop until rCount >0
Expand|Select|Wrap|Line Numbers
  1.   SELECT COUNT(CompleteDate) FROM UCT_Count as rCount 
Then pop a MsgBox to show the job completed.
I hope this makes sense, if not let me know.
Nov 18 '09 #1
4 2414
NeoPa
32,568 Recognized Expert Moderator MVP
Would something like this work for you :
Expand|Select|Wrap|Line Numbers
  1. Do
  2.     DoEvents()
  3.     rCount = DCount("[CompleteDate]", "[UCT_Count]")
  4. Loop Until rCount > 0
Nov 18 '09 #2
thayes5150
13 New Member
Thanks, that did the trick - had to play around with placement to get it to keep from interrupting my code execution, but it works like a charm now. Much better alternative to a generic sleep timer that I was going to use. Thanks again. Completed code posted below:
Expand|Select|Wrap|Line Numbers
  1. Function DataTransfer()
  2.  
  3.     Dim cnn As ADODB.Connection
  4.     Dim cmd As ADODB.Command
  5.     Dim lngRecs As Long
  6.     Dim rCount As Integer
  7.  
  8.     rCount = 0
  9.  
  10.     Set cnn = New ADODB.Connection
  11.     Set cmd = New ADODB.Command
  12.  
  13.     With cnn
  14.       .Provider = "SQLOLEDB"
  15.       .Properties("Data Source") = "ServerName"
  16.       .Properties("Initial Catalog") = "APEXDATA"
  17.       .Properties("User Id") = "XXXXuser"
  18.       .Properties("Password") = "XXXXXX"
  19.       .Open
  20.     End With
  21.  
  22.     Set cmd.ActiveConnection = cnn
  23.     cmd.CommandText = "dbo.ACC_util_UCT_DataTransfer"
  24.     cmd.CommandType = adCmdStoredProc
  25.  
  26.     cmd.Execute
  27.  
  28.         Do
  29.         DoEvents
  30.         rCount = DCount("[CompleteDate]", "[dbo_UCT_Count]")
  31.         Loop Until rCount > 0
  32.         MsgBox "The Data has been transfered."
  33.  
  34.  
  35.     Set cmd = Nothing
  36.     cnn.Close
  37.     Set cnn = Nothing
  38.   End Function
  39.  
Nov 19 '09 #3
ADezii
8,834 Recognized Expert Expert
If you wish to avoid a Do..Loop all together:
  1. Create a small Form and Minimize it.
  2. Set the Form's Timer Interval to 10000 (10 secs).
  3. Place the following code, or something similar, in the Form's Timer() Event.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Timer()
    2. Dim intResponse As Integer
    3. Dim strMsg As String
    4.  
    5. strMsg = "Record Count in Table UCT_Count > 0" & vbCrLf & vbCrLf & _
    6.          "Reset/Minimize Form and Set Timer Interval?"
    7.  
    8. If DCount("*", "UCT_Count") > 0 Then
    9.   DoCmd.Restore
    10.   Me.TimerInterval = 0        'Turn OFF the Timer
    11.     intResponse = MsgBox(strMsg, vbYesNo + vbQuestion, "Reset Form")
    12.         If intResponse = vbYes Then
    13.           DoCmd.Minimize
    14.           Me.TimerInterval = 10000    'Restore Timer Interval to 10 secs
    15.         End If
    16. End If
    17. End Sub
    18.  
  4. Every 10 seconds (you can vary this), Table UDC_Count will be polled to see if it contains a Record. If it does, the Form will be Restored with some kind of descriptive Message or a Message Box, and the Timer will be Disabled. You will then have the option to Rest the Timer, Minimize the Form again, and start all over.
Nov 19 '09 #4
NeoPa
32,568 Recognized Expert Moderator MVP
While my suggestion answers your question more directly, I would certainly recommend ADezii's suggestion over that as it uses the facilities of Access better.

Note also the slight change to the DCount() usage. Your original call requests the count of all records which contain a value for [CompleteDate]. If you really need a simple count of all records, then ADezii's version is the more correct. Even if there will always be a value for any existing record, his code is clear what it's asking for whereas yours (in that situation) would return an accurate value, but be misleading for anyone reading your code.
Nov 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3888
by: The Beast | last post by:
I'm trying to create a thread to write to the serial port and I keep getting an odd error cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)' and it points to the CreateThread call. Here is my class, why is it doing this and how can I fix it? <TxdRxd.h>
0
1322
by: - | last post by:
i have a query as follows and is unsure whether it is mysql or php: $result = mysqli_query("SELECT COUNT(*) > @foobar AS status ....") where it's suppose to get a one row value of either '0' or '1' (false or true) if i were to do a SELECT COUNT(*) FROM... i can use the php $row to refer to the index. if i were to do a SELECT COUNT(*) AS status FROM... i can use the php $row to refer to the index.
11
20340
by: Peter Kirk | last post by:
Hi there I am looking at using a thread-pool, for example one written by Jon Skeet (http://www.yoda.arachsys.com/csharp/miscutil/). Can anyone tell me if this pool provides the possibility to wait for all its threads to finish? For example, if I start 20 threads: CustomThreadPool pool = new CustomThreadPool("PetersThreadPool"); ThreadMethod m = new ThreadMethod(InsertThread);
11
1530
by: Farel | last post by:
Which is Faster in Python and Why? jc = {}; m = x = ,,.......] # upwards of 10000 entries def mcountb(): for item in x: b = item; b.sort(); bc = 0 for bitem in b: bc += int(bitem) try: m = jc
0
11695
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"; We get such errors generally on inserts or updates while applying a
3
1838
by: Jimmy | last post by:
Is there a way to force access to wait a specified time before making a calculation? On my report there is a subreport with a number of calculation on it. One if which is a count of certain records using a text control with a running sum. When I display the subreport on my main report, I can see the correct count but when I make a reference to that control on the main report, I simply get the number 1. I am sure that the reference to the...
5
5580
by: Deepak | last post by:
I am programing a ping application which pings various centers . I used timer loop and it pings one by one. Now when i finish pinging one center it should wait for the ping_completed function to be executed and then continue pinging another certer. The ping_completed function is called on completion of ping by the os and i have no control on it .
26
2443
by: Ping | last post by:
Hi, I'm wondering if it is useful to extend the count() method of a list to accept a callable object? What it does should be quite intuitive: count the number of items that the callable returns True or anything logically equivalent (non-empty sequence, non-zero number, etc). This would return the same result as len(filter(a_callable, a_list)), but without constructing an intermediate list which is thrown away after len() is done.
22
11744
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened in my situation. I first created a few child processes with Popen, then in a while(True) loop wait on any of the child process to exit, then restart a child process: import os from subprocess import Popen
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.