I have the following query defined
SELECT TimeAnalysisControlTable.ControlInfo,
TimeAnalysisControlTable.ControlID
FROM TimeAnalysisControlTable
WHERE (((TimeAnalysisControlTable.ControlID)="ReportDirectory"));
and it is called "Query - Get Report Directory"
And one that is similar that gets the master directory.
========================================
In my vba module I have a createanalysis function: it deletes the
output report if it happens to have already been run so that it can be
replaced by a more recent version. I then copy a master that has some
special formating etc. and then export into that copy.
function CreateAnalysis()
MasterDir = DLookup("[ControlInfo]", "Query - Get Masters
Directory")
ReportDir = DLookup("[ControlInfo]", "Query - Get Report
Directory")
ReportFileName = "Time Analysis Report " & Year(EndDate) &
Format(Month(EndDate), "00") & Format(Day(EndDate), "00") & ".xls"
With Application.FileSearch
.NewSearch
.LookIn = ReportDir
.SearchSubFolders = False
.Filename = ReportFileName
If .Execute() = 1 Then
Let match = ""
VBA.FileSystem.Kill ReportDir & ReportFileName
End If
End With
VBA.FileCopy MasterDir & "Time Analysis Ding Master.xls", ReportDir
& ReportFileName
ReportFileName = ReportDir & ReportFileName
DoCmd.TransferSpreadsheet _
TransferType:=acExport, _
SpreadsheetType:=acSpreadsheetTypeExcel9, _
TableName:="Query - All Employee Ding Only", _
Filename:=ReportFileName, _
HasFieldNames:=True, _
Range:="ExportData"
function end
===========================================
That is the general gist of the function. I does other things but that
is how I use the dlookup and the control file.
I started out a long time ago having a single record file with many
fields, but whenever I had to add another field it was a bear. Then I
saw a reference to this type of structure in in one of the groups and
have converted over to using it.
Hope this gives you some ideas.
The same approach could be used almost anywhere. I would want to write
out the vba code for an importtxt so I would have better control and
instead of using the macro to do the import/export, have it run the
code that does the import/export. Just like I did with the
transferspreadsheet above.
Ron