Can't a file be written in the Unload event of a Form? I am trying to populate a text file with some text in the Form's Unload event function:
But the above code generates theCode:Private Sub Form_Unload(Cancel As Integer) Dim FileName As String Dim iFile As Integer If (Form2.chkLoad.Value = 0) Then FileName = App.Path & "\MyFile.txt" 'the file is a hidden file; so changing it to a normal file for editing SetAttr FileName, vbNormal Open FileName For Output As #iFile Write #iFile, "Windows" Close #iFile SetAttr FileName, vbHidden End If Unload Me End Sub
Bad file name or number.
error pointing to the red line in the above code. I also tried the above code in the Form's QueryUnload event function but it generates the same error.
Is there any way to edit a file when the Form is unloaded?




ARPAN
Reply With Quote