472,133 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Stephen Lebans' ReportUtilities - error in my adaption

I am trying to adapt Lebans' ReportUtilities to export reports (to
preserve formatting) from an Access 97 application. I have made the
reference to his mde and copied the modules into my db. I have
created a custom toolbar with a custom control, "Export to File". In
the On Action property (of the export control) I inserted the code
"pf.ExportToMSWord rptApplicantReferral" which I had copied from his
sample db except for the name of my report. When I run the report and
attempt to export it I receive the error "...can't run the macro or
callback function 'pf.ExportToMSWord rptApplicantReferral'. Make sure
the macro or function exists and takes the correct parameters." I was
trying to get just one report exporting before trying to code the
toolbar control to respond to whatever report was open at the time. I
would appreciate any assistance in figuring out how to code this such
that the user could from the PrintPreview mode of the report choose to
print a hardcopy or export it to a Word document.

Thanks,
Alex
Nov 12 '05 #1
3 2424
You cannot call a method of a Class as you are trying to do from the On
Action prop. Insteaad create a function that:

Creates the instance of the ReportUtilites class
Calls the ExportToMSWord method
Deletes the instance of the ReportUtilities class

Basically, all of the setup code you see behind the sample form you need
to palce behind a Public function contained within a standard Code
module(not a Form's class module!)

Le tme know how you make out. I would like to post the finished code to
my site as it is a good idea.
:-)
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Alex Wisnoski" <Al***********@ncmail.net> wrote in message
news:5c**************************@posting.google.c om...
I am trying to adapt Lebans' ReportUtilities to export reports (to
preserve formatting) from an Access 97 application. I have made the
reference to his mde and copied the modules into my db. I have
created a custom toolbar with a custom control, "Export to File". In
the On Action property (of the export control) I inserted the code
"pf.ExportToMSWord rptApplicantReferral" which I had copied from his
sample db except for the name of my report. When I run the report and
attempt to export it I receive the error "...can't run the macro or
callback function 'pf.ExportToMSWord rptApplicantReferral'. Make sure
the macro or function exists and takes the correct parameters." I was
trying to get just one report exporting before trying to code the
toolbar control to respond to whatever report was open at the time. I
would appreciate any assistance in figuring out how to code this such
that the user could from the PrintPreview mode of the report choose to
print a hardcopy or export it to a Word document.

Thanks,
Alex


Nov 12 '05 #2
Thank you for your quick response to my request for help. I did like
you said and created the following function:
Function Exporttofile()
Set pf = New clsPrintToFit
pf.ExportToMSWord stDocName
Set pf = Nothing
End Function
I set the OnAction property of my Export control to the function
"=Exporttofile()". After running my test report, I clicked on my
Export control and everything seemed to work fine; I was prompted for
a name and location of the file to be saved. When I opened the saved
file the data was there but all the lines that separate the fields and
records were absent. I knew I must be leaving out some of your key
code so I looked back thru your sample and saw the lines in the report
dealing with the class clsPrintLines. I inserted those lines in my
report but began getting "Compile error: User-defined type not
defined." on the variable "pl =" in the phrase "Set pl =". Here is my
code:

Option Compare Database
Option Explicit
Dim strPriority As String
' Stephen Lebans
' Copyright Lebans Holdings 1999 Ltd.
' St*****@lebans.com
' www.lebans.com
' Declare an object of Type PrintLine Class
Dim pl As clsPrintLines

Private Sub Report_Close()
' Cleanup Stephen Lebans
Set pl = Nothing
DoCmd.Close acForm, "frmPositionNumDialog", acSaveNo
End Sub

Private Sub Report_Open(Cancel As Integer)
' Create the instance of our Class Stephen Lebans
Set pl = New clsPrintLines
' Init the Class Stephen Lebans
pl.InitSections Me

' For Demonstration purposes Stephen Lebans
' Turn on Borders and Vertical Lines
' for every Section on the Report.
pl.ResetToDefaults

DoCmd.Maximize
End Sub

I do have the module "clsPrintLines" in the database and the variable
pl is defined in the approriate location. Would you have any
suggestions as to what is causing this?
Thank you for your help,
Alex
"Stephen Lebans" <Fo****************************************@linval id.com> wrote in message news:<Ke*********************@ursa-nb00s0.nbnet.nb.ca>...
You cannot call a method of a Class as you are trying to do from the On
Action prop. Insteaad create a function that:

Creates the instance of the ReportUtilites class
Calls the ExportToMSWord method
Deletes the instance of the ReportUtilities class

Basically, all of the setup code you see behind the sample form you need
to palce behind a Public function contained within a standard Code
module(not a Form's class module!)

Le tme know how you make out. I would like to post the finished code to
my site as it is a good idea.
:-)
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Alex Wisnoski" <Al***********@ncmail.net> wrote in message
news:5c**************************@posting.google.c om...
I am trying to adapt Lebans' ReportUtilities to export reports (to
preserve formatting) from an Access 97 application. I have made the
reference to his mde and copied the modules into my db. I have
created a custom toolbar with a custom control, "Export to File". In
the On Action property (of the export control) I inserted the code
"pf.ExportToMSWord rptApplicantReferral" which I had copied from his
sample db except for the name of my report. When I run the report and
attempt to export it I receive the error "...can't run the macro or
callback function 'pf.ExportToMSWord rptApplicantReferral'. Make sure
the macro or function exists and takes the correct parameters." I was
trying to get just one report exporting before trying to code the
toolbar control to respond to whatever report was open at the time. I
would appreciate any assistance in figuring out how to code this such
that the user could from the PrintPreview mode of the report choose to
print a hardcopy or export it to a Word document.

Thanks,
Alex

Nov 12 '05 #3
On 6 May 2004 08:30:54 -0700, Al***********@ncmail.net (Alex Wisnoski) wrote:

It is mentioned in Stephen's notes that come with ReportUtilities that due to a bug in Access, lines will not export correctly. Replace all your
straight lines with rectangles set to 0 height and they will export and display correctly.

Thank you for your quick response to my request for help. I did like
you said and created the following function:
Function Exporttofile()
Set pf = New clsPrintToFit
pf.ExportToMSWord stDocName
Set pf = Nothing
End Function
I set the OnAction property of my Export control to the function
"=Exporttofile()". After running my test report, I clicked on my
Export control and everything seemed to work fine; I was prompted for
a name and location of the file to be saved. When I opened the saved
file the data was there but all the lines that separate the fields and
records were absent.

Wayne Gillespie
Gosford NSW Australia
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Patrick | last post: by
1 post views Thread by ChrisR | last post: by
reply views Thread by leo001 | last post: by

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.