oron
oron

Reputation: 13

How to run function in vba using data macro?

i am new to data macro in ms access 2013 and need some help with it. so lets assume that i have a simple database with only one table of Users. when i change the "Age" Field in the table, i want to run an external exe file (the reason why dosent matter). so i learn the subject during the last few days and end up with this: 1. i build a module in ms access called RunMiniFix (MiniFix is the name of the exe file i want to run). the module uses ShellExecute function and the whole module looks like that:

Option Compare Database
Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3

Public Declare Function ShellExecute Lib "Shell32.dll" Alias "ShellExecuteA" 
  (ByVal hwnd As Long, _
   ByVal lpOperation As String, _
   ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, _
   Optional ByVal nShowCmd As Long) As Long

Public Function RunMiniFix()
     Dim RetVal As Long
     On Error Resume Next
     RetVal = ShellExecute(0, "open", "C:\Program Files\MiniFix\MiniFix.exe", "<arguments>", _
                        "<run in folder>", SW_SHOWMAXIMIZED)
End Function

Now, when activating the module, everything works just fine and the exe file is running.

  1. in ms access, i build a data macro based on an 'If Then' statement, asking if [Users]![Age] > x and then calls the build-in RunCode event from the action catalog which calls the RunMiniFix function. Now, when saving the data macro, the ms access pops up a message box saying Microsoft access dosen't have the ability to find the name "Users" i mentioned in the phrase and recommend me to look for the right control in the form. "the form"? yes, the form! this database is not form based. i have no gui designed what so ever. i have no buttons or click event to handle. what i am asking is how can i trigger the RunMiniFix module when the Age field is modify. please, this is very important!

    thanks a head,

    oron.

Upvotes: 1

Views: 2219

Answers (1)

hassan hojabri
hassan hojabri

Reputation: 16

Please use SetLocalVar from the action list in data macro and set the expression to name of your function. Sample:

name: "test"
Expression: RunMiniFix()

Upvotes: 0

Related Questions