The Now function is good to capture both the date and time, or you can use the Time function to just capture when the app is unloaded.
Code:
'When X Button is clicked
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Open App.Path & "\unloaded.txt" For Append As #1
'Append is used if you want to add to the file
'Output is used to overwrite the file
Print #1, Now() 'or Time()
Close #1
End Sub
'Or:
Private Sub Form_Unload(Cancel As Integer)
Open App.Path & "\unloaded.txt" For Append As #1
Print #1, Now() 'or Time()
Close #1
End Sub