Solved

MS Access setTempVar

Posted on 2013-05-29
3
1,327 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

860 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