Use Excel to trigger a process in Access.

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I have some procedures that I have written in VBA in Access, I use an excel spreadsheet as one of my data sources in Access. I would like to know if there is a way when something happens in Excel (i.e its opened at 9AM) for it to trigger the process in access?

Ideally, when the file is opened in the morning (say 9AM) and in the afternoon (say 1PM) the access process would be called.

Is this possible? If so how could this be done?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You can use Excel to call Access and run any procedure:

Code:
Sub Do_Something()
    Set objAccess = CreateObject("Access.Application")
    With objAccess
        .OpenCurrentDatabase "C:\db1.mdb", False
        .Run ("MyProcedure")
    End With
End Sub

By the way you can schedule this to happen automatically through windows task scheduler and forgo the need to open Excel at all (which, by the way, if you do go through excel you'll need to create an event trigger and make sure that the event can't be fired more than once in a specific time frame). The only change would be to write the code as a vbs script and run it from windows task scheduler.
 
Upvote 0
Thank you that was great....

Is there a way to send information (i,e. status messages) back to excel to let the user know what has been done?
 
Upvote 0
Hi,

My personal preference is to write procedures as functions (value returning -- normally true/false or 0/1 to indicate success or failure). Then it is only necessary to write another function to email recipients the status code (i.e., if success, then "such and such procedure ran successfully", or if failure then "such and such procedure was completed with errors").

So:
Code:
Sub Do_Something()
    Set objAccess = CreateObject("Access.Application")
    With objAccess
        .OpenCurrentDatabase "C:\db1.mdb", False
        ret = .Run ("MyProcedure") '// procedure is  a function that returns a status code
        [COLOR="#FF0000"]Call emailEndUsers(ret)
[/COLOR]    End With
End Sub
To be honest, working with email in VBA is not my favorite as the only reliable method I have found is to use Outlook automation, which is somewhat onerous. Nevertheless, I do use it on a regular (daily) basis. I normally just leave my machine always on and Outlook always running in order to keep it simplest. BTW you can minimize outlook to the system tray so even if it is always running, it isn't "in your face".

If you aren't sure about using vba and outlook, try some simple tests to get acquainted (send yourself some emails). We can then tweak that to get it ramped up.

ξ

Edit:
note:
To be honest, working with email in VBA is not my favorite as the only reliable method I have found is to use Outlook automation, which is somewhat onerous
If your organization has a local email server, then actually CDO is very easy to use and is reliable. I used it exclusively until we moved to an exchange server "in the cloud", after which my life became more difficult.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,904
Messages
6,162,743
Members
451,785
Latest member
DanielCorn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top