Topics Search

Eval function with variables

Eval function with variables
Views: 12
is it possible to use the eval function with variables e.g. Eval("foo + bar") or Eval("""The value of foo is "" & foo")?

This is because I have my database settings in a table (one field having the name of the setting and the other containing the value) and I wish to be able to reference variables in the settings value. E.g., for the "MsgOnExit" setting, I would have the string

"Are you sure you would like to exit " & AppTitle

Where AppTitle is the name of the database. I would then plan to use Eval at runtime to evaluate the expression to resolve AppTitle to a value. Of course, this may not be the best example as many would argue AppTitle should be a constant, but there are other settings which rely more heavily on variables being able to be resolved at runtime.

(I'm using a settings table because it allows for a settings GUI and also the ability to variables across sessions
Sponsored Links:

More topics

 

Eval function with variables

Preview
is it possible to use the eval function with variables e.g. Eval("foo + bar") or Eval("""The value of foo is "" & foo")?

This is because I have my database settings in a table (one field having the name of the setting and the other containing the value) and I wish to be able to reference variables in the settings value. E.g., for the "MsgOnExit" setting, I would have the string

"Are you sure you would like to exit " & AppTitle

Where AppTitle is the name of the database. I would then plan to use Eval at runtime to evaluate the expression to resolve AppTitle to a value. Of course, this may not be the best example as many would argue AppTitle should be a constant, but there are other settings which rely more heavily on variables being able to be resolved at runtime.

(I'm using a settings table because it allows for a settings GUI and also the ability to variables across sessions
 

Eval function question doesn't work

Preview
I'm trying to update a form using the eval function in a program.
However there is a part that I can't get to work
It will not change the back ground color to white.
I use the eval function since I will do this many times and the form automatically add textboxes when more data is available

Function test()
a = "Forms![INFORM]!LabelIt7.backcolor= 16777215"
Eval (a)
Debug.Print a
End Function

Also tried "Forms![INFORM]!LabelIt7.backcolor= " & 16777215

It doesn't change the color and it doesn't give an error message.
If I change the a string into an command that is not possible it will give an error message.

If I give an enter in the immediate window at the place where it printed the 'a' string the function works perfectley
 

Access - Eval function

Preview
this is my problem
I need to use <EVAL> function for my db, but it does not run.
Example: if I execute this routines (sure enough I build my string)

Sub ChangeIcon() Dim mStr As String mStr = "CommandBars(18).Controls(1).FaceId" Debug.Print Eval(mStr) End Sub

all works well and I see the result (67 for example)
But if I want to change the FaceId, the routines don't show any error, but che FaceId is non changed

Sub ChangeIcon() Dim mStr As String mStr = "CommandBars(18).Controls(1).FaceId" Eval (mStr & "= 3") Debug.Print Eval(mStr) End Sub

value returned always
 

Need a 'smart' field

Preview
Here's what I'm trying to do.

I have a table of employees with their HIRING_DATE stored in a field in DATE format. In the same table I have another field which is called TRIAL_PERIOD which is in a NUMBER format (possible values 0,3,6,12 - 3,6,12 months of trial period respectivelly, and 0 if the trial period is over).

Where it all gets messy, is that I need to display the schedule for the evaluations (as a DATE):
FIRST_EVALUATION, SECOND_EVALUATION and THIRD_EVALUATION

The problem is that those dates are calculated differently for the different trial periods:
e.g. for a 3 months trial period the evaluations are done as follows:
1st eval - after 1 month
2nd eval - not required
3rd eval - after 2 months

for a 6 months trial the evals are:
1st eval - after 2 months
2nd eval - optional
3rd eval - after 4 months

and for a 12 months trial:
1st eval - after 2 months
2nd eval - after 6 months
3rd eval - after 10 months

What do you recon to be the best way to implement this
 

Access - Eval function

Preview
This is my problem I need to use function for my db, but it does not run.
Example: if I execute this routines (sure enough I build my string) Code:
 

using Eval()

Preview
I'm trying to run this piece of code, but I get an error

Public Function fnNoWorkDays()
Dim strOpenArgs As String
strOpenArgs = "DoCmd.OpenForm 'NoWorkDays_Form', acNormal, , , , acDialog"
DoCmd.OpenForm "MonthSchedule", , , , , acDialog, strOpenArgs End Function
and in the MonthSchedule's button click
Sub MyBtn_Click()
Eval (Me.OpenArgs) end sub
 

Eval() for calling an Event proc

Preview
I've got a generic builder for a text box on a form. The builder will assist the user to enter data, and then add that value to the text box. Under normal circumstances the control's before and after events does not fire when the builder populates the control, so we've added code in the builder to call the procs explicitely of the control with something like.
Eval(Forms.MyForm.UserName_AfterUpdate())
And that works.

But since it is a generic builder, I need to work with some variable or control, so I try the following and it fails.
myVar = "Forms.MyForm.UserName"
Eval (myVar & "_AfterUpdate()") or.
Eval("Forms.MyForm.UserName_AfterUpdate()")
Error: Access failed to evaluate one or more expressions because 'UserName_AfterUpdate' was referenced in an expression.
Which kind of makes sense, but it was working in Access 97 - 2003. Not anymore.
 

Hiding Code

Preview
I am working an a complex database.

I have created specific functions (Public <function name>() as.) whose code is stored in table fields. When some of these specific functions are needed, I read the table content, dynamically create a new module, put the function code within, make an Eval(<function name>) to get a result, and erase the dynamically created module.

My problem is that the VBA editor window is launched. Is there a way to prevent its display (by code or something else
 

Hiding code

Preview
I am working an a complex database.

I have created specific functions (Public <function name>() as.) whose code is stored in table fields. When some of these specific functions are needed, I read the table content, dynamically create a new module, put the function code within, make an Eval(<function name>) to get a result, and erase the dynamically created module.

My problem is that the VBA editor window is launched. Is there a way to prevent its display (by code or something else
 

Passing Multiple Arguments to a Function

Preview
I'm trying to pass 2 variables to a function so I dont have the some code repeated a bunch of times just for different variables. But when I finish the call statement I get a "compile error: = expected". If I take the second argument out of the call the error goes away, but it wont work without it. Any thoughts or better ways to do this? The call statement and function look like the following:

Call Statement: Private Sub btnGraphs_Click()
OpenFile ("http://1.1.1.1:8080/aptweb/fileSearch.jsf", "btnGraphs")
End Sub
Function: Public Function OpenFile(FileName As String, Cntrl As String)
Dim ctl As CommandButton
Set ctl = Cntrl
With ctl
.HyperlinkAddress = FileName
.Hyperlink.Follow
End With End Function