Im using Access 2016 files are server based which means I cant touch the registry.

I import a new CSV file every morning date CSV01 - CSV31 dependant on day of the month. Thanks to this site it imports the data irrespective of the table format possibly changing (new fields being added). Until about 2 weeks ago everything worked fine for over a year but then I firstly got Exceeded size issues and table not found on the imports.

Size problem solved with dbMAXlocksPerFile code added and I had to change a query format which was the same query but with different query name pulling data from 1 table to allow me to get rid of specific duplicate reports. Used same named query for both recordsets. (Still dont understand why it kept saying size exceeded but hey ho it now works so).

Back to current import issue

If I add a sleep module of 5 seconds no less (set to 5 secs) the table imports with no issues but anything less and it says table not found and stops at the line of code. (If I press run it then loads without issue)



"
Code:
Public Function fImport2(strCFFile As String) As Boolean ' imports a text file from a specified folder
    Dim strFilePathName, strPath As String
    
    DoCmd.SetWarnings False


    strPath = "C:\Users\colin\Desktop"      'strPath = where the txt files are found
    strFilePathName = strPath & strCFFile & ".txt" '***full path to file, CFImport is the spec for table which currently has 100 fields but using 81.


    DoCmd.TransferText acImportDelim, SpecificationName:="CFImport", tablename:=strCFFile, filename:=strFilePathName, hasfieldnames:=False


    fImport2 = fWriteheaders3(strCFFile)  '***this takes the headers from a row in the imported text file and and makes them headers replacing the generic Field1, Field2 etc


    
End Function
Code:
Function fWriteheaders3(strTblname As String) As Boolean 'this takes the headers from a row in the imported text file and and makes them headers replacing the generic Field1, Field2 etc
Dim db as DAO.Database
Dim td As TableDef
Dim rs as DAO.Recordset
Dim i As Integer
Dim strSQL As String


'Have to now put Sleep For  (5000) 'code here to ensure table loads Yes I probably could have put in previous function but that code took soooooo long to work I hate going near it lol "Aint broke dont fix it"




Set db = Currentdb
Set rs = db.Openrecordset(strTblname) ' where it stops without the 5 second delay saying cant find table


.... rest of code but never get here

End function

Any ideas why or solutions to stop me needing to delay code by 5 seconds. Its useable but obviously slower for the user who initially opens the database. Everyone else doesnt need this process once the data has been loaded the first time in the day.
The biggest time lag is after weekend and / or bankholidays which can amount to a 20 second delay overall on top of the normal code running time

Thanks