I have an Access Form named "Form1", and in the form it has a couple of subs like, Form_Load, Form_Unload, etc.
I want to use an AutoHotKey script to control the opening and closing of the form.
Form opening code:
acc:= ComObjCreate("Access.Application")
acc.OpenCurrentDatabase("\\...\target_database.accdb")
acc.Visible := True
acc.UserControl := True
acc.DoCmd.OpenForm("Form1")
Form closing code:
acc.quit
Error 91
pops up when it tries to close the application. And the error seems to relate to the Form_Unload sub. It only happens when I use AutoHotKey, I am able to close the Access manually with no problem.
Here is the Code for Form_Unload:
Private Sub Form_Unload(Cancel As Integer)
' update the data in txt, signal and datetime
Dim fso As New FileSystemObject
'the file we're going to write to
Dim ts As TextStream
'open this file to write to it
Set ts = fso.CreateTextFile("\\cp-apps01\ExtruderDataCollector\TESTING\log.txt", True)
For Each Key In Module1.dict_pre_Signal.Keys
ts.WriteLine (Key & " " & Module1.dict_pre_Signal.Item(Key) & " " _
& DateValue(CStr(Module1.dict_pre_Time.Item(Key))) & " " _
& TimeValue(CStr(Module1.dict_pre_Time.Item(Key))))
Next Key
ts.Close
Set fso = Nothing
End Sub
Is there a way that I can close the form or change the form to design view before I close the access application?