Storing Functions in a Table (1 Viewer)

Gina

Registered User.
Local time
Today, 12:00
Joined
Apr 15, 2000
Messages
30
This may have been covered in another post so I apologize ahead. What I am trying to do is to store a function call in a table field (identified as text), and then try to run that function in a query. I need to know how to tell the query to run the function, instead of just returning the text of the function.
Example:
Table 1:
Field Name Field Contents
Fields: Product_ID = 68500
Fields: Products_Function = fp([some date from another table], 1)

So when I use the [Products_Function] field in a query it just returns the text contents. I want it to run the function.

Help!!!
MS Access 2003 SP =3
Gina
 

Gina

Registered User.
Local time
Today, 12:00
Joined
Apr 15, 2000
Messages
30
I tried EVAL and I am getting an error. I tried =Eval([products_function]) and just Eval([products_function]). I know the function works, because I am using it in other queries.
 

vbaInet

AWF VIP
Local time
Today, 17:00
Joined
Jan 22, 2010
Messages
26,374
Try
Code:
Eval([products_function] [COLOR=Red][B]& "()"[/B][/COLOR])
those are parentheses.
 

Gina

Registered User.
Local time
Today, 12:00
Joined
Apr 15, 2000
Messages
30
Sorry, that didn't work either.
 

vbaInet

AWF VIP
Local time
Today, 17:00
Joined
Jan 22, 2010
Messages
26,374
Is your function returning a string or a numeric value? If it isn't then Eval won't work.

All you want to do is run the function?
 

Gina

Registered User.
Local time
Today, 12:00
Joined
Apr 15, 2000
Messages
30
My function was returning a variant. I changed it to an integer and it's still not working.

Yes, all I want to do is run the function.
 

vbaInet

AWF VIP
Local time
Today, 17:00
Joined
Jan 22, 2010
Messages
26,374
Can you upload a stripped down version of your db with the query and any related tables. I'll take a quick look.
 

Gina

Registered User.
Local time
Today, 12:00
Joined
Apr 15, 2000
Messages
30
this is a really stripped down version of the function.
 

Attachments

  • EvalTest.mdb
    196 KB · Views: 84

vbaInet

AWF VIP
Local time
Today, 17:00
Joined
Jan 22, 2010
Messages
26,374
I have attached two ways of how it can be accomplished.
 

Attachments

  • EvalTest.mdb
    288 KB · Views: 95

Gina

Registered User.
Local time
Today, 12:00
Joined
Apr 15, 2000
Messages
30
THANK YOU!!!! THANK YOU!!!! THANK YOU!!!!

Way 2 is the way to go...
 

vbaInet

AWF VIP
Local time
Today, 17:00
Joined
Jan 22, 2010
Messages
26,374
You're welcome! I'm still not convinced why you want to do it though, but then again I don't know the bigger picture.

Anyway, I looked at it again and noticed that it errors further down the line, so replace these bits:
Code:
Public Function funTest(LE As Variant, Actual As [COLOR=Red]Long[/COLOR]) As Integer
    If [COLOR=Red]VarType[/COLOR](LE) = [COLOR=Red]vbString[/COLOR] Then
Code:
funTest = [COLOR=Red]Nz([/COLOR]rs.Fields(0)[COLOR=Red], 0)[/COLOR] + [COLOR=Red]Nz([/COLOR]rs.Fields(1)[COLOR=Red], 0)[/COLOR]
 

Users who are viewing this thread

Top Bottom