Search code examples
vbams-accessvariableseval

Access vba eval variable


I created a string Path="E:\" to assign a value to a variable with Eval. But it returned a run-time error 2766: This object cannot contain 'automatic' object 'Path'.

Eval variable

Is there a way that I can work on variables with string? I have strings of variables and strings of values. This would save me lot of time.

Many thanks


Solution

  • You can't use Eval to set a variable within the expression. If you write it like this:

    Path = Calcu.Eval("E:\tables")
    

    you'll get the answer in the Path variable. Obviously, this is the same as

    Path = "E:\tables"
    

    but that is a different topic. If you want the variable name to be dynamic as well, then you are probably doing something wrong. If you really want it, the you need to have a look at VBIDE.VBProject, but don't go there until you have a fairly good understanding of VBA.