Way this code dont work in accesds 2016
Private Sub C71_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine ("This is a test.")
a.Close
End Sub
Syntactically and semantically, there is nothing wrong in that code. It should run in any event routine since technically, all events and any functions or subroutine they call are of equal CPU priority and are part of the same process and in the same memory space, therefore of indistinguishable execution context.
However, it is quite common in an office environment, particularly if the office has an activist IT department that uses group policy files, to block WRITE access to the system disk's root folder - which is exactly where you are writing. The error message suggests this might in fact be the case. While it IS possible for you to set the root folder of the C: drive to be READ only, it is uncommon on a personal standalone machine. Which is why I brought up the idea of an active IT department.
Factors that could change this include whether Access is running as you, as administrator, or as some other user; and whether your IT department is active or more passive in the way it manages your environment.