Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formulas in table. How do I put them into a query? 1

Status
Not open for further replies.

jkirkland

Technical User
Apr 24, 2003
61
US
I have a table with canned formulas such as: (FldA + FldB)/FldB

I want the user to be able to select one of these from a combobox and then have this become a formula in my master query.

Unfortunately, I can only get the query to display (FldA + FldB)/FldB instead of this formula's result which should be a number.

My SQL shows: forms!myform!mytextbox as ColA

Any recommendations on how to make the query take the string from the text box and recognize it as a formula?

Let me know if I didn't provide enough details
Thanks!
 
Something like this ?
Dim qdf As QueryDef
Set qdf = CurrentDB.QueryDefs("your saved query name")
qdf.SQL = Replace(qdf.SQL, "forms!myform!mytextbox", forms!myform!mytextbox)


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tried that and the report still shows the formula string in the text box rather than the result of the formula.

Is there another way to format the code?

Thanks for your help! :)
 
I think I found the answer. The query saw the formula from the table as a string only because the formula itself referenced on strings. So in the formula I did a plus zero to make the code recognize it as a formula.

((FldA - FldB)/FldB)+0

Then I used PHV's qdf code and it seems to work.

Thanks PHV!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top