- Private Sub ExportCP_Click()
-
-
On Error GoTo Proc_err
-
-
Dim strSQL As String
-
Dim rs As DAO.Recordset
-
-
Set db = CurrentDb()
-
-
DoCmd.OpenForm "Web Bruce", acNormal, "CP_FEMA_PF_OutPut-QRY"
-
-
strSQL = "CP_FEMA_PF_OutPut"
-
-
Set rs = CurrentDb.OpenRecordset(strSQL)
-
-
With rs
-
-
If Not .BOF And Not .EOF Then
-
.MoveLast
-
.MoveFirst
-
-
While (Not .EOF)
-
-
With CodeContextObject
-
-
DoCmd.OpenReport "rptFinalCPExport", acViewPreview, "", "[Part Number]=[Forms]![Web Bruce]![Part]"
-
DoCmd.OutputTo acOutputReport, "rptFinalCPExport", "PDFFormat(*.pdf)", Forms![Web Bruce]![Web Output], False, "", , acExportQualityPrint
-
DoCmd.SetWarnings False
-
DoCmd.Close acReport, "rptFinalCPExport"
-
DoCmd.SetWarnings True
-
DoCmd.GoToRecord acForm, "Web Bruce", acNext
-
-
End With
-
.MoveNext
-
Wend
-
End If
-
End With
-
-
-
Proc_err:
-
-
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
-
Error:
-
-
Select Case Err.Number
-
Case 2501: 'Cancel button error
-
GoTo Cancel_Error
-
Case 2105:
-
GoTo exitsub
-
Case 0
-
GoTo exitsub
-
Case 20
-
GoTo exitsub
-
-
End Select
-
-
Cancel_Error: 'What you need the handler to do
-
Err.Clear
-
Resume Next
-
exitsub:
-
Set rs = Nothing
-
Set db = Nothing
-
DoCmd.SetWarnings True
-
Exit Sub
-
-
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
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 .
Thanks NeoPa. That's what I needed. I even cleaned up the code some more. Here is what it looks like now. No errors. - Private Sub ExportCP_Click()
-
-
On Error GoTo Error
-
-
Dim strSQL As String
-
Dim rs As DAO.Recordset
-
-
DoCmd.OpenForm "Web Bruce", acNormal, "CP_FEMA_PF_OutPut-QRY"
-
-
strSQL = "CP_FEMA_PF_OutPut"
-
-
Set rs = CurrentDb.OpenRecordset(strSQL)
-
-
If Not (rs.BOF And Not rs.EOF) Then
-
rs.MoveFirst
-
Do Until rs.EOF
-
-
DoCmd.OpenReport "rptFinalCPExport", acViewPreview, "", "[Part Number]=[Forms]![Web Bruce]![Part]"
-
DoCmd.OutputTo acOutputReport, "rptFinalCPExport", "PDFFormat(*.pdf)", Forms![Web Bruce]![Web Output], False, "", , acExportQualityPrint
-
DoCmd.SetWarnings False
-
DoCmd.Close acReport, "rptFinalCPExport"
-
DoCmd.SetWarnings True
-
DoCmd.GoToRecord acForm, "Web Bruce", acNext
-
-
rs.MoveNext
-
Loop
-
-
End If
-
-
Error:
-
Select Case Err.Number
-
Case 2501: 'Cancel button error
-
GoTo Cancel_Error
-
Case 2105:
-
GoTo exitsub
-
Case 0
-
GoTo exitsub
-
Case 20
-
GoTo exitsub
-
-
End Select
-
-
Cancel_Error: 'What you need the handler to do
-
Err.Clear
-
Resume Next
-
exitsub:
-
rs.Close
-
Set rs = Nothing
-
DoCmd.SetWarnings True
-
Exit Sub
-
-
End Sub
NeoPa 32,547
Expert Mod 16PB
Always a pleasure Rhino :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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 =...
|
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
|
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...
|
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")
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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 :...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |