You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Option Explicit' Go to Tools -> References... and check "Microsoft Scripting Runtime" to be able to use' the FileSystemObject which has many useful features for handling files and foldersPublicFunctionSaveTextToFile()' The advantage of correctly typing fso as FileSystemObject is to make autocompletion' (Intellisense) work, which helps you avoid typos and lets you discover other useful' methods of the FileSystemObjectDimfsoAsFileSystemObjectSetfso=NewFileSystemObjectSetcurDb=Application.CurrentDbdbFullPath=fso.GetAbsolutePathName(curDb.Name)DimfilePathAsStringfilePath=dbFullPath&".locked"DimfileStreamAsTextStream' Here the actual file is created and opened for write accessSetfileStream=fso.CreateTextFile(filePath)' Write something to the filefileStream.WriteLine"File is currently used from another user and therefore locked."' Close it, so it is not locked anymorefileStream.Close' Here is another great method of the FileSystemObject that checks if a file existsIffso.FileExists(filePath)ThenMsgBox"Yay! The file was created! :D"EndIf' Explicitly setting objects to Nothing should not be necessary in most cases, but if' you're writing macros for Microsoft Access, you may want to uncomment the following' two lines (see https://stackoverflow.com/a/517202/2822719 for details):SetfileStream=NothingSetfso=NothingEndFunction