views:

79

answers:

3

I have a variable newItem. I want to place the value stored in newItem into a string. I thought I would be able to accomplish this with...

myString = eval(newItem)

...but it doesn't work.

Is there any way to evaluate a variable in Access vba?

+3  A: 

Sure is. you need to typecast the variable to a string.

In VBA you use myString = CStr(var)

I believe these are all the typecasts in vba:

CBool(expression)
CByte(expression)
CCur(expression)
CDate(expression)
CDbl(expression)
CDec(expression)
CInt(expression)
CLng(expression)
CSng(expression)
CVar(expression)
CStr(expression) 
Byron Whitlock
+2  A: 

Eval is a function that will execute the text in the given string as if it were code.

I think what you are looking for is CInt:

Dim s as String : s = "15"
Dim i as Integer : i = CInt(s)
'at this point, i = 15, and s = "15"

Similarly, you should look into CStr, CLng, CDate, etc.

mgroves