Using the follwing code and getting the error message:
Run time error '2455':
You entered an expression that contains an invalid reference to the
property MaxRecButton.
My code just searches the directory where the database is and imports
the csv files it finds there. Debug on the error takes me to the line:
DoCmd.TransferText acImportDelim, "FileImport", "tblFiles",
strfullname, False
Any ideas what is causing this error???
Thanks,
Rob.
***Code Block***
Private Sub Command0_Click()
Dim db As DAO.Database, rs1 As DAO.Recordset, rs2 As DAO.Recordset,
rs3 As DAO.Recordset
Dim strfilename As String
Dim strfullname As String, mysql As String, strmsg As String, docase
As Integer
'***Set up variables
Set db = CurrentDb
Set rs1 = db.OpenRecordset("tblFiles")
Set rs2 = db.OpenRecordset("tblFilesLoaded")
'***Find first file
strfilename = Dir("C:/Documents and
Settings/rmcgrego/Desktop/audit2/*.csv")
strfullname = "C:/Documents and Settings/rmcgrego/Desktop/audit2/"
& strfilename
'***Loop until no files left
Do Until strfilename = ""
'***Case check file is not already loaded
'set up new record source that is a query based on the filename
returned by Dir
mysql = "select all * from tblFilesLoaded where filename='" &
strfilename & "'"
Set rs3 = db.OpenRecordset(mysql, dbOpenSnapshot)
'check if file is already listed in the record source
If rs3.RecordCount > 0 Then
docase = 0
Else
docase = 1
End If
'***Start new case select
Select Case docase
'***Case loaded - error message
Case 0
strmsg = "File - " & strfilename & " - already loaded on " &
rs3![dateloaded]
strmsg = strmsg & ". Check files you are trying to load and
run again if necessary."
MsgBox strmsg, vbOKOnly
strfilename = Dir
'***Case not loaded - load file
Case 1
SysCmd acSysCmdSetStatus, "Loading file " & strfilename
DoCmd.TransferText acImportDelim, "FileImport", "tblFiles",
strfullname, False
SysCmd acSysCmdSetStatus, "Completed loading " & strfilename
rs2.AddNew
rs2![FileName] = strfilename
rs2.Update
'***Move file to completed directory
FileCopy strfullname, "C:/Documents and
Settings/rmcgrego/Desktop/audit2/processed/" & strfilename
Kill (strfullname)
'***End Case
End Select
strfilename = Dir("C:/Documents and
Settings/rmcgrego/Desktop/audit2/*.csv")
strfullname = "C:/Documents and Settings/rmcgrego/Desktop/audit2/"
& strfilename
'Return to loop until all files processed
Loop
SysCmd acSysCmdClearStatus
End Sub