473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Do Loop in Access Code Runs to Infinity

I have inherited someone else's database and process. There is a report that would not work. The problem lies in the code but I do not know enough to fix it.

I turned on all Warnings to help me determine where the problem is. The queries loop continuously as expected but when 0 rows are returned the loop needs to stop.

I have determined this because if I hit No when it asks to return 0 records the report appears in perfect condition. Can someone help me with the EscapeEndlessLoop that they appear to be using but is not working.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintLabels_Click()
  2.  
  3. DoCmd.SetWarnings True
  4. DoCmd.OpenQuery "qdClearLabelQuantities"
  5. DoCmd.OpenQuery "qdClearLabels"
  6. DoCmd.OpenQuery "qaLabelQuantity"
  7. DoCmd.SetWarnings True
  8.  
  9. Dim cmd As ADODB.Command
  10. Dim rst As ADODB.Recordset
  11. Dim prm As ADODB.Parameter
  12.  
  13. Set cmd = New ADODB.Command
  14. Set cmd.ActiveConnection = CurrentProject.Connection
  15. cmd.CommandText = "qsLabelQuantityNotZeroNew"
  16. cmd.CommandType = adCmdTable
  17.  
  18. cmd.Parameters.Refresh
  19. For Each prm In cmd.Parameters
  20.     prm.Value = Eval(prm.Name)
  21. Next prm
  22.  
  23. Set rst = cmd.Execute
  24.  
  25. DoCmd.SetWarnings True
  26.  
  27. Do
  28.     DoCmd.OpenQuery "qaPartNumberLabels"
  29.     DoCmd.OpenQuery "quQuantityMinusOneNew"
  30.     On Error GoTo EscapeEndlessLoop
  31.     rst.MoveFirst
  32. Loop
  33.  
  34. EscapeEndlessLoop:
  35. rst.Close
  36. Set rst = Nothing
  37. Set cmd = Nothing
  38.  
  39. DoCmd.SetWarnings True
  40.  
  41. DoCmd.OpenReport "rlPartNumbers", acViewPreview
  42.  
  43. End Sub
May 4 '14 #1
5 1254
Rabbit
12,516 Expert Mod 8TB
No error is thrown when a query has no records. Instead, loop until the query returns no records by using a DCount on the query.
May 4 '14 #2
Thank you for responding but I don't really know how to write code. What would that DCount look like and where within the Loop command would I put it?

Thanks in advance for any assistance.
May 5 '14 #3
Rabbit
12,516 Expert Mod 8TB
Since you don't know how to write code, you will probably want to learn how to before taking on a project like this.

Here is a link to a tutorial: http://www.functionx.com/vbaccess/Lesson01.htm

And a link to the DCount documentation: http://office.microsoft.com/en-us/ac...001228817.aspx
May 5 '14 #4
Thank you. I was told it was just a simple Access database or I would have turned it down. Thanks again for your help. I think I'll go take a VBA class ASAP.
May 5 '14 #5
Rabbit
12,516 Expert Mod 8TB
Once you have some of the basics down, let us know if you run into trouble with the DCount. You can post the code you used and any error messages you get.
May 5 '14 #6

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

Similar topics

1
by: Rocky A | last post by:
I need to open an excel workbook and import info to my access program. That isn't the problem, I've got the code down for doing what I want to do. I'm declaring the variable and setting it like...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
16
by: nelu | last post by:
I know I can use unsinged byte, but I need it for java, which code runs faster in C? int f1(char b) { return (b&0x80)|(b&0x7f); } or int f2(char b) {
3
by: Academia | last post by:
If the user types into the TextBox of a combobox it works OK. But if he hold a key down so the letter repeats quickly the code runs into trouble. My questions are: Is it true that an event's...
2
by: gangac | last post by:
I am currently working on an ms access application for a large insurance company which generates reports for the user after the user inputs/select some data.... Unfortunately the application has...
2
by: gtfrueh | last post by:
I have a VB6 project that runs OK under XP, but not under Win98. I have not packaged and deployed. I just copied my working folder of code from the XP machine to the Win98 machine. The code on the...
1
by: BhupendraNVyas | last post by:
Dear All, I want to send Out standing E-Mail detail to customer's throug ms access code .....can you help me for genrate a mail and attach a file from local hard disk drive. Regards, Bhupendra
3
by: kenan | last post by:
hi, i have found a solution to calling code behind function but it does not work if i put the call statement in a loop Javascript <script language="javascript"> function init() { alert('hello...
2
by: anymous | last post by:
i have this code, but i don't know how to loop this code. please somebody help me :( import turtle turtle.bgcolor("black") turtle.pensize(5) turtle.penup() turtle.goto(-415,100)...
0
by: group014 | last post by:
1. Groups provide members who purchase a course a voucher with an access code. 2. Buyer enters his unique, personal access code in our site to access registration page. 3. Once registered he has...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.