Jump to content

Access Database and Mouse Click Automation


RossIV
 Share

Recommended Posts

I am working on a script to replace a page worth of instructions for a process I do daily.

What I am doing is opening an Access 2010 database, deleting a table, then switching to another (already open and logged in) program. In the second program, I am navigating through a few menus which then export to the aforementioned Access database (adding a table). Then I swap back to Access and print a report based on the table that was just inserted.

I have looked all over this forum and on Google for the past hour and found >this which (should) take care of opening the DB, but even when the AutoIt script is in the same folder as the .accdb file, it says the file doesn't exist.

Is this doable or am I wasting my time?

Thanks in advance!

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

I think it should be possible to do what you want to do.

Please post the code you use to open the database. We will have a look at it and - hopefully - can provide a solution.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks for the welcome!

I guess I can't attach files yet since I'm new, so I've put the two relevant files on PasteBin.

Script: http://pastebin.com/n47sCT5Q

Supporting File: http://pastebin.com/BQWu50HG

In the script right now, it's just reading the Access database and is supposed to spit out a list of tables and fields. The example that I'm using doesn't have a provision for dropping a table, so I was trying to figure out how to do that too.

Thanks!

Link to comment
Share on other sites

I'm not sure the UDF can handle the "new" ACCDB extension. Can you manually create a MDB database and try to open it with the UDF?

When you run your script from SciTE do you get any additional error information in the output pane?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Your problem is described >here. The UDF doesn't seem to support the new ACCDB file format.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I am not using anything special that requires .accdb so I converted it to a .mdb and the script runs just fine after I edited in the proper table name that was throwing some errors.

Left to do:

1. Drop the table

2. Navigate through the menus on the second application and export the report

3. Re-open Access and print the generated report

Ideas for those? In the code, it says that dropping a table is not on the to-do list, so I guess I"ll have to find some other way to do that.

As for navigating through the menus, from what I've seen it's likely going to be X,Y coordinates or if I'm lucky I can use the actual button name. The program that I need to click through is written in VB (I think VB6.) I can't post too many screenshots because of what the program contains, but I can post screenshots of AutoIT Info when run on the program and shots of the menus themselves.

Edit: Here's a screenshot of the menu of the program with AutoIt selecting the menu area. Button I want is highlighted.

aNnAQO3.png

Edit 2: PasteBin of AutoIt Info Summary http://pastebin.com/TDy6q0Jg

Edited by RossIV
Link to comment
Share on other sites

Updated code:  (Decided code tags would be easier than PasteBin)

AutoItSetOption ("MustDeclareVars", 1)

#include "Access.au3"

MsgBox (0, "Welcome", "Click OK to start printing the new callback log.")
    OpenDatabase()
MsgBox (0, "Information", "Checking if Table exists.")
    CheckForTable()
MsgBox (0, "Information", "Now Opening Front Desk. DO NOT MOVE THE MOUSE OR TYPE ANYTHING!!!")
    OpenFrontDesk()

Func OpenDatabase()
    Local $o_DataBase = _AccessOpen(@ScriptDir & "\NewCallbackLog.mdb")
    If $o_DataBase = 0 Then
        MsgBox(0, "Information", "Database file can not be found :-" & @CR & @ScriptDir & "\NewCallbackLog.mdb")
        Return
    Else
        MsgBox(0, "Information", "Database file was opened :-" & @CR & @ScriptDir & "\NewCallbackLog.mdb")
    EndIf

    _AccessClose($o_DataBase)
 EndFunc   ;==>OpenDatabase

Func CheckForTable()
    Local $o_DataBase = _AccessOpen(@ScriptDir & "\NewCallbackLog.mdb")
    Local $O_TableObject

    If $o_DataBase = 0 Then
        MsgBox(0, "Information", "Database file can not be found :-" & @CR & @ScriptDir & "\NewCallbackLog.mdb")
        Return
    EndIf

    $O_TableObject = _AccessTableExists ($o_DataBase, "CREXPORT")
    If $O_TableObject = 0 Then
        MsgBox(0, "Information", "Table does not exist. Proceeding. ")
        Return
    Else
        MsgBox(0, "Information", "Table exists. Need to delete. ")
        DeleteTable()
    EndIf

    _AccessClose($o_DataBase)
EndFunc   ;==>CheckForTable

Func OpenFrontDesk()
   Local $frontDeskEXE = "C:\Program Files (x86)\HPMS\HPMS_FD.exe"
   Local $iPID = Run($frontDeskEXE, "", @SW_SHOWMAXIMIZED)
   Local $hWnd = WinWait("[CLASS:Front Desk]", "", 10)
   WinActivate($hWnd)
EndFunc

Func DeleteTable()
    Local $title,$adoCon,$dbname,$adoRs,$_output,$query
    ; create connection
    $adoCon = ObjCreate("ADODB.Connection")
    $dbname = @ScriptDir & "\" & "Nwind2007.accdb"
    Local $dbname = 'NewCallbackLog.mdb'
    $adoCon.Open('Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=' & $dbname & ';')
    $adoRs = ObjCreate ("ADODB.Recordset")
    ; this query is copied from MS Access designer
    ; should return something
    $query = "DROP TABLE CREXPORT;"
    ; open query
    $adoRs.Open ($query, $adoCon)
    $adoCon.Close

EndFunc ;==>DeleteTable


Func _ErrFunc($oError)
    if $oError <> "0" then
    MsgBox(0, "COM error", "err.number is: " & @TAB & $oError.number & @CRLF & _
    "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
    "err.description is: " & @TAB & $oError.description & @CRLF & _
    "err.source is: " & @TAB & $oError.source & @CRLF & _
    "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
    "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
    "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
    "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
    "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
    endif
EndFunc ;==>_ErrFunc

I have it working as follows:

It opens the DB, checks if the table exists or not and if so, deletes the DB. Then it opens the second application. Problem is - the delete doesn't work. No errors thrown at all - but the table never gets deleted. Followed >this post for executing the query to delete.

Link to comment
Share on other sites

I've never used the Access UDF, so can't help with this.

What I know about databases is that you need to commit changes. Don't know if the UDF supports that.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...