Execute a string as a VBA statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to execute a string as a VBA statement?

For example something like:
Execute "Msgbox"

I am looking for a means to assemble and execute a VBA statement as a string
similar to the means to execute a SQL statement such as:
CurrentProject.Connection.Execute "DELETE FROM [tblCustomers] WHERE ......"

However this example works only for SQL statements. I am looking for a
similar means to execute a VBA statement.

Jack Cannon
 
Hi Jack,

The nearest thing is the Eval() function.

Is there a way to execute a string as a VBA statement?

For example something like:
Execute "Msgbox"

I am looking for a means to assemble and execute a VBA statement as a string
similar to the means to execute a SQL statement such as:
CurrentProject.Connection.Execute "DELETE FROM [tblCustomers] WHERE ......"

However this example works only for SQL statements. I am looking for a
similar means to execute a VBA statement.

Jack Cannon
 
Thanks John,

While that is not exactly what I was looking for, I believe that it will
probably solve my problem.

Jack Cannon


John Nurick said:
Hi Jack,

The nearest thing is the Eval() function.

Is there a way to execute a string as a VBA statement?

For example something like:
Execute "Msgbox"

I am looking for a means to assemble and execute a VBA statement as a string
similar to the means to execute a SQL statement such as:
CurrentProject.Connection.Execute "DELETE FROM [tblCustomers] WHERE ......"

However this example works only for SQL statements. I am looking for a
similar means to execute a VBA statement.

Jack Cannon
 
Hi Jack,

If you run into the "Error 2482" problem, you may have to ensure that the
string you pass to Eval() is properly "Quoted." For example"

Eval("'" & <My_Custom-Built_Expression> & "'")

Good luck,

Ed


John Nurick said:
Hi Jack,

The nearest thing is the Eval() function.

Is there a way to execute a string as a VBA statement?

For example something like:
Execute "Msgbox"

I am looking for a means to assemble and execute a VBA statement as a string
similar to the means to execute a SQL statement such as:
CurrentProject.Connection.Execute "DELETE FROM [tblCustomers] WHERE ......"

However this example works only for SQL statements. I am looking for a
similar means to execute a VBA statement.

Jack Cannon
 
Good Point!
Thanks Ed.

Ed B said:
Hi Jack,

If you run into the "Error 2482" problem, you may have to ensure that the
string you pass to Eval() is properly "Quoted." For example"

Eval("'" & <My_Custom-Built_Expression> & "'")

Good luck,

Ed


John Nurick said:
Hi Jack,

The nearest thing is the Eval() function.

Is there a way to execute a string as a VBA statement?

For example something like:
Execute "Msgbox"

I am looking for a means to assemble and execute a VBA statement as a string
similar to the means to execute a SQL statement such as:
CurrentProject.Connection.Execute "DELETE FROM [tblCustomers] WHERE ......"

However this example works only for SQL statements. I am looking for a
similar means to execute a VBA statement.

Jack Cannon
 
Jack Cannon said:
Is there a way to execute a string as a VBA statement?

For example something like:
Execute "Msgbox"

I am looking for a means to assemble and execute a VBA statement as a
string
similar to the means to execute a SQL statement such as:
CurrentProject.Connection.Execute "DELETE FROM [tblCustomers] WHERE
......"

However this example works only for SQL statements. I am looking for a
similar means to execute a VBA statement.

Jack Cannon

In addition to the Eval function, you could also look at the Run method of
the Application object:

Application.Run "MySubProcedureName"

although this doesn't return a value (Eval can), which can be useful
sometimes.
 
Back
Top