Data Macros and TempVar Object (1 Viewer)

mazoon

New member
Local time
Today, 01:42
Joined
Jun 20, 2018
Messages
5
I want to create a data macro on a table in my database that is triggered by the after update event and writes the content of a TempVar object in a field in another table.



When I want to use the data macro to write something else then a TempVar Object I do the following:

If Updated("ProductName") Then
Create a Record In tblLog
SetFiled

Name tblLog.tblName

Value tbleProducts



this works find and the entry is successful in tblLog, but if I wanted to use a TempVar Object like so:


If Updated("ProductName") Then
Create a Record In tblLog
SetFiled

Name tblLog.User

Value TempVars("UserID")


this does not work, I googled it around and found that you can't use the TempVar Object inside a data macro and you should use a named macro instead, but I don't know how to do that, could someone please give me an example ?
 

Minty

AWF VIP
Local time
Today, 09:42
Joined
Jul 26, 2013
Messages
10,368
I don't use macro's, but could you not call a normal macro/bit of VBA to do this from the data macro?
 

mazoon

New member
Local time
Today, 01:42
Joined
Jun 20, 2018
Messages
5
I don't use macro's, but could you not call a normal macro/bit of VBA to do this from the data macro?


I could, but data macro are much more easier (at least for me) in what I am trying to achieve, I could write some vba code, but that would set me back a few weeks, I hope someone else knows how to do this and show me an example
 

June7

AWF VIP
Local time
Today, 00:42
Joined
Mar 9, 2014
Messages
5,466
Can data macro reference an unbound textbox? Instead of setting TempVar, set textbox.
 

mazoon

New member
Local time
Today, 01:42
Joined
Jun 20, 2018
Messages
5
Can data macro reference an unbound textbox? Instead of setting TempVar, set textbox.


I am not sure if they can reference a textbox, but even if they could that would mean I will have to update every form, that really defeat the purpose of using data macros. Data macros are used at the table level independently from and form, report or vba code
 

June7

AWF VIP
Local time
Today, 00:42
Joined
Mar 9, 2014
Messages
5,466
Yes. Or use a form that never closes - I usually set main menu that way. Other alternatves already provided. Build a named macro or VBA function that references TempVar and call that from DataMacro.

I also never use macros of any type (except for AutoKeys one time).
Never used TempVars either.
 
Last edited:

mazoon

New member
Local time
Today, 01:42
Joined
Jun 20, 2018
Messages
5
Yes. Or use a form that never closes - I usually set main menu that way. Other alternatves already provided. Build a named macro or VBA function that references TempVar and call that from DataMacro.

I also never use macros of any type (except for AutoExec one time).
Never used TempVars either.


It was suggested to me to build a named macro that reference tempvar, but my problem is I don't know how to build a named macro that reference tempvar and I don't know how to call it from data macro either, I would really appreciate it if someone shows me an example of how to do that
 

June7

AWF VIP
Local time
Today, 00:42
Joined
Mar 9, 2014
Messages
5,466
Google: datamacro call function

"use setLocalVar from Action list in data macro and set expression to name of your function sample: name 'test' ..."

I am not finding way to set TempVar in data macros, not even named, just in regular macro or VBA. Now question is how data macro can call a regular macro - same as VBA function?

Why data macro and not form event? How many forms edit this table?
 
Last edited:

jdraw

Super Moderator
Staff member
Local time
Today, 04:42
Joined
Jan 23, 2006
Messages
15,379
@mazoon,
Did you look at the example in the link I suggested?
It deals with data macro and named macro and tables to create records in an audit log.
It also shows use of a standard function to get user info for the audit log.
 

Users who are viewing this thread

Top Bottom