473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Rename an external file

Problem: to rename a file sent to a PDF writer

A macro opens a report in print mode
the printer is a pdf writer
The report name is: "Directory.pdf"
The desired name is: "Directory " & (format(Date(),"yymmdd")) & ",pdf"
So that the file name becomes: "Directory 050126.pdf"

I have tried the NAME {oldfilename} AS {newfilename} as an event procedure In:
On Close and On Deactivate.

Both produce errors because the program is trying to rename the file before the
file print process is complete and therefore the file does not exist at the
time it is trying to be renamed.

All suggestions will be gratefully received.

Chuck
---

Nov 13 '05 #1
7 2659
Rog
I haven't tried this but you could loop until the pdf file exists,
something like:

do until Len(Dir("c:\...\directory.pdf") <> 0
loop

but give it a maximum number of loops in case something goes wrong and
the file cannot be created.

Nov 13 '05 #2
Rog wrote:
I haven't tried this but you could loop until the pdf file exists,
something like:

do until Len(Dir("c:\...\directory.pdf") <> 0
loop

but give it a maximum number of loops in case something goes wrong and
the file cannot be created.

And throw in a DoEvents statement in that loop so that Access (rather,
VBA) yields to the CPU so that the OS so that it can actually do the
file writes.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #3
On Thu, 27 Jan 2005 23:39:15 -0600, John Mishefske <mi************@JUNKtds.net>
wrote:
Rog wrote:
I haven't tried this but you could loop until the pdf file exists,
something like:

do until Len(Dir("c:\...\directory.pdf") <> 0
loop

but give it a maximum number of loops in case something goes wrong and
the file cannot be created.

And throw in a DoEvents statement in that loop so that Access (rather,
VBA) yields to the CPU so that the OS so that it can actually do the
file writes.


Thanks Rog and John.

I did the 'do until loop' with out a counter to prevent endless looping in the
OnClose event of the report.
The pdf file is going to exist - eventually.
Apparently, as soon as the report starts to print to the pdf printer, the
report closes. There's no close command in the macro that opens the report.
And the private sub stops even thou it has not found the pdf file.

I'm not a code writer and do not understand the DoEvents function. After
looking at the help file and the example it would appear that the DoEvents is
never going to happen anyhow because the report with the code will be closed.

A not very clean work around is to open then close an unrelated report with the
code, with out the loop, after the pdf file has been saved.

Code:
Private Sub Report_Close()
Do Until Len(Dir("e:\MyData\Directory.pdf")) <> 0
Name "e:\MyData\ Directory.pdf" As "e:\MyData\ Directory " &
(Format(Date, "yymmdd" & ".pdf"))
Loop
End Sub

Chuck
---

Nov 13 '05 #4
DoEvents gives up control to the Windows to allow other events ("things") to
happen. I don't know what your expectation was, but the purpose of that
suggestion was to allow the user to take any kind of manual action to
interrupt the running of the code if you happened to make a small mistake
that put it into a never-ending loop.

Yep, Windows _IS_ supposed to have pre-emptive multitasking, but -- trust
us, you nee the DoEvents!

Larry Linson
Microsoft Access MVP

"Chuck" <li*****@schoollink.net> wrote in message
news:3m********************************@4ax.com...
On Thu, 27 Jan 2005 23:39:15 -0600, John Mishefske <mi************@JUNKtds.net> wrote:
Rog wrote:
I haven't tried this but you could loop until the pdf file exists,
something like:

do until Len(Dir("c:\...\directory.pdf") <> 0
loop

but give it a maximum number of loops in case something goes wrong and
the file cannot be created.
And throw in a DoEvents statement in that loop so that Access (rather,
VBA) yields to the CPU so that the OS so that it can actually do the
file writes.


Thanks Rog and John.

I did the 'do until loop' with out a counter to prevent endless looping in

the OnClose event of the report.
The pdf file is going to exist - eventually.
Apparently, as soon as the report starts to print to the pdf printer, the
report closes. There's no close command in the macro that opens the report. And the private sub stops even thou it has not found the pdf file.

I'm not a code writer and do not understand the DoEvents function. After
looking at the help file and the example it would appear that the DoEvents is never going to happen anyhow because the report with the code will be closed.
A not very clean work around is to open then close an unrelated report with the code, with out the loop, after the pdf file has been saved.

Code:
Private Sub Report_Close()
Do Until Len(Dir("e:\MyData\Directory.pdf")) <> 0
Name "e:\MyData\ Directory.pdf" As "e:\MyData\ Directory " &
(Format(Date, "yymmdd" & ".pdf"))
Loop
End Sub

Chuck
---

Nov 13 '05 #5
Larry Linson wrote:
DoEvents gives up control to the Windows to allow other events ("things") to
happen. I don't know what your expectation was, but the purpose of that
suggestion was to allow the user to take any kind of manual action to
interrupt the running of the code if you happened to make a small mistake
that put it into a never-ending loop.

Yep, Windows _IS_ supposed to have pre-emptive multitasking, but -- trust
us, you nee the DoEvents!


Even if Windows' multitasking was as good as Linux's, it would still be
a good idea to use it. This would allow your own application to process
messages, e.g. using a cancel button within a loop, without DoEvents you
could never hit that button.

--
This sig left intentionally blank
Nov 13 '05 #6
Rog, would looping like this work if a file is created as soon as PDF
writer starts spittting it out? IE, the file starts to exist before
it's been completely written.

Nov 13 '05 #7
On Sun, 30 Jan 2005 13:02:42 +0000, Trevor Best <no****@besty.org.uk> wrote:
Larry Linson wrote:
DoEvents gives up control to the Windows to allow other events ("things") to
happen. I don't know what your expectation was, but the purpose of that
suggestion was to allow the user to take any kind of manual action to
interrupt the running of the code if you happened to make a small mistake
that put it into a never-ending loop.

Yep, Windows _IS_ supposed to have pre-emptive multitasking, but -- trust
us, you nee the DoEvents!


Even if Windows' multitasking was as good as Linux's, it would still be
a good idea to use it. This would allow your own application to process
messages, e.g. using a cancel button within a loop, without DoEvents you
could never hit that button.


Thanks to all who tried to help. Unfortunately I don't undrestand what you all
are telling me. I have put the event procedure in an unrelated report that is
manually opened and closed after the pdf file is printer. Awkward, but
liveable.

Chuck
---

Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tom | last post by:
I'm having a problem using a path with spaces as a parameter to os.rename() in a program on WinXP. This works fine at the command line (where the folder "c:\aa bb" exists) > os.rename( "c\aa...
5
by: jez123456 | last post by:
Hi, I’ve written a c# program to compact certain msaccess databases. The way this works is to compact say C:\test1.mdb to C:\temp.mdb, then delete C:\test1.mdb and rename C:\temp.mdb as...
1
by: Jay at SCA | last post by:
I've been having the following issue with a windows service I've created in vb.net (.net fw 1.1): Basically, my service monitors a folder for the creation of any new files of a particular type...
2
by: Bruce Russell | last post by:
This may sound stupid but I can't rename the WebForm1.aspx in the solution explorer. The file is located in my local web server at C:\Inetpub\wwwroot\Lab3-VB-Starter\WebForm1.aspx Is there...
5
by: Tony Meyer | last post by:
On Windows, if I do os.rename(old, new) where old is a file that is in-use (e.g. python itself, or a dll that is loaded), I would expect that an error would be raised (e.g. as when os.remove is...
12
by: mantrid | last post by:
Im trying to move a file but am having luck my code is below. The temp and target paths are valid as they echo correctly. but I cant get the copy() function to work, or the rename() function ...
1
by: spacehopper_man | last post by:
no "rename" operation in C# !!! - this has been covered in this group before, but I can't find any good answers. what I am trying to do is refresh the content in a file with minimum...
2
by: =?iso-8859-1?b?cultaQ==?= | last post by:
Hi, I would like to rename files (jpg's ones) using a text file containing the new names... Below is the code that doesn't work : ***** #!/usr/bin/python #-*- coding: utf-8 -*- from os...
3
by: robboll | last post by:
I am working on a form where one of the checkboxes asks if there is a document associated with the record? If you user clicks to check it (i.e., "Yes"), I would like these events to occur: 1. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.