[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MS Access setTempVar

Posted on 2013-05-29
3
Medium Priority
?
1,511 Views
Last Modified: 2013-05-30
I have a macro that retrieves a value from a table and sets it into a tempvar.

the value retrieved is "New Account " & [LocationID] & "-" & [ClientID]

so gnewacctformat = "New Account " & [LocationID] & "-" & [ClientID]

I am trying to insert this value into a query so that the query is executed using the variable information - in other words [LocationID] and [Clientid] exist in the table tblWorking_Locations.  So I wrote the query as follows;


SELECT [TempVars]![gnewacctformat] AS account
FROM tblWorking_Locations;

What is returned is "New Account " & [LocationID] & "-" & [ClientID]

What I want to do is have the query execute is

SELECT "New Account " & [LocationID] & "-" & [ClientID] AS account
FROM tblWorking_Locations;

and return  New Account 123-CSC   where 123 and CSC are values from the table tblWorking_Locations.

Is it possible to do this without creating and executing the query from VB?
0
Comment
Question by:keschuster
3 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 39206986
are you just checking to see if an account 123-CSC exists?  and if so return the string "New Account 123-CSC"

there's no where clauses listed in your query examples... what are you using gnewacctformat for?

From your question it sounds like you are getting a value from a table into a variable then checking to see if a string exists in another table, but not saying how the where clause works....
0
 

Author Comment

by:keschuster
ID: 39207834
I'm trying to manipulate the actual sql statement by passing a variable in the contains a piece of the statement.  What is retrieve does not matter here
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 2000 total points
ID: 39208267
Typically, the query editor does NOT like to fetch global variables.
One method of attack is VBA
You create a little wrapper function

Public Function gnewacctformatValue() as string
    gnewacctformatValue = gnewacctformat
end function

You can then use gnewacctformatValue() in queries

Although this syntax confuses me
[TempVars]![gnewacctformat] as I have never seen anything like it

Try the sample for a straight up query, though
working-locations.mdb
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question