- 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
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 .
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,556
Recognized Expert Moderator MVP
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: 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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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: 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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |