I don't quite get that fname2 is picking up a file name. take a look at the codes below might give a better understanding. sorry i am not a coder....
Private Sub ImportLogs_Click()
Dim a As Date, fname1, fname2, d As String, sqltxt As String
DoCmd.SetWarnings False
For a = Me.StartDate To Me.EndDate
DoCmd.SetWarnings False
d = "[logdate] = #" & Format(a, "dd/mm/yyyy") & "#"
Me.filedate = Format(a, "dd/mm/yyyy")
Me.Repaint
z = DLookup("[DateImported]", "tbl ImportLog", "" & d & "")
'If IsNull(z) = False Then
'MsgBox "The File for " & a & " has already been imported."
'Else
DoCmd.OpenQuery "qry delete temporary table"
fname1 = "l:/ex" & Format(a, "yymmdd") & ".Log"
fname2 = "l:/txtfiles/ex" & Format(a, "yymmdd") & ".txt"
FileCopy fname1, fname2
DoCmd.TransferText acImportDelim, "Logs Import Specification", "tmp Temporary File", fname2, 0
Kill fname2
DoCmd.OpenQuery "qry delete images logs"
DoCmd.OpenQuery "qry delete no ref logs"
DoCmd.OpenQuery "qry Append to Logs Table"
sqltxt = "INSERT INTO [tbl ImportLog] ( LogDate, DateImported )SELECT '" & DateValue(a) & "' AS LogDate, '" & Format(Now(), "dd/mm/yyyy") & "' AS importedDate;"
DoCmd.RunSQL sqltxt
b = DMax("[tbl ImportLog].[LogDate]", "tbl ImportLog")
c = Format(Now() - 1, "dd/mm/yyyy")
Me.filedate.Format = Text
Me.filedate = Format(a, "dd/mm/yyyy")
DoCmd.RunMacro "mcro Log Report"
'End If
If b = c Then
Me.LastImported.SetFocus
Me.StartDate.Visible = False
Me.EndDate.Visible = False
Me.ImportLogs.Visible = False
Me.CloseForm.Visible = True
Else
Me.StartDate.Visible = True
Me.EndDate.Visible = True
Me.ImportLogs.Visible = True
Me.CloseForm.Visible = False
Me.StartDate = b + 1
Me.EndDate = c
Me.StartDate.SetFocus
Me.Repaint
End If
Me.LastImported = b
Me.Repaint
Next
DoCmd.SetWarnings True
End Sub