What I am trying to do is import around 30-31 text files in one hit,
currently I have a transfer text for each file. is there a way of importing
all files in one go rather the 30-31 transfer texts macro actions?
Cheers
No, a separate TransferText action is required for each text file.
If you used a VBA procedure instead of a macro, it may be possible to
loop through the files, depending on their file names, and the names of
the tables you are importing into, etc.
--
Steve Schapel, Microsoft Access MVP
I can't quite work out how this would work... can you expand?
--
Steve Schapel, Microsoft Access MVP
Ken Snell [MVP] wrote:
> Or use the RepeatMacro action that has a condition based on Dir function?
>
--
Ken Snell
<MS ACCESS MVP>
"Steve Schapel" <sch...@mvps.org.ns> wrote in message
news:ua2PBijA...@TK2MSFTNGP10.phx.gbl...
It would take a bit of finagling...one would need to use a "storage" place
(control on a hidden form, for example) to hold the filename returned by the
Dir function (recursive call or first time call).
OK - new form "HiddenForm" would have one textbox: txtFile.
Something like this?
----
MacroName: MacroStart
Condition: (none)
Action: OpenForm
Form Name: "HiddenForm"
Condition: (none)
Action: SetValue
Expression: Dir("C:\MyFolder\*.txt")
Control Name: Forms!HiddenForm!txtFile
Condition: (none)
Action: RunMacro
Macro Name: MacroGet
Repeat Expression: Len(Forms!HiddenForm!txtFile & "") > 0
(end of MacroStart)
----
MacroName: MacroGet
Action: TransferText
File Name: ="C:\MyFolder| & Forms!HiddenForm!txtFile"
(other arguments as appropriate)
Action: SetValue
Expression: Dir()
Control Name: Forms!HiddenForm!txtFile
--
Ken Snell
<MS ACCESS MVP>
"Steve Schapel" <sch...@mvps.org.ns> wrote in message
news:uHLZZ9lA...@TK2MSFTNGP10.phx.gbl...
Private Sub btnImportAllFiles_Click()
'procedure to import all files in a directory and delete them.
'assumes they are all the correct format for an ASCII
delimited import.
Dim strfile As String
ChDir ("c:\MyFiles")
strfile = Dir("FileName*.*")
Do While Len(strfile) > 0
DoCmd.TransferText acImportDelim, "ImportSpecName",
"AccessTableName",
"c:\MyFiles\" & strfile, True
'delete the file (consider moving it to an Archive folder
instead.)
Kill "c:\MyFiles\" & strfile
strfile = Dir
Loop
End Sub
>.
>
----
MacroName: MacroStart
Condition: (none)
Action: OpenForm
Form Name: "HiddenForm"
Mode: Hidden
Condition: (none)
Action: SetValue
Expression: Dir("C:\MyFolder\*.txt")
Control Name: Forms!HiddenForm!txtFile
Condition: (none)
Action: RunMacro
Macro Name: MacroGet
Repeat Expression: Len(Forms!HiddenForm!txtFile & "") > 0
Condition: (none)
Action: Close
Object Type: Form
Object Name: HiddenForm
(end of MacroStart)
----
MacroName: MacroGet
Action: TransferText
File Name: ="C:\MyFolder| & Forms!HiddenForm!txtFile"
(other arguments as appropriate)
Action: SetValue
Expression: Dir()
Control Name: Forms!HiddenForm!txtFile
(end of MacroGet)
--
Ken Snell
<MS ACCESS MVP>
"Ken Snell [MVP]" <kthsne...@ncoomcastt.renaetl> wrote in message
news:eo66e%23mAFH...@tk2msftngp13.phx.gbl...
----
MacroName: MacroStart
(end of MacroStart)
----
MacroName: MacroGet
(end of MacroGet)
--
news:e4rVYy9A...@TK2MSFTNGP14.phx.gbl...