AutoHotkey Community

It is currently May 27th, 2012, 4:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: AHK talking to MS Access
PostPosted: February 22nd, 2010, 8:07 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
Greetings!

I was wondering if any of you know of a simple way for AHK to talk with Access?

In my shop, I use an AHK script to count keystrokes using the script, below. What I would like to build instead is a bot that transfers the stored keystroke counts (including a timestamp) into MS Access. Any ideas of how I could get this done?

Code:
FormatTime, Hour, , HH
IfNotExist, Data Corrections.xls
SetTimer, WatchActiveWindow, 5000


return

WatchActiveWindow:
line = %KC%
StringReplace, line, line, `n, %A_SPACE%, All
StringReplace, line, line, `r, , All
FileAppend, %line%`n,Data Corrections.xls
return

~*a::
~*b::
~*c::
~*d::
~*e::
~*f::
~*g::
~*h::
~*i::
~*j::
~*K::
~*l::
KC++
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2010, 9:09 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
I have not worked with Access, so the following don't have a firm foundation.

Excel can read from CSV file (comma separated Values). Those files can be written and read by Ahk.
Can Access read CSV files?

There is something referred to on this board as "COM" which allows better control of I.E. Word and other programs.
Perhaps it works with Access ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2010, 9:32 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
Thanks for the info! I'm thinking it might be easier to build this in pieces. First, a keyboard hook that captures the user ID and the total for all the keys pressed, and writes them to an INI or a CSV file in a centralized location. These entries would need to have a timestamp.

Second, create a bot that can monitor data saved in the INI or CSV file, and sweep those items into the Access database form by user. The bot would need to empty the INI or CSV file so it starts off with a zero balance after retrieval.

The Access part should be easy to do, it's the loop/set timer that I am unfamiliar with.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2010, 10:22 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
Btw, I somehow missed seeing you script.

I have a few comments about it:
1. don't use Data Corrections.xls as your output file. XLS has a particular format. You will destroy any useful data in the original XLS file.
2. Why are you uing StringReplace on a variable that has no `n and no `r ?
3. In "WatchActiveWindow" you write the current value of KC after removing non-existant `n and `r. But you don't clear KC.
This means that KC is an ever-increasing number. Is that what you want?
4. You probably wanted more than just a...L, correct ?


Edit:
INI files have a useful format, with sections and data & values.
It irks me that some would use this file extension for other types of files
that are non-INI in nature. Just my 2cents worth.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 22nd, 2010, 11:24 pm 
Offline

Joined: January 30th, 2006, 2:53 pm
Posts: 51
Hey John,
Check this discussion out for ADO connections to Access databases.

http://www.autohotkey.com/forum/viewtopic.php?t=16565


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], JSLover, Mickers, rbrtryn and 72 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group