Export File Title

  • Thread starter Thread starter LJG
  • Start date Start date
L

LJG

Hi Guys,

I run a qry that creates a excel export file and I need to include fields of
data to title the file it creates, is this possible?

I currently do this by adding a date format:

"C:\database\dataexport\Appointments\folder_x" & "_" & Format(Now(),
"dd_mmmm_yyyy, hh.nn") & ".xls"

With a change in policy I need to add other elements that are included in
the query that creates each excel file:

UserName
ContactID

UserName will be used to identify 'folder_x' to make sure each file is saved
in the correct folder
ContactID will be included in the file tile to provide naming uniqueness
i.e:

"C:\database\dataexport\Appointments\JohnSmith"&"_"&ContactID& "_" &
Format(Now(), "dd_mmmm_yyyy, hh.nn") & ".xls"

TIA
 
Dear LJ:

So, what's the problem? You seem to have avoided using any illegal
characters in the file names, assuming the variable ContactID doesn't
contain any. You might want to pay some attention to how the directory will
sort. Month names don't sort well. A YY-MM-DD format works well for me.
Also, do you want the names to sort by date or by ContactID? Perhaps date
would come first. Just something to think about.

Also, you must make sure the folder already exists. I use a function that
creates all the folders along the chain if they don't already exist.
Otherwise you must make sure to create them when you install, and even then
this risks having some user remove or rename them.

I also use a function that replaces any illegal characters in file names. A
%XX format where XX are the hex digits of any illegal character is common.
If the ContactID or the UserName are user supplied, and if you don't limit
these values to have only legal file-name characters, then you must decide
what to do and program for that.

Tom Ellison
 
Back
Top