Eval function with variables

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:

Related Topics

Eval function with variables
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


Access - Eval function
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


Eval function question doesn't work
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


Need a 'smart' field
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
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()
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
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
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
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
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


Declaring and seting few variables at once
I have few variables with similar names, like:
str_MyVar1
str_MyVar2..

is it possible to declare them with something similar to:
for i = 1 to xx
Dim str_MyVar(i)
next i

if it is possible, is it also possible if they are public and declared outside of the function?
is it possible to set them using a similar routine ?


How do you use a Function inside another Function?
Forum,

I have created a Function to perform a task (delete records) and want this to be actioned within another function.

How do I get this to happen ? DoCmd ?

Here is an extract of the main procedure and the function I want to get to work is FuncDeleteRecord(some variables)


If RepayFreq = "Fortnightly" Then
'FuncDeleteRecord("TblLateFeeCalculated", "LDPK", "LoanID")
Do Until Date <= CommenceDate

Appreciate any advice


[Access 2003] Commandline options
I want to send mail with access, but there are a couple of variables (to, cc, bcc, subject, body, att) that have to be typed on the command line. I've searched and searched a correct way to call a function from the command line, but can't seem to succeed.

I have a function (fn_sendmail) that works if I set the variables hardcoded. When opening the DB a macro calls the function.
Macro1 = openprocedure (sorry for the dutch) Functionname: fn_sendmail()

This is the code I put in dos

"C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE" "G:\mail_test.mdb" /x Macro1 /cmd to, cc, bcc, subject, body, att

I've tried to quote the variables, put them between brackets, used semicolon but nothing works!


Declaring Variables
I have a ListBox that returns a different number of instances depending on which "account" I am working on.

Example:
Tenor Spread COF
5 1.58% 2.15%
7 2.81% 2.74%
10 2.57% 3.33%

It could be anywhere from 1 to 15 lines. I need a function that sets columns 1 and 2 for each instance as a variable i.e.

x1 = 5, 1.58%
x2 = 7, 2.81%
x3 = 10, 2.57%
and so on..

I have the code to set each variable down (Me.PricingList.Column(0, 0) & " yrs, " & format(Me.PricingList.Column(1, 0), "#.00%")

Is there a way I can use a dynamic array to specify how many different variables I will need based on the list box? Ulimately I will be using these variables as text in the body of an email generated via vba.


Variables within String variables possible?
I have a small access application where I have several text segments (like email subjects and bodies) which can be edited by users.

These text segments/string variables shall contain variables, like names etc. Users should be able to place those variables as they like within e.g. an email body (e.g. Hello {firstname}, etc.).

I work with Access + MySQL. Is something like that possible


How to allow variables in function??
Forum,

I have this Function but would like it to work with variables if possible.

Public Function FuncDeleteRecord(MyTable As String, MyField As String, MyCriteria As String)
Dim rs As DAO.Recordset
Dim sqlString As String
sqlString = "SELECT LDPK " & _
"FROM TblLateFeeCalculated " & _
"WHERE (((LDPK)=" & MyCriteria & "));"
Set rs = DBEngine(0)(0).OpenRecordset(sqlString)
Do While Not rs.EOF
Debug.Print rs!LDPK
rs.MoveNext
Loop
rs.Close
Set rs = Nothing End Function

TblLateFeeCalculated should be MyTable and LDPK should be MyField.

MyCriteria works.

Appreciate any advice.


VBA variables in SQL
I am trying to use a variable (defined in my function) in a SQL statement.
But its not working. I've bolded the line where my function fails to work, everything else is A-OK!
Code...


AutoKeys and function arguments
I use an {F1} Autokey macro that use the RunCode Action with the argument as = Help(). This Help function in fact has 2 arguments which are public variables eg DirA & StrB that were declared in the Application. When I put them in eg = Help([DirA], [StrB]) and then press F1 key, an error messages states that "Object don't contain the Automation object "DirA". By the way, without the 2 arguments, F1 works.

2 questions

1) How can I make the Autokey {F1} work with the 2 variables?

2) Can I create an Autokey F1 without using a Macro. I tried using VB codes without success


How to pick the maximum value from variables in code
I have four variables DHVN, DHVE, DHVS, and DHVW that are calculated in my code. Next, I need to do another calculation that involves picking the highest of these four variables. Can someone tell me how to do this


Calculating memory requirement
I have a max of 200 employees here at work, and they all log into thin clients and running on two terminal servers. I am starting to write a function in VBA that is going to have the following Public variables:

23 long integers,
58 strings,
18 dates,
1 currency &
1 boolean

Now, if all 200 employees ran this function around the same time while using the same terminal server, what kind of memory usage could I expect at thatinstant? let's assume that each long integer is holding eight digits and each string is holding 255 characters

If all of that memory (multiplied by 200) is less than 32MB then I have nothing to worry about. Could the variables consume more memory than that?