473,480 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

End a loop error

DJRhino1175
221 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub ExportCP_Click()
  2.  
  3. On Error GoTo Proc_err
  4.  
  5.     Dim strSQL As String
  6.     Dim rs As DAO.Recordset
  7.  
  8.     Set db = CurrentDb()
  9.  
  10.     DoCmd.OpenForm "Web Bruce", acNormal, "CP_FEMA_PF_OutPut-QRY"
  11.  
  12.     strSQL = "CP_FEMA_PF_OutPut"
  13.  
  14.     Set rs = CurrentDb.OpenRecordset(strSQL)
  15.  
  16.     With rs
  17.  
  18.         If Not .BOF And Not .EOF Then
  19.             .MoveLast
  20.             .MoveFirst
  21.  
  22.     While (Not .EOF)
  23.  
  24.     With CodeContextObject
  25.  
  26.             DoCmd.OpenReport "rptFinalCPExport", acViewPreview, "", "[Part Number]=[Forms]![Web Bruce]![Part]"
  27.             DoCmd.OutputTo acOutputReport, "rptFinalCPExport", "PDFFormat(*.pdf)", Forms![Web Bruce]![Web Output], False, "", , acExportQualityPrint
  28.             DoCmd.SetWarnings False
  29.             DoCmd.Close acReport, "rptFinalCPExport"
  30.             DoCmd.SetWarnings True
  31.             DoCmd.GoToRecord acForm, "Web Bruce", acNext
  32.  
  33.     End With
  34.          .MoveNext
  35.     Wend
  36.     End If
  37. End With
  38.  
  39.  
  40. Proc_err:
  41.  
  42. MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
  43. Error:
  44.  
  45. Select Case Err.Number
  46.     Case 2501:      'Cancel button error
  47.         GoTo Cancel_Error
  48.     Case 2105:
  49.         GoTo exitsub
  50.     Case 0
  51.         GoTo exitsub
  52.     Case 20
  53.         GoTo exitsub
  54.  
  55. End Select
  56.  
  57. Cancel_Error:   'What you need the handler to do
  58.     Err.Clear
  59.     Resume Next
  60. exitsub:
  61.     Set rs = Nothing
  62.     Set db = Nothing
  63.     DoCmd.SetWarnings True
  64. Exit Sub
  65.  
  66. End Sub
The above code works fairly well, the only Issue I have is when it goes through all the records needing exported it pops up an error #0 but does not state what its for. After some research its says not ending a loop can cause this error. I thought "Wend" was supposed to do this. So I researched more and found "Wend" is no longer supported. It says to use "End While". So I did this and it throws a syntax error when I try to compile it. Any one have a solution for me to try?

Thanks,

Rhino
Mar 22 '22 #1
3 4457
NeoPa
32,556 Recognized Expert Moderator MVP
Hi Rhino.

I'm not sure if/when While ... Wend ever got discontinued but the replacement for it is Do While ... Loop, or really Do ... Loop, which has optional While or Until modifiers that can be used at either the Do line or the Loop one.

In your case I would use Do Until .EOF ... Loop.
Mar 22 '22 #2
DJRhino1175
221 New Member
Thanks NeoPa. That's what I needed. I even cleaned up the code some more. Here is what it looks like now. No errors.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ExportCP_Click()
  2.  
  3. On Error GoTo Error
  4.  
  5.     Dim strSQL As String
  6.     Dim rs As DAO.Recordset
  7.  
  8.     DoCmd.OpenForm "Web Bruce", acNormal, "CP_FEMA_PF_OutPut-QRY"
  9.  
  10.     strSQL = "CP_FEMA_PF_OutPut"
  11.  
  12.     Set rs = CurrentDb.OpenRecordset(strSQL)
  13.  
  14. If Not (rs.BOF And Not rs.EOF) Then
  15.             rs.MoveFirst
  16.             Do Until rs.EOF
  17.  
  18.             DoCmd.OpenReport "rptFinalCPExport", acViewPreview, "", "[Part Number]=[Forms]![Web Bruce]![Part]"
  19.             DoCmd.OutputTo acOutputReport, "rptFinalCPExport", "PDFFormat(*.pdf)", Forms![Web Bruce]![Web Output], False, "", , acExportQualityPrint
  20.             DoCmd.SetWarnings False
  21.             DoCmd.Close acReport, "rptFinalCPExport"
  22.             DoCmd.SetWarnings True
  23.             DoCmd.GoToRecord acForm, "Web Bruce", acNext
  24.  
  25.     rs.MoveNext
  26.     Loop
  27.  
  28. End If
  29.  
  30. Error:
  31. Select Case Err.Number
  32.     Case 2501:      'Cancel button error
  33.         GoTo Cancel_Error
  34.     Case 2105:
  35.         GoTo exitsub
  36.     Case 0
  37.         GoTo exitsub
  38.     Case 20
  39.         GoTo exitsub
  40.  
  41. End Select
  42.  
  43. Cancel_Error:   'What you need the handler to do
  44.     Err.Clear
  45.     Resume Next
  46. exitsub:
  47.     rs.Close
  48.     Set rs = Nothing
  49.     DoCmd.SetWarnings True
  50. Exit Sub
  51.  
  52. End Sub
Mar 23 '22 #3
NeoPa
32,556 Recognized Expert Moderator MVP
Always a pleasure Rhino :-)
Mar 24 '22 #4

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

Similar topics

3
2363
by: undercups | last post by:
When I run page I immediatley get "Object expected" message and the tag <body onload="setfocus()" is highlighted. The error occurs in this snippet from within the script file function...
2
4251
by: JMCN | last post by:
help! i'm caught in the endless of "compile error message: do without loop." i thought that i closed all of my statments but it appears not. does anyone know why my structure is incorrect? what...
1
1373
by: SJ | last post by:
I'm developing a WAP client which presently works fine on most mobile phone browsers, but gives me an Infinite loop error (error 1025) when i try to access it from a couple of phones(motorola for...
8
1640
by: Sheldon | last post by:
Hi, I have a problem that and the answer eludes me: I am converting a 2D array to a 1D array within a for loop that looks something like this: ii=0; for (i = 0; i < 300; i++) { for (j =...
11
2748
by: orajit | last post by:
---When I run following code DECLARE v_evct NUMBER(20); v_evcd NUMBER(20); v_class VARCHAR2(100); cursor c1 is select * from input_info; BEGIN
5
2750
by: Poly | last post by:
Here is a block of code that I am having trouble with. I rewrote it as a main function, so I could isolate the problem to fix it, but still haven't been able to figure out the problem. I am pretty...
2
1923
by: Darkside12 | last post by:
Hi, I'm trying to create a do loop that renames files in a folder. My current code looks like this: Private Sub Rename_Files_Click() Dim VPNPath As String VPNPath = Dir("C:\Temp\*.txt")
0
831
by: if1467 | last post by:
Hi, I am working with a loop that has the .Find method in it. I need to figure out how to have the program continue when the find doesn't find anything. The VB Help for Find Method shows the...
2
1215
by: rando1000 | last post by:
I keep getting a compile error, "Loop without Do". I've tried Do While and Do Until. What am I doing wrong here? I've got other pieces of code like this in my project, and they work fine. ...
4
8731
by: PlzSendHelp | last post by:
I'm a student and I'm not sure why I'm getting this error. // Using Arduino Uno and RFIDs RC522 #include <require_cpp11.h> #include <MFRC522.h> #include <deprecated.h> #include...
0
7037
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,...
0
6904
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
7032
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
7076
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...
1
6730
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
6873
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...
1
4767
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...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.