Solved

MS Access setTempVar

Posted on 2013-05-29
3
1,378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

726 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