• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 973
  • Last Modified:

Access 2013 How do I reference a Local Variable in a 'Data Macro'

I am trying to run an 'After Update' data macro where I create a record in another table ONLY if any of 3 fields are changed.  Otherwise, I do not need to log any of the changes.

Problem - I am attempting use a 'local variable' that I set in the beginning of the data macro to tell me if indeed any of these fields have changed.   However, I never get a new record created.   I believe that I may not be referencing the local variable correctly.

I have attached a screen shot of the code for your review.  I hope this is a quick fix that someone out there can help me with.

Thank you.
lq
LocalVariable.jpg
0
Linda Quintana
Asked:
Linda Quintana
  • 3
  • 2
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
TempVars is generally the best way to refer to those in a Macro.

You can add a new item to the TempVars collection like this:

TempVars.Add "NameOfYourVariable", "Value of Your Variable"

You can also use SetTempVar in your Macro to do the same.

To refer to a TempVar:

TempVars("NameOfYourVariable")

https://msdn.microsoft.com/en-us/library/office/ff821458.aspx
0
 
Linda QuintanaAnalyst, Business Process Development and Continuous ImprovementAuthor Commented:
I'm not having any luck either way.   I have to create the 'temporary variable' when I change the specific variables on the form.   But when I reference it in the data macro I get a message that the variable cannot be found.  

Is it possible that I'm just not referencing it correctly.    I am using and IF statement    --    
If [TempVars]![tmpChanged] = "Yes"  then
   Create record....statement.
EndIf

Whether I reference the variable as a Local Variable or a Temporary Variable -- I get the same message.

Any ideas?   or thoughts?
lq
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Sorry, I believe that should be:

TempVar!tmpChanged
0
 
Linda QuintanaAnalyst, Business Process Development and Continuous ImprovementAuthor Commented:
I found that comparing and old value of  NULL   vs a new value was the culprit.   For some reason the system was unable to understand that the values were different.   Since the values expected were from a 'product list', I created a product that stated  NONE.   Once I changed all the values in the table that were originally   NULL   to   select the product   NONE.   I was able to make changes and have the logic understand that there was indeed a change.   Perhaps I could have done that by checking if the value were NULL, but it was easiest to just change the table.

I'll mark this as solved.

Thank you.
lq
0
 
Linda QuintanaAnalyst, Business Process Development and Continuous ImprovementAuthor Commented:
--
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now