0

So I am looking to open an access database on a daily basis using task scheduler. I want this script to open the .aacdb and then open a specific form. The problem is, this database has an auto executable that opens a different form that will close the program when exiting out of it. I need to somehow bypass this executable. I've been trying to write a .vbs script that will use the hold down shift key (to bypass the auto executable) > open database > release shift key > open form > close database. After days of searching, I can't seem to find any answers on whether this is possible. Here is what I have so far (it opens the database but doesn't bypass the auto executable). The aim of this script is to hold down the shift key for 10 seconds while opening the database.

b = DateAdd("s", 10, Time)
Set WshShell = CreateObject("WScript.Shell")
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True
strDBNameAndPath = "C:\FileFolder\file.aacdb"
Do While (Time < b)
  WshShell.SendKeys "+"
Loop
appAccess.OpenCurrentDatabase strDBNameAndPath
Set WshShell = Nothing

I can't mess with the actual database (the macros), this has to happen by somehow bypassing the actual auto executable upon opening a database. Is this possible in .vbs? .vba? .vb? vb.net? any language?? I'm only familiar with .vbs. But any insight would be helpful. Thanks!!!

6
  • 7
    Why are you trying to programmatically interact with a database via its forms? Is there something you're trying to accomplish that you can't via ADODB?
    – Comintern
    Commented Nov 1, 2018 at 20:29
  • 1
    I'm not aware of a way to programmatically disable the AutoExec macro. The vb script you have will repeatedly send a shift key for 10 seconds and then open the database. Obviously this doesn't help. You CAN hold the shift key yourself while the vb script runs.
    – ArcherBird
    Commented Nov 1, 2018 at 20:40
  • 2
    SendKeys doesn't work that way. It doesn't support holding down keys and releasing them. The WinAPI SendMessage function does support sending KeyDown and KeyUp statments separately, you can use that in either VBA or VB.Net, but not in VBScript afaik.
    – Erik A
    Commented Nov 1, 2018 at 20:43
  • 2
    @abce744: Why don't you change the startup behaviour of the accdb? You could change it to not immediately open the default form but instead first check the command line and open a form whose name has been passed there possibly.
    – AHeyne
    Commented Nov 2, 2018 at 4:30
  • 1
    Thanks for all the helpful feedback! This access database is being fed from a website that we use to input data. And by accessing one of the forms, the background processes update the database from the website. Currently the only solution we have found (so far) is to go in everyday and access one of the forms to update everything. I'm coming late on this project, but I was trying to find a way to automate the opening of this form. I don't know much about ADOdb, but I'm all ears if you can think of a better way to do that. Thanks for all the help!
    – abce744
    Commented Nov 2, 2018 at 20:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.