Controlling Microsoft Access

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Controlling Microsoft Access

Post by mightycpa » Thu Jan 28, 2010 5:03 am

Hi,

It has been a long time since I've fired up MS... I'm running on Windows XP, and my version is MS10.

I'm trying to automate the operation of an MS Access application. I need to click buttons, read dialog boxes, dropdown lists, etc.

I'm having trouble doing that, when I record a new macro, it basically creates a file that goes to various coordinates and types or clicks. I'd feel a whole lot better if I could find a button by name, read the contents of a dropdown list, and interpret the value of controls and other objects.

Have I just forgotten how to use this? Is there a way? I'd appreciate any small code snippets that demonstrate how to do this, and I'll be on my way.

Tx,

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Thu Jan 28, 2010 5:21 am

Hi mightycpa,


Before trying to control Microsoft Access via its GUI, consider this:

http://www.mjtnet.com/blog/2006/02/20/a ... databases/


I generally use embedded vbscript to control the Excel and Access objects:

http://www.mjtnet.com/vbsdb.htm


Gale

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Thu Jan 28, 2010 6:01 am

I appreciate what you're suggesting, but I'm trying to control an Access APP... so while I can certainly connect, run queries, insert records, etc...

I need to run an Application written by somebody else who used MS Access as the front end. It is a fairly sophisticated app, so I don't want to recreate the wheel, I just want to run it.

Tx,

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 28, 2010 9:53 am

You might want to refresh and read this:
http://www.mjtnet.com/blog/automation-f ... omate-xyz/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Thu Jan 28, 2010 12:53 pm

Hi Marcus,

I did read that last night, but controlling Notepad and controlling Access appear to be two completely different things.

For example, Notepad does not have a dropdown control that holds values one might select. My Access App does.

When I click on that coordinate, MS does not appear to know that it is a control. It has no idea how many values are in the dropdown, nor what their values are.

So if the list contained A C E G I and I wanted to select E, I would have to click on the coordinates where the dropdown appears, and then press DOWN 3 times. That works fine until someone adds B to the list (A B C E G I)...

What I'm looking for is a way to read those values and know what they are. Same for buttons and text controls, although I suppose I could use image recognition for that.

So that's really my question... is it possible using MS?

Tx,

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Thu Jan 28, 2010 1:06 pm

You know, I may have answered my own question here.

It occurred to me that Notepad does indeed have dropdown controls. They are called the "menu".

I guess the difference is that Notepad's menu hasn't changed in years. So I can confidently record a keystroke sequence, Alt-F-S, to save a file.

But my Access APP's dropdowns are populated dynamically from data. They can be rapidly changing values. I suppose that it is possible to first query the data to know what is populated in the APP, then to blindly choose accordingly.

Hmm.... like I said, it has been awhile.

Tx,

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 28, 2010 2:10 pm

Many drop downs can just be "drilled down" by simply sending the text of the item you want to select.

But read this:
http://www.mjtnet.com/blog/2009/07/02/s ... down-list/

Doesn't matter whether it's Access, Notepad, the drop down in the Display Settings dialog, or a drop down in MyWidgetApp made by WeMakeWidgets Inc that I've never seen nor heard of. The answer is going to be one of:

1. Ideally you can "drill down" by sending the text of the item you want to select.
2. If not, is the item you want always at the same position. E.g. if the list is only ever 12 lines long, you can hard code the position of each item and send the down arrow to it as appropriate.
3. If it's a horrible stubborn control with no drill down, no way to select via the keyboard and/or an unknown length list with changing items, then try the screen text capture approach discussed in the above blog post.
4. You might be lucky if it's a standard list control and you might be able to use the GetListItem command.

I guarantee - there's a method that works. But start with the basics - pretend your mouse doesn't exist. Can you select the item you want with the keyboard?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Fri Jan 29, 2010 5:29 am

Hi,

There were lots of things I couldn't do reliably, including 1,2,4 on your list. I didn't try #3... interestingly, the one thing I could do was to copy the text of the item in the list to the clipboard once it was selected.

Look ma, I can read!

But I cannot even SetFocus to several windows within the application. So I will need to get tricky.

Anyway, I think I got the jumpstart I needed, I'm sure I'll be back to the forums for specific assistance.

Tx,

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts