openfile with date in the filename (1 Viewer)

miketamp

Registered User.
Local time
Today, 13:29
Joined
Mar 30, 2005
Messages
22
:confused:
hi there
i use this code to copy a file from a source folder to the destination folder.



Code:
Dim myfolder$, myfoldertarget

myfolder = "C:\source\"
myfoldertarget = "c:\target\"

Dim fs As Object
Set fs = CreateObject("scripting.filesystemobject")
fs.CopyFile (myfolder) & [Mylistbox], [myfoldertarget] & Left([Mylistbox], Len([Mylistbox]) - 4) & Format(now, "DD-MM-YYYY") & ".doc", True

[Mylistbox] is a list in the form where the file name apears.

for example if the filename in the "mylistbox" is test
after the copy the file must be "test10-01-2006.doc" in the c:\target\ folder.

the problem is that after the copy i need an openfile command to execute the new filename.Something like openifle test10-01-2006.doc. but for the file that the last command has create and only for that file.

please help me
thanx...
 

Summerwind

Registered User.
Local time
Today, 13:29
Joined
Aug 25, 2005
Messages
91
Hi Mike

Assuming that your newly created file is an MS Word file, you need to create an instance of Word, then open the file using "Automation."

If you can't find any help on that, come back and I will post some code for you (Or some other kind soul will ;-)
 

miketamp

Registered User.
Local time
Today, 13:29
Joined
Mar 30, 2005
Messages
22
Hi Summerwind
first of all thanks for the reply
can you please post me the code to do that because i don't know exactly what you mean.
thanx...
 

Summerwind

Registered User.
Local time
Today, 13:29
Joined
Aug 25, 2005
Messages
91
Create an Instance of Word

OK, The code goes something like this:

Dim WordDoc As Word.Application

Set WordDoc = CreateObject("Word.Application")
With WordDoc
.Visible = True
.Documents.Open (NameOfYourNewFileAsAString)

Do Stuff

.Quit
End With

Set WordDoc = Nothing

Don't forget to set Word in your References.

Hope that helps.

(Sorry I don't know how to put the code in a fancy window. Maybe I need some ICT lessons :)
 

ghudson

Registered User.
Local time
Today, 16:29
Joined
Jun 8, 2002
Messages
6,195
Searching the forum is a great way to discover and learn the answers to your Access programming questions.

Besides using Automation, there are other ways to open a file. I prefer the OpenFile method I use in my Browse [Find a directory or file] sample.
 

miketamp

Registered User.
Local time
Today, 13:29
Joined
Mar 30, 2005
Messages
22
help....

If you look my example you will understand what I am looking for.
It’s not a specific file that I need to open. Every time a file copied from the source folder to the destination folder, the program add's to the filename the current date. After that the program must run the file that has created before (filename with current date).
So I can't use the code that Summerwind give me because in the ".Documents.Open (NameOfYourNewFileAsAString)" I have to replace the (NameOfYourNewFileAsAString) with the file name which I don't know. I also prefer the openfile command but how can I do that?
Please I need help for that.

If you can give me some code......
 

ghudson

Registered User.
Local time
Today, 16:29
Joined
Jun 8, 2002
Messages
6,195
Your file name is the string you are building with the...
[myfoldertarget] & Left([Mylistbox], Len([Mylistbox]) - 4) & Format(now, "DD-MM-YYYY") & ".doc",

I suggest that you define it, like this...
Dim myFile as String
myFile = myFolderTarget & Left([Mylistbox], Len([Mylistbox]) - 4) & Format(now, "DD-MM-YYYY") & ".doc"

Then you can reference the myFile string to open the file using the OpenFile code I have in my db.

Also, you have not correctly dim'd your strings. Something like this is better...

Dim myFolder as String, myFolderTarget as String, myFile as String

myFolder = "C:\source\"
myFolderTarget = "c:\target\"
myFile = myFolderTarget & Left([Mylistbox], Len([Mylistbox]) - 4) & Format(now, "DD-MM-YYYY") & ".doc"
 

Summerwind

Registered User.
Local time
Today, 13:29
Joined
Aug 25, 2005
Messages
91
Just a second

Surely the name of the file that you have just created and the one you are trying to open includes the date that you've attached to the original filename, doesn't it?????:eek:

Therefore you wouldn't need to trim off the additional date. The file you are trying to open is refered to in the code I sent by the name you have just created in code. It's already in a string format so can be inserted straight into the openfile clause, can't it?????:)

It is completely irrelevant what the name of the file is because your code is holding the string variable of the name you have just created. You don't need to hard code the file name , just use the string variable you created when you saved the re-named file.;)
 

Users who are viewing this thread

Top Bottom