I have little experience with Access other than trial and error changes and forums like this helping me out.
Original owner of our company taught me a few things many years ago but he has since passed away so here I am.
This section of code works fine on Office 365 32 bit but will not function on a 64 bit version. I'd like to change that.
The Dim intLoop and intx statements used to be "Integer". I've changed them to "Long" and it does not correct the issue.
Any help would be greatly appreciated.
Original owner of our company taught me a few things many years ago but he has since passed away so here I am.
This section of code works fine on Office 365 32 bit but will not function on a 64 bit version. I'd like to change that.
The Dim intLoop and intx statements used to be "Integer". I've changed them to "Long" and it does not correct the issue.
Any help would be greatly appreciated.
Code:
Public Function CreatePDF(Optional strCalling As String)
'************************************************************
'Date Last Modified: 07/18/07
'Purpose: Loop through xtblRptInv for email custs and create PDFs from rptInv
'Requires: Bullzip PDF Printer, and setting of printer directory to conOutDir & rptInv.pdf
'Also set confirms etc to no and never.
'Double Click icon to set printer properties.
'Called By: Tasks cmdEMAILBatch, ReLoadInvoice("ReEmail")and ReprintBatch this is the only one that uses strCalling
'************************************************************
Dim db As Database
Dim rsMailingList As Recordset
Dim strDefPrn As String, strPDFPrn As String, strFile As String, strSQL As String
Dim prnPDF As Printer
Dim prnDef As Printer
Dim intLoop As Long
Dim varRet As Variant
Dim intx As Long
Set db = CurrentDb
'Dim sw As New StopWatch
'Set sw = New StopWatch
'in case of failure there will be files created in previous run
On Error Resume Next
Kill conOutDir & "*.*"
On Error GoTo ErrorHandler:
'get the current msaccess default printer, so can reset
strDefPrn = Application.Printer.DeviceName
'check if this printer name is in printers collection
strPDFPrn = "Bullzip PDF Printer"
'error if not
Set prnPDF = Application.Printers(strPDFPrn)
'set the msaccess printer to the PDF printer
Set Application.Printer = Application.Printers(strPDFPrn)
'cmdEmailBatch calls with no parameter, and RePrintBatch if answer yes to Email?
If strCalling = "" Then
'set rptInv record source to email qry (only difference is parameter custno and InvByEmail = True)
DoCmd.OpenReport "rptInv", acViewDesign, , , acHidden
Reports("rptInv").RecordSource = "qryInvRptEmail"
DoCmd.Close acReport, "rptInv", acSaveYes
strSQL = MailList(True) 'limit to only EmailByInvoice
Else
'single coming from frmPopInvoices called with ReLoad as parameter was stopped there if no email address
DoCmd.OpenReport "rptInv", acViewDesign, , , acHidden
Reports("rptInv").RecordSource = "qryInvRpt0"
DoCmd.Close acReport, "rptInv", acSaveYes
strSQL = MailList(False) 'not limited as above, only needs an email address, not InvByEmail
End If
Set rsMailingList = db.OpenRecordset(strSQL)
With rsMailingList
.MoveLast
.MoveFirst
'set the max meter value to record count
varRet = SysCmd(acSysCmdInitMeter, "Creating PDF files from Invoice ", .RecordCount)
DoCmd.OpenForm "frmEInv", , , , , acHidden
intLoop = 1
Do Until .EOF
varRet = SysCmd(acSysCmdUpdateMeter, intLoop)
intLoop = intLoop + 1
'provides parameter to qryInvRptEmail so report creates that pdf (no effect on reloadinvoice call)
Forms!frmEInv!txtCustno = !CUSTNO
'recordsource will be qryInvByEmail or qryInvRpt0
'creates file in conOutDir (VoiceMailInvoice.pdf) since printer is now pdf printer and printer is set to dir and fname
DoCmd.OpenReport "rptInv", , , , acHidden
strFile = "INV" & !InvNo & ".pdf" 'desired new name INVxxxx-xxxxx.pdf
'rename the file this fails with err.number=53 see errorhandler. Creation of rpt.pdf
'takes a really variable time. So just loop with resume on error.
'sw.StartTimer 'about 14 secs first loop then 4 secs each succeding
'intx = 0
Call ReNamePDF(strFile)
'Name conOutDir & "rpt.pdf" As conOutDir & strFile 'ie c:\CurlewFiles\OutEFiles\INVxxxxx-xxxxx.pdf
'Debug.Print sw.ElapsedTime
'Debug.Print strFile
'Debug.Print !Email
'Call SendEmail(!Email, conOutDir & "VoiceMailInvoice.pdf")
Call SendEmail(!Email, conOutDir & strFile)
'Kill conOutDir & "VoiceMailInvoice.pdf"
Kill conOutDir & strFile
.MoveNext
Loop
End With 'rsMailingList
''->If strCalling = "" Then
'Call FillArrayEmail
'Else
'Call FillArrayEmail("ReLoad")
'End If
varRet = SysCmd(acSysCmdClearStatus)
Exit_CreatePDF:
'reset all back to original state
DoCmd.OpenReport "rptInv", acViewDesign, , , acHidden
Reports("rptInv").RecordSource = "qryInvRpt"
DoCmd.Close acReport, "rptInv", acSaveYes
Set prnDef = Application.Printers(strDefPrn)
Set Application.Printer = Application.Printers(strDefPrn)
DoCmd.Close acForm, "frmEInv"
Exit Function
ErrorHandler:
Select Case Err.Number
Case 53, 75 ' file not found. Occurs at "Name conPDFDir " 75 is no access to dir
'loop until PDF creation is finished, resume starts again with line that caused error
intx = intx + 0
Resume
Case Else
basUtilities.ErrorHandler "basEmail", "CreatePDF"
Resume Exit_CreatePDF
End Select
End Function
Last edited: