Go Back   Access World Forums > Microsoft Access Discussion > Macros

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-20-2018, 01:32 AM   #1
mazoon
Newly Registered User
 
Join Date: Jun 2018
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
mazoon is on a distinguished road
Data Macros and TempVar Object

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 ?

mazoon is offline   Reply With Quote
Old 06-20-2018, 01:37 AM   #2
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 5,369
Thanks: 128
Thanked 1,467 Times in 1,439 Posts
Minty has a spectacular aura about Minty has a spectacular aura about Minty has a spectacular aura about
Re: Data Macros and TempVar Object

I don't use macro's, but could you not call a normal macro/bit of VBA to do this from the data macro?
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 06-20-2018, 01:45 AM   #3
mazoon
Newly Registered User
 
Join Date: Jun 2018
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
mazoon is on a distinguished road
Re: Data Macros and TempVar Object

Quote:
Originally Posted by Minty View Post
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

mazoon is offline   Reply With Quote
Old 06-20-2018, 09:49 AM   #4
June7
Newly Registered User
 
Join Date: Mar 2014
Posts: 348
Thanks: 0
Thanked 80 Times in 80 Posts
June7 is on a distinguished road
Re: Data Macros and TempVar Object

Can data macro reference an unbound textbox? Instead of setting TempVar, set textbox.
June7 is offline   Reply With Quote
Old 06-20-2018, 10:29 AM   #5
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,373
Thanks: 49
Thanked 1,844 Times in 1,794 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: Data Macros and TempVar Object

I'm not sure why you involve a tempvar.
See this thread for use of Data macro and audit log.

Good luck.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is online now   Reply With Quote
Old 06-20-2018, 10:38 AM   #6
mazoon
Newly Registered User
 
Join Date: Jun 2018
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
mazoon is on a distinguished road
Re: Data Macros and TempVar Object

Quote:
Originally Posted by June7 View Post
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
mazoon is offline   Reply With Quote
Old 06-20-2018, 10:40 AM   #7
mazoon
Newly Registered User
 
Join Date: Jun 2018
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
mazoon is on a distinguished road
Re: Data Macros and TempVar Object

Quote:
Originally Posted by jdraw View Post
I'm not sure why you involve a tempvar.


Good luck.

I am using tempvar because I store the current user name in it.

mazoon is offline   Reply With Quote
Old 06-20-2018, 10:44 AM   #8
June7
Newly Registered User
 
Join Date: Mar 2014
Posts: 348
Thanks: 0
Thanked 80 Times in 80 Posts
June7 is on a distinguished road
Re: Data Macros and TempVar Object

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 by June7; 06-20-2018 at 11:59 AM.
June7 is offline   Reply With Quote
Old 06-20-2018, 10:50 AM   #9
mazoon
Newly Registered User
 
Join Date: Jun 2018
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
mazoon is on a distinguished road
Re: Data Macros and TempVar Object

Quote:
Originally Posted by June7 View Post
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
mazoon is offline   Reply With Quote
Old 06-20-2018, 11:52 AM   #10
June7
Newly Registered User
 
Join Date: Mar 2014
Posts: 348
Thanks: 0
Thanked 80 Times in 80 Posts
June7 is on a distinguished road
Re: Data Macros and TempVar Object

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 by June7; 06-20-2018 at 12:09 PM.
June7 is offline   Reply With Quote
Old 06-20-2018, 01:36 PM   #11
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 11,373
Thanks: 49
Thanked 1,844 Times in 1,794 Posts
jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice jdraw is just really nice
Re: Data Macros and TempVar Object

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

__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing a JPG as a TempVar? RiotSloth Macros 5 10-01-2013 01:19 AM
Hello - How to Find & Replace object names within all Macros CC65 Macros 6 07-11-2013 07:02 AM
Using TempVar Variable dugoneill Forms 9 03-24-2010 05:35 AM
Macros opening Data Entry Forms and copying Data. TedMurphy Macros 4 04-30-2003 02:32 PM
Insert Object Using Macros mstorer Macros 0 06-28-2002 06:40 AM




All times are GMT -8. The time now is 03:59 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World