View Single Post
  #3  
Old July 11th, 2004, 08:44 PM
Jeff Conrad
external usenet poster
 
Posts: n/a
Default Save Report With CreateReport Coding Issue

Hi Doug!

Thanks for the assistance.
I thought it would be that easy as well, but that code produces error 2135.
Further checking of the Help files reveal that the Name property is Read
Only in all views.
Grrrr.....

I have a work-around by saving the report with the default name and then
renaming it.
It's a little weird, but it seems to work just fine in my tests.
What do you think?:

(strOldReportName is Dimmed as string)

' Remember the name of the report that Access has given it
strOldReportName = rpt.Name

' Close and save the report with the given name with no prompt for user
DoCmd.Close acReport, rpt.Name, acSaveYes
' Refresh the database window to reflect the change
RefreshDatabaseWindow

' Now rename the report we just created to the name we want
DoCmd.Rename "rptNewName", acReport, strOldReportName
' Refresh the database window to reflect the change
RefreshDatabaseWindow

' All finished now so open the report in Preview mode
' Maximize the report and have it fill the whole screen
DoCmd.OpenReport "rptNewName", acViewPreview
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow

Do you think this is OK?
Seems to be just fine in testing.

--
Jeff Conrad
Access Junkie
Bend, Oregon


"Douglas J. Steele" wrote in message
...
Haven't bothered to test, but you should be able to do something like:

Set rpt = CreateReport
rpt.Name = "rptMyNameHere"

' put the rest of your code here

DoCmd.Close acReport, rpt.Name, acSaveYes

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Jeff Conrad" wrote in message
...
Hi,

Using Access 97 at the moment.
After building a report in code using CreateReport and

CreateReportControl
coding I wish to save the report without being prompted for the name.

Fine
enough I can do that by using code like this at the end:

DoCmd.Close acReport, rpt.Name, acSaveYes

But, how do I save the report with a name of my choosing without being
prompted?
Right now it saves it as Report1 or Report2, etc.
I have already assigned a caption for the report so I assumed it would

save
the report with that name. I was incorrect.
If I try something like this:

DoCmd.Close acReport, "rptMyNameHere", acSaveYes

Access says it can't find that report.
Is this not possible to do?

Do I have to save the report with the default name and then rename it in
code?

Thanks,
--
Jeff Conrad
Access Junkie
Bend, Oregon