getrighteous
Programmer
I have created an networked Access application that allow users to view data coming from another Access database via linked tables. The users do not add any data to either database in the process, all data is read only. The data in the "data" database (where the data files are stored) gets updated on a monthly basis by executing a macro that runs the following code:
This function loops through a directory and for each text file, checks for the presence of the appropriate table, deletes it, and imports the text file.
This all works just fine -- unless someone else is currently accessing the database. The tables can not be deleted, and the code hangs.
Does anyone know how I can change the code to free up the database at the time the import macro is run, ensuring that no one can access the application unless the code finishes running?
Code:
Public Function GetFiles()
MyPath = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""
If Right(MyName, 4) = ".txt" Then
strTblName = Left(MyName, Len(MyName) - 4)
strSpec = LCase(strTblName) & " Import Specification"
If Not CurrentDb.OpenRecordset("SELECT * FROM MSysObjects WHERE name = '" & strTblName & "'").EOF Then
DoCmd.DeleteObject acTable, strTblName
End If
strFile = MyPath & MyName
DoCmd.TransferText acImportDelim, strSpec, strTblName, strFile
End If
MyName = Dir
Loop
End Function
This function loops through a directory and for each text file, checks for the presence of the appropriate table, deletes it, and imports the text file.
This all works just fine -- unless someone else is currently accessing the database. The tables can not be deleted, and the code hangs.
Does anyone know how I can change the code to free up the database at the time the import macro is run, ensuring that no one can access the application unless the code finishes running?