472,961 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

End a loop error

DJRhino1175
221 128KB
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

✓ answered by NeoPa

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.

3 4383
NeoPa
32,547 Expert Mod 16PB
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 128KB
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,547 Expert Mod 16PB
Always a pleasure Rhino :-)
Mar 24 '22 #4

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

Similar topics

3
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
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
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
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
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
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
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
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
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
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
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.