Can't Find Object

C

Chuck

A97

One of the outputs of a club database is a pdf report using the CutePDF Writer.
After the report is saved to the hard drive I use a macro to change the report
name - or at least I used to. I haven't used the database for over a year.
Today I opened the database and ran the report. The report printed the pdf file
correctly and was saved to the correct folder with the correct name,
E:\Data\Access\Club\Directory.pdf. The pdf file can be opened with Acrobat
reader. Then I ran the macro to change the name. An error message came up
saying: "The Microsoft Jet database engine could not find the object
"'E:\Data\Access\Club\Directory.pdf'" The path, name, and spelling are all
correct. The last time I used the database the Jet engine could find object
and renamed it correctly. Obviously something has changed, but what?

Macro:
Rename
New Name: "E:\Data\Access\Club\Directory" & " " &_
format(date(),"yymmdd") & ".pdf"
Object Type: Report
Old Name: "E:\Data\Access\Club\Directory.pdf"

All suggestions will be greatly appreciated.

Chuck
 
R

Rob Parker

Hi Chuck,

I never use macros, so I may be wrong, but I don't think that you can rename
anything other than an object within the database via the Rename action
within a macro. You are trying to rename an external file, and I don't
believe that the Rename action is capable of doing that; certainly, when I
look at the list of Object Types in the drop-down, I only see database
objects available there. It could be done via VBA code, but that's another
story.

What probably would work is to rename the Report object within the database
(presumable named Directory) before you run it and generate the .pdf file.
Set the Old Name to the current name of the report object in your database,
and the New Name to that name and your date concatenation string. For
example:
Old Name: "Directory"
New Name: "Directory" & " " & format(date(),"yymmdd")

You might want another macro to rename the report to the old name after it's
run, so that your macro will work when run again. Or, alternatively, get
your macro to copy the report to the new name, run it, then delete the
newly-named report.

HTH,

Rob
 
B

Brian

I'm not sure how it ever worked to start with - the Rename action applies
only to database objects (i.e. reports, tables, forms, etc. in Access), not
to objects outside Access, such as the file. Maybe it was different in Access
97 (I did not start using Access until 2000).

I think this is a candidate for the following bit of VBA code instead, using
the Name function:

Name "E:\Data\Access\Club\Directory.pdf" As "E:\Data\Access\Club\Directory"
& " " & Format(date(),"yymmdd") & ".pdf"

You could make a button, and put that code in its Click event.
 
C

Chuck

Hi Chuck,

I never use macros, so I may be wrong, but I don't think that you can rename
anything other than an object within the database via the Rename action
within a macro. You are trying to rename an external file, and I don't
believe that the Rename action is capable of doing that; certainly, when I
look at the list of Object Types in the drop-down, I only see database
objects available there. It could be done via VBA code, but that's another
story.

What probably would work is to rename the Report object within the database
(presumable named Directory) before you run it and generate the .pdf file.
Set the Old Name to the current name of the report object in your database,
and the New Name to that name and your date concatenation string. For
example:
Old Name: "Directory"
New Name: "Directory" & " " & format(date(),"yymmdd")

You might want another macro to rename the report to the old name after it's
run, so that your macro will work when run again. Or, alternatively, get
your macro to copy the report to the new name, run it, then delete the
newly-named report.

HTH,

Rob
Thanks Rob. My memory isn't what it was, but I was sure that I ran that macro
once a month for 3 years. I put out 5 reports each month. They were run from
one macro that called 5 other macros plus the rename macro. Anyhow, the help
files are telling me exactly what you are telling me. I looked to see if I had
any modules any where, but didn't find any. Haven't checked for any event
procedures yet. Will let you know what I finally settle for.

Chuck
 
C

Chuck

I'm not sure how it ever worked to start with - the Rename action applies
only to database objects (i.e. reports, tables, forms, etc. in Access), not
to objects outside Access, such as the file. Maybe it was different in Access
97 (I did not start using Access until 2000).

I think this is a candidate for the following bit of VBA code instead, using
the Name function:

Name "E:\Data\Access\Club\Directory.pdf" As "E:\Data\Access\Club\Directory"
& " " & Format(date(),"yymmdd") & ".pdf"

You could make a button, and put that code in its Click event.

I vaguely remember the Name function, but couldn't find any place where I used
it. Probably would have been in an event procedure. I'll check for those.

Chuck
 
C

Chuck

A97

One of the outputs of a club database is a pdf report using the CutePDF Writer.
After the report is saved to the hard drive I use a macro to change the report
name - or at least I used to. I haven't used the database for over a year.
Today I opened the database and ran the report. The report printed the pdf file
correctly and was saved to the correct folder with the correct name,
E:\Data\Access\Club\Directory.pdf. The pdf file can be opened with Acrobat
reader. Then I ran the macro to change the name. An error message came up
saying: "The Microsoft Jet database engine could not find the object
"'E:\Data\Access\Club\Directory.pdf'" The path, name, and spelling are all
correct. The last time I used the database the Jet engine could find object
and renamed it correctly. Obviously something has changed, but what?

Macro:
Rename
New Name: "E:\Data\Access\Club\Directory" & " " &_
format(date(),"yymmdd") & ".pdf"
Object Type: Report
Old Name: "E:\Data\Access\Club\Directory.pdf"

All suggestions will be greatly appreciated.

Chuck
Found my problem. I was running the wrong report! That's what happens when
you don't clean things up. The correct report has the code suggested by Brian
in the On Close event and works as expected.

Thanks for your help Rob and Brian.
 
C

Chuck

Found my problem. I was running the wrong report! That's what happens when
you don't clean things up. The correct report has the code suggested by Brian
in the On Close event and works as expected.

Thanks for your help Rob and Brian.
Not so fast!!! If the report is opened in Print Preview than click on Print
than after printing close the report it works fine. If the report is run from
a macro, the name does not get changed.

I've been opening the MDB file then going either to the macros or reports tab
and running from there. The MDB file has a form named Menu. It's like a
switch board. It opens maximized when the MDB file opens. There is nothing
there but command buttons. One button's caption is "Run monthly reports" which
includes a Directory report that does not have an On Close event. The caption
of a command button directly below Run monthly reports button is "Add date to
PDF file". The on click event is exactly as Brian gave in his reply. If I
had just used the MDB file as I originally intended, I would never had the
problem.

Thanks all

Chuck
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top