Jump to content

Using MSAccess with COM


 Share

Recommended Posts

hi, i am writing a script that will attach to any open msaccess process and save/close the database (any access version) on either XP or windows 2000 professional then quit the application. The scripts works fine under XP however on W2K professional it is causing an error. I have inserted code to recognise what OS i am running the script on and this works fine for XP but my W2K command is failing.

My Code is as follows -

AutoItSetOption("WinTitleMatchMode", 2)

Do

Local $oMDB = ObjGet("", "Access.Application")

If not IsObj($oMDB) Then

ExitLoop

Else

WinActivate("Microsoft Access")

Sleep(5000)

IF @OSVERSION= "WIN_2000" Then

$oMDB.Quit ;<--------------------this is causing the issue

Else

$oMDB.Quit.acQuitSaveAll

EndIf

EndIf

Local $ftitle = WinGetTitle($oMDB, "")

Until $ftitle = "Microsoft Access"

If I have 5 access processes open, the loop will run and use the $oMDB.Quit command fine. But after the last access window has closed it opens up an error dialog box with the following message:

Line 0 file (\\server\test$\log.exe)

$oMDB.Quit

$oMDB.Quit^ ERROR

Error: The requested action with this object has failed.

I have tried using $oMDB.Quit.acQuitSaveAll on this line but it complains about a similar issue although this command runs fine on Windows XP irrespective of access version.

I have used this loop as a similar model for clsing outlook, excel, powerpoint and word processes where all don't complain about this issue - just msaccess.

Lastly, I have noticed that the Loops in autoit3 don't flow naturally and will run one last time after the condition has been met which is why i have had to do a force exit from the loop with the following "if" statement:

If not IsObj($oMDB) Then

ExitLoop

Any help would be appreciated as to why I am getting this error.

Thanks,

Craig

Link to comment
Share on other sites

i have managed to resolve this myself as follows by moving the following line:

Local $ftitle = WinGetTitle($oMDB, "") :

AutoItSetOption("WinTitleMatchMode", 2)

Do

;Local $oMDB = ObjCreate("shell.application")

Local $oMDB = ObjGet("", "Access.Application")

Local $ftitle = WinGetTitle($oMDB, "")

;MsgBox(0, "", $oMDB)

If not IsObj($oMDB) Then

ExitLoop

Else

WinActivate("Microsoft Access")

Sleep(5000)

IF @OSVERSION= "WIN_2000" Then

;$oMDB.CloseCurrentDatabase

$oMDB.Quit.acSave

Else

$oMDB.Quit.acQuitSaveAll

EndIf

EndIf

Until $ftitle = "Microsoft Access"

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...