Exporting with VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I use a macro to export files to excel. No problem here, but I'd like to
use file names dependent on variables in the form. One variable is the team's
name "First" another variable is year "2004". My preferred export file name
is then export_First_2004. How can I arrange this?
Hans
 
Hans,

In the File Name argument of your TransferSpreadsheet macro, you would
put an expression to construct the file path/name according to your
requirements. The specifics of this will depend on where the program is
supposed to find the team name and year.
 
Steve, on the main form I have two combo's, in one I can choose the team and
in the other combo the year. So one is called Forms![StatsTeamYear]![Team]
and the other Forms![StatsTeamYear]![Year]. But what now?
Hans
 
Hans,

Ok, so the File Name is like this...
="C:\YourFolder\export_" & [Forms]![StatsTeamYear]![Team] & "_" &
[Forms]![StatsTeamYear]![Year] & ".xls"

I am pretty sure that if the macro is being triggered via an event on
the StatsTeamYear form, you don't need the full reference, in other
words the macro argument expression could be like...
="C:\YourFolder\export_" & [Team] & "_" & [Year] & ".xls"

By the way, as an aside, 'year' is a Reserved Word in Access, and as
such should not really bve used as the name of a field or control or
database object.
 
Back
Top